balajikandavel
balajikandavel

Reputation: 43

Hazelcast Eviction not working with Spring when max-size-policy as USED_HEAP_SIZE. It works fine with max-size-policy as PER_NODE

This issue is for any Hazelcast versions. (Tried 3.2.x ,3.3.x,3.4.x) I have specified Eviction conditions below which needs to be happening to prevent Out of memory Error. But though I have mentioned the max-size, Eviction is not triggered when USED_HEAP_SIZE is the policy while it is triggered while the policy is PER_NODE.

  <hz:map name="aggregateCache" eviction-policy="LRU"  in-memory-format="OBJECT"
             statistics-enabled="true"
            eviction-percentage="25" 
            max-size="120"
            max-size-policy="USED_HEAP_SIZE">

    <hz:entry-listeners>
                <hz:entry-listener 
                    include-value="true"
                    implementation="messageEventListener" />
            </hz:entry-listeners>
        </hz:map>

  <bean id="messageEventListener"
    class="com.manheim.webservices.ovcoutbound.cep.cache.MessageEventListener" />

I trigger the Eviction as part of MessageEventListener class as shown below. public class MessageEventListener implements EntryListener {

private static final String  EVICTED_MESSAGES= "direct:evictedAggregateCacheMessages";  

@Override
public void entryEvicted(EntryEvent<String, HubMessageAggregate> event) {

    try{

    HubMessageAggregate aggregate =  event.getOldValue();
    exchange.getIn().setBody(aggregate);
    template.send(EVICTED_MESSAGES, exchange);
    }
    catch(Exception e){
        String error = "Unable to process the Evicted message properly with the Key " + 
                event.getKey();
    }

}

Upvotes: 1

Views: 1237

Answers (1)

Bilal Yasar
Bilal Yasar

Reputation: 967

You have to change in-memory-format="OBJECT" to in-memory-format="BINARY"

And currently there is a PRD for this request: https://hazelcast.atlassian.net/wiki/display/COM/HEP+3+-+Entry+Cost+Calculator+SPI

If you want you can contribute to hazelcast :)

Upvotes: 1

Related Questions