You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by bingili <bi...@illinois.edu> on 2017/10/13 16:32:07 UTC

Is there a way to know mapping of keys and machine nodes

Hello:

There is a section ``Performance Considerations'' talking about the order of
keys to reduce the number of network messages in a large transaction.

May I know there is a api to know the mappings of key and node, please? 

/e.g., Suppose that these keys are mapped to nodes in the following fashion:
{A: 1, 4}, {B: 2, 5}, {C: 3, 6}.
/
https://apacheignite.readme.io/docs/transactions#pessimistic-transactions


Regards.




--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: Is there a way to know mapping of keys and machine nodes

Posted by Alexey Kukushkin <ku...@gmail.com>.
Hi, Ignite Affinity#mapKeysToNodes returns a map node -> keys. This is
copied from CacheAffinityExample you can find in Ignite distribution:

// Map all keys to nodes.
Map<ClusterNode, Collection<Integer>> mappings =
ignite.<Integer>affinity(CACHE_NAME).mapKeysToNodes(keys);

for (Map.Entry<ClusterNode, Collection<Integer>> mapping :
mappings.entrySet()) {
    ClusterNode node = mapping.getKey();

    final Collection<Integer> mappedKeys = mapping.getValue();

    if (node != null) {
        // Bring computations to the nodes where the data resides
(i.e. collocation).
        ignite.compute(ignite.cluster().forNode(node)).run(() -> {
            IgniteCache<Integer, String> cache = ignite.cache(CACHE_NAME);

            // Peek is a local memory lookup, however, value should
never be 'null'
            // as we are co-located with node that has a given key.
            for (Integer key : mappedKeys)
                System.out.println("Co-located using mapKeysToNodes
[key= " + key +
                    ", value=" + cache.localPeek(key) + ']');
        });
    }
}


On Fri, Oct 13, 2017 at 7:32 PM, bingili <bi...@illinois.edu> wrote:

> Hello:
>
> There is a section ``Performance Considerations'' talking about the order
> of
> keys to reduce the number of network messages in a large transaction.
>
> May I know there is a api to know the mappings of key and node, please?
>
> /e.g., Suppose that these keys are mapped to nodes in the following
> fashion:
> {A: 1, 4}, {B: 2, 5}, {C: 3, 6}.
> /
> https://apacheignite.readme.io/docs/transactions#pessimistic-transactions
>
>
> Regards.
>
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>



-- 
Best regards,
Alexey