Viktor Stolbin
Viktor Stolbin

Reputation: 2939

Hazelcast: make sure related objects are physically stored on same member

I have 3 distributed maps which objects have one shared property - identifier. This identifier is used as a key for one map while 2 other maps are using cluster wide global ids as a key. There's also a Map-Reduce job that is combining related by this identifier object and is storing the result into another map. The idea is to minimize inter-cluster network traffic so job is communicating only with one member where it is being executed.

The question is: do I need to do any extra action to make sure partitions of different distributed maps are physically stored on one member?

Upvotes: 2

Views: 178

Answers (1)

Neil Stevenson
Neil Stevenson

Reputation: 3150

PartitionAware will do this for you.

If you want to guarantee three objects reside in the same partition, their key classes should implement PartitionAware and return the same result from the getPartitionKey() method.

For example, to keep all members of the same family together:

public class Person implements PartitionAware, Serializable {
    private String firstName;
    private String lastName;

    public Object getPartitionKey() {
        return this.lastName;
    }

You can verify the partition with hazelcastInstance.getPartitionService().getPartition(key).getPartitionId()

Partition 0 contains the first part of each of map X, map Y, map Z. Partition 1 contains the next part, etc.

Upvotes: 4

Related Questions