Question

I have problem understanding the concept of Hazelcast Distributed Execution. It is said to be able to perform the execution on the owner instance of a specific key.
From Documentation:

   <T> Future<T> submitToKeyOwner(Callable<T> task, Object key)
   Submits task to owner of the specified key and returns a Future representing that task.
       Parameters:
            task - task
            key - key
       Returns:
            a Future representing pending completion of the task

I believe that I'm not alone to have a cluster built with multiple maps which might actually use the same key for different purposes, holding different objects (e.g. something along the following setup):

IMap<String, ObjectTypeA> firstMap = HazelcastInstance.getMap("firstMap");
IMap<String, ObjectTypeA_AppendixClass> secondMap = HazelcastInstance.getMap("secondMap");

To me it seems quite confusing what documentation says about the owner of a key. My real frustration is that I don't know WHICH - in which map - key does it refer to?
The documentation also gives a "demo" of this approach:

import com.hazelcast.core.Member;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.IExecutorService;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;   
import java.util.Set;
import com.hazelcast.config.Config;

public void echoOnTheMemberOwningTheKey(String input, Object key) throws Exception {
   Callable<String> task = new Echo(input);
   HazelcastInstance hz = Hazelcast.newHazelcastInstance();
   IExecutorService executorService = hz.getExecutorService("default");
   Future<String> future = executorService.submitToKeyOwner(task, key);
   String echoResult = future.get();
}

Here's a link to the documentation site: Hazelcast MultiHTML Documentation 3.0 - Distributed Execution
Did any of you guys figure out in the past what key does it want?

Was it helpful?

Solution

Perhaps I can explain it better with a code example:

   Callable<String> task = new Echo(input);

   String key = "foo";
   IMap map1 = hz.getMap("m1");
   IMap map2 = hz.getMap("m2");
   map1.put(key,1);
   map2.put(key,2);

   IExecutorService executorService = hz.getExecutorService("default");
   Future<String> future = executorService.submitToKeyOwner(task, key);
   String echoResult = future.get();

As you can see there are 2 maps, map1 and map2.

Both of these maps have a map entry with the same key 'foo' but different values.

But these 2 map entries will end up in the same partition (so on the same member) because the key is used to determine the partition.

In the last few lines the task is send to the key owner, in this case we are going to send the task to the member that owns key 'foo'. So the task is going to be send to the same machine as where both the map entries are stored.

I have not checked the discussion you had on support; this is an answer to your original question you posted here on stack overflow.

OTHER TIPS

In Hazelcast you can partition your data and in a map, the key is used.

E.g. when I have 2 maps using the same key, the map entry for that key will be placed for both the maps in the same partition.

So it isn't very important which map is being used.

You can use the executor to send a task to the member owning that partition.

I hope this answers your question, else feel free to ask for more information.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top