Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hazelcast Map is locked

Tags:

java

hazelcast

We are using Hazelcast 2.3.1, in our hazelcast.xml configuration file we use write behind for an Hazelcast IMap:

 <map name="HazelcastObjectOperations.objectMap">
         <backup-count>1</backup-count>
         <map-store enabled="true">
             <class-name>persister.HazelcastObjectPersister</class-name>
             <write-delay-seconds>10</write-delay-seconds>
         </map-store>
 </map>
 <properties>
      <property name="hazelcast.map.cleanup.delay.seconds">5</property>
 </properties>

We got two classes

  1. HazelcastObjectOperation which holds the map and is used to put objects into it.
  2. HazelcastObjectPersister which extends MapStore is used to persist Objects when Hazelcast is calling storeAll().
public class HazelcastObjectOperation {

    protected final IMap<Long, MyHzcObj> objectMap;
    private final HazelcastInstance instance;

    public HazelcastObjectOperation() {
        this.instance = Hazelcast.getDefaultInstance();
        this.objectMap = this.instance.getMap("HazelcastObjectOperations.objectMap" );
    }

    public void save( final MyHzcObj object ) {
        long start = System.currentTimeMillis();
        IdGenerator generator = Hazelcast.getIdGenerator("generator");
        this.objectMap.put( generator.newId(), object );
        long end = System.currentTimeMillis();
    }
}

The Problem is when Hazelcast runs through this map and fetches the objects which should be stored in the storeAll method of the persister class, the map is locked for seconds and so a put into this map lasts this time. Is there any solution for this problem?

like image 781
luko Avatar asked Sep 26 '12 06:09

luko


1 Answers

This was a Hazelcast issue and fixed by: https://github.com/hazelcast/hazelcast/issues/293

By the way: Note that it is always better to use set() instead put() if you do not need the old value. The issue was related to that put() tries to load old value if mapstore is defined. set() does not try to load old value so it is faster and cleaner.

like image 155
enesness Avatar answered Nov 05 '22 02:11

enesness