You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by kotamrajuyashasvi <ko...@gmail.com> on 2018/07/23 15:35:12 UTC

Implementing custom affinity logic

Hi 

I m working on an ignite project where I want to have certain records to be 
collocated based on a custom calculated value which is obtained from the
fields of the 
primary key object. 

For example the Primary key pojos have fields a,b,c. I want all records 
having same value of (a+b)/c collocated on same node/partition. 
  
I have gone through the ignite documentation and found that custom 
AffinityKeyMapper is the one that can be used. Also there is an option to
use custom Affinity 
function but extra logic has to be added for partition to node mapping etc.. 

1. How can I achieve my above requirement? What are the correct options and 
where can I get a working example of custom AffinityKeyMapper or
AffinityFunction ?

2. Once after achieving custom affinity how to test if all records are 
getting collocated as expected. One option that I found was to use scan
query and scan a particular 
partition and test each record if it should actually belong to the scanned
partition. But if there are huge 
number of records I'm facing OOM while running scan query for a partition.
So I would like to know 
how to achieve this/ test to confirm for sure the collocation is as
expected. 

3. What is the performance impact of using custom affinity logic when 
compared to using no affinity and using @AffinityKeyMapped annotation to
achieve affinity where the 
scenario is to collocate based on a single field. 

4. When using @AffinityKeyMapped or no affinity is used, is 
org.apache.ignite.internal.processors.cache.GridCacheDefaultAffinityKeyMapper 
is used as default AffinityKeyMapper ? or there is any other default module
that is used 
for calculating affinity ? 







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

RE: Implementing custom affinity logic

Posted by Stanislav Lukyanov <st...@gmail.com>.
Hi,

I think all you need is to store (a+b)/c in a separate field of the key and annotate it with @AffinityKeyMapped:
    class Key {
        private long a, b, c;
        @AffinityKeyMapped 
        private long affKey;
        
        public Key(long a, long b, long c) {
            this.a = a;
            this.b = b;
            this.c = c;
            this.affKey = (a+b)/c;
        }
    }

AffinityKeyMapper is deprecated, don’t use that.

Writing your own affinity function is needed incredibly rarely, try to avoid that unless you’re 150% sure you need that.

To check if the records are collocated you could run some local queries (new SqlQuery().setLocal(true)) and see that the number of entries returned is as expected.

Stan 

From: kotamrajuyashasvi
Sent: 23 июля 2018 г. 18:35
To: user@ignite.apache.org
Subject: Implementing custom affinity logic

Hi 

I m working on an ignite project where I want to have certain records to be 
collocated based on a custom calculated value which is obtained from the
fields of the 
primary key object. 

For example the Primary key pojos have fields a,b,c. I want all records 
having same value of (a+b)/c collocated on same node/partition. 
  
I have gone through the ignite documentation and found that custom 
AffinityKeyMapper is the one that can be used. Also there is an option to
use custom Affinity 
function but extra logic has to be added for partition to node mapping etc.. 

1. How can I achieve my above requirement? What are the correct options and 
where can I get a working example of custom AffinityKeyMapper or
AffinityFunction ?

2. Once after achieving custom affinity how to test if all records are 
getting collocated as expected. One option that I found was to use scan
query and scan a particular 
partition and test each record if it should actually belong to the scanned
partition. But if there are huge 
number of records I'm facing OOM while running scan query for a partition.
So I would like to know 
how to achieve this/ test to confirm for sure the collocation is as
expected. 

3. What is the performance impact of using custom affinity logic when 
compared to using no affinity and using @AffinityKeyMapped annotation to
achieve affinity where the 
scenario is to collocate based on a single field. 

4. When using @AffinityKeyMapped or no affinity is used, is 
org.apache.ignite.internal.processors.cache.GridCacheDefaultAffinityKeyMapper 
is used as default AffinityKeyMapper ? or there is any other default module
that is used 
for calculating affinity ? 







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