Search code examples
javahazelcasthazelcast-imap

putAll causing single store() calls with Hazelcast IMap


I have a simple map backed by a MapStore implementation. When I call putAll() on the map, passing a map of key-value pairs to be added to the map, Hazelcast for some reason calls store() method on the MapStore for every value, rather than calling storeAll() once.

Not sure why is this behavior occuring. Is putAll/storeAll relationship supported for hazelcast maps?

Thanks, Konrad


Solution

  • Hazelcast supports different modes of persistence viz. read-through, write-through, and write-behind mode.

    Batch write operations like storeAll() and deleteAll() are only supported in write-behind mode. Hence you need to turn on write-behind mode to make use of storeAll() , in your case.

    In order to "turn on" write-behind mode, you need to set <write-delay-seconds> in your config xml to a value greater than 0. Configuring <write-delay-seconds> to 'x' seconds implies that the modified entries will be put to the store asynchronously after 'x' seconds.

    A sample config:

    <map name="employeesMap">
        <map-store enabled="true">
            <class-name>main.jdbc.EmployeeMapStore</class-name>
            <write-delay-seconds>10</write-delay-seconds>
        </map-store>
    </map>
    

    I would also like to recommend you a good read related to this topic.

    http://docs.hazelcast.org/docs/3.5/manual/html/map-persistence.html