ignite-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aealexsandrov <aealexsand...@gmail.com>
Subject Re: Customized affinity function
Date Wed, 11 Apr 2018 07:41:28 GMT
Hi Prasad,

Affinity function does not directly map keys to nodes, it maps keys to
partitions. So it takes care about entities balance between nodes. To read
more please take a look here:

https://apacheignite.readme.io/docs/affinity-collocation#affinity-function

In case if for every subscriber you are going to create it's own cache then
you can try to setup the node filters for every subscriber:

https://ignite.apache.org/releases/latest/javadoc/org/apache/ignite/configuration/CacheConfiguration.html#setNodeFilter-org.apache.ignite.lang.IgnitePredicate-

If you have the same cache for all subscribers then try to setup your own
AffinityKey (as descibed above):

            IgniteCache<EntityKey, String> cache =
ignite.getOrCreateCache(cfg);

            for (int i = 0 ; i < 1_000_000; i++) {
                cache.put(new EntityKey(2*i, 1L), "Value1" + i); //sub id =
1
                cache.put(new EntityKey(2*i + 1, 2L), "Value2" + i); //sub
id =2
            }

where:

    public static class EntityKey {
        public EntityKey(long id, long subscriberId) {
            this.id = id;
            this.subscriberId = subscriberId;
        }

        private long id;

        // Subscriber ID which will be used for affinity.
        @AffinityKeyMapped
        private long subscriberId;

        public long getSubscriberId() {
            return subscriberId;
        }

        public long getId() {
            return id;
        }
    }

Thank you,
Andrei



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

Mime
View raw message