TTL defined in hazelcast.yaml and not working - Spring Boot

17 views
Skip to first unread message

Tomislav Šimović

unread,
Nov 17, 2022, 3:47:53 AM11/17/22
to Hazelcast
Hi,

I am pretty new to the hazelcast thing, and I have an issue that I've been working on for about this week.

I have defined this hazelcast.yaml to the src/main/java/resources:

hazelcast:
    map:
        marketOfferModes:
            time-to-live-seconds: 10
            max-idle-seconds: 10
    network:
        join:
            multicast:
                enabled: true

So, my problem is that cache is shared between members on the cluster but is not evicted, although the TTL is defined.

I tried this hazelcast.yaml with the basic Spring Boot API that gets books by ISBN, and it works, but I can't get it working with this more complicated service.

I don't know where to look anymore, and any help would be appreciated.

P.S. I'm using hazelcast version: 4.2.5



Neil Stevenson

unread,
Nov 17, 2022, 11:43:57 AM11/17/22
to Hazelcast
Try the below. The first print confirms config is loaded from the file, the print in the listener shows the entry being expired.
Works for me with 4.2.5.
The usual problem with YAML is indenting..

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

        Config config = new ClasspathYamlConfig("hazelcast.yaml");

        System.out.println(config.getMapConfigs());

        HazelcastInstance hz = Hazelcast.newHazelcastInstance(config);

        IMap<String, String> marketOfferModes = hz.getMap("marketOfferModes");

        marketOfferModes.addEntryListener(new MyListener(), true);

        TimeUnit.SECONDS.sleep(5L);

        marketOfferModes.put("hello", "world");

        TimeUnit.SECONDS.sleep(15L);

        hz.shutdown();

    }

    static class MyListener implements EntryExpiredListener<String, String> {

       @Override

       public void entryExpired(EntryEvent<String, String> event) {

           System.out.println(event);

       }  

    }


Tomislav Šimović

unread,
Nov 22, 2022, 2:21:41 AM11/22/22
to haze...@googlegroups.com
Hi Neil,

Thank you for your answer!
I did that, and the app is not executing the entryExpired method.

This is the only log that I got:

{MarketOfferMetadataModel=MapConfig{name='MarketOfferMetadataModel', inMemoryFormat='BINARY', metadataPolicy=CREATE_ON_UPDATE, backupCount=1, asyncBackupCount=0, timeToLiveSeconds=10, maxIdleSeconds=10, readBackupData=false, evictionConfig=EvictionConfig{size=500, maxSizePolicy=PER_NODE, evictionPolicy=NONE, comparatorClassName=null, comparator=null}, merkleTree=MerkleTreeConfig{enabled=false, depth=10}, eventJournal=EventJournalConfig{enabled=false, capacity=10000, timeToLiveSeconds=0}, hotRestart=HotRestartConfig{enabled=false, fsync=false}, nearCacheConfig=null, mapStoreConfig=MapStoreConfig{enabled=false, className='null', factoryClassName='null', writeDelaySeconds=0, writeBatchSize=1, implementation=null, factoryImplementation=null, properties={}, initialLoadMode=LAZY, writeCoalescing=true}, mergePolicyConfig=MergePolicyConfig{policy='com.hazelcast.spi.merge.PutIfAbsentMergePolicy', batchSize=100}, wanReplicationRef=null, entryListenerConfigs=null, indexConfigs=null, attributeConfigs=null, splitBrainProtectionName=null, queryCacheConfigs=null, cacheDeserializedValues=INDEX_ONLY, statisticsEnabled=true, entryStatsEnabled=false}}

 Based on this it looks like the configuration is loaded correctly, but I don't know what's happening with eviction.


This message contains confidential information and is intended only for the individuals named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message, which arise as a result of e-mail transmission. If verification is required, please request a hard-copy version. -Hazelcast

--
You received this message because you are subscribed to a topic in the Google Groups "Hazelcast" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/hazelcast/94eGHVtJLNw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to hazelcast+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hazelcast/a624d299-ce51-4be2-92b8-e4dd7ffc0a52n%40googlegroups.com.

Neil Stevenson

unread,
Nov 22, 2022, 6:57:28 AM11/22/22
to Hazelcast
 Next thing to try is to confirm if the data is really present where you expect, as the map name in your log above differs from the YAML in the earlier message.

 You should see this be non-zero once you've put data in, and reduce to zero as the data expires.

 Something like printing 'hazelcastInstance.getMap("MarketOfferMetadataModel").size()' in a loop
(or, use the Management Center, which makes it even easier)

 With expiry, you need to be careful that testing the data is there doesn't keep it alive! So use "size()" rather than "get(K)"  etc

Neil
Reply all
Reply to author
Forward
0 new messages