1
votes

Hazelcast IMap put method acquires a lock on bucket or partition or key? java.util.concurrent.ConcurrentHashMap put method acquires a lock on the bucket and writes to the Map.
Whereas in Hazelcast IMap which is a distributed map implementation of java.util.concurrent.ConcurrentHashMap, when the following code is executed by one Hazelcast node.
imap.put(key, value);
does it acquire a lock on bucket or partition or key? Please clarify? I don't see the answer for this anywhere in hazelcast documentation.

1

1 Answers

5
votes

IMap.put does not acquire any lock. Each Hazelcast member has certain set of partitions, which are handled by a number of partition threads. Each partition thread owns certain number of partitions. So when a write operation arrives at a cluster member, it is picked by the partition thread that owns the partition which would be the host of the Entry object in that write operation.

If the same member receives another write operation, which is destined for the same or other partitions owned by the same partition thread, it would not be picked until the previous write operation by the thread is complete. This prevents any potential race conditions and does not require explicit locking in default state.

One, however can acquire locks on keys by using IMap API.

See here for details on Hazelcast threading model: https://docs.hazelcast.org/docs/3.10.5/manual/html-single/index.html#threading-model