Thursday, February 23, 2012

Synchronization Between JGroups.ReplicatedHashMap's

ReplicatedHashMap of JGroups provides a distributed ConcurrentHashMap implementation. In its simplest form, it propagates every local change to all other instances in the cluster and you get your replicated-HashMap between available cluster members.

In a cluster environment, new node arrivals are highly anticipated, but ReplicatedHashMap doesn't really keep up with the late joiners. See below execution flow for a late joiner scenario.


TimeNode ANode B
1joins
2adds 1
3gets 1
4sees {1}
5join
6sees {}
7adds 2
8gets 2gets 2
9sees {1,2}sees {2}

In the above figure, nodes are out of sync at time steps 6 and 9. To avoid such cases, we need to force ReplicatedHashMap for a sync during initialization. For this purpose, quoting with Bela Ban's (author of JGroups) words,
  1. Move JChannel.connect() after the creation of ReplicatedHashMap,
  2. I also suggest to call ReplicatedHashmap.start(), or else there won't be any state transfer.
See ReplicatedHashMap Updates for Late Joiners mailing-list for the related discussion.

No comments:

Post a Comment