You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by Tejashwa Kumar Verma <te...@gmail.com> on 2016/12/28 07:26:45 UTC

Affinity Key

Hi,

I have doubt regarding affinity key.
I have 2 cache :

Cache 1 and 2 both should be related with "equipmentID". Hence
"equipmentID" should be affinity key for cache2.

Hence in Cache2 creating affinity key like --new AffinityKey<>(pk, eqID);

now the question is how to relate  this with cache1??



Thanks & Regards
Tejas

Re: Affinity Key

Posted by dkarachentsev <dk...@gridgain.com>.
Tejas,

What is your use-case?

AffinityKey helps collocate related data. F.e. if you have Person and
Organization entities and want that Person`s related to Organization was
resided on the same node, you may use AffinityKey:

        // Organizations.
        Organization org1 = new Organization("ApacheIgnite");
        Organization org2 = new Organization("Other");

        orgCache.put(org1.id(), org1);
        orgCache.put(org2.id(), org2);

        // People.
        Person p1 = new Person(org1, "John", "Doe", 2000, "John Doe has
Master Degree.");
        Person p2 = new Person(org2, "John", "Smith", 1000, "John Smith has
Bachelor Degree.");

        // These persons are collocated with their organizations.
        // Preson.key() returns new AffinityKey(personId, organizationId)
        colPersonCache.put(p1.key(), p1);
        colPersonCache.put(p2.key(), p2);

        // These Person objects are not collocated with their organizations.
        personCache.put(p1.id, p1);
        personCache.put(p2.id, p2);

Note that if you saved entry with AffinityKey you have to use that same key
to retrieve values.



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Affinity-Key-tp9772p9780.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Affinity Key

Posted by Tejashwa Kumar Verma <te...@gmail.com>.
Hi dkarachentsev,

I had tried below way to implement affinityKey..

cache1.put(new AffinityKey<>(pk0, eqID),
value2);
cache2.put(new AffinityKey<>(pk, eqID), value2);


But after doing above. full data was not getting loaded in cache . It was
loading only 2 records and getting stuck there only .



Regards
Tejas

On Wed, Dec 28, 2016 at 3:01 PM, dkarachentsev <dk...@gridgain.com>
wrote:

> Hi Tejas,
>
> You may do the following:
>
> cache1.put(eqID, value1); or cache1.put(new AffinityKey<>(pk0, eqID),
> value2);
> cache2.put(new AffinityKey<>(pk, eqID), value2);
>
> In that case keys in Cache 2 will be collocated with keys in Cache 1.
>
>
>
> --
> View this message in context: http://apache-ignite-users.
> 70518.x6.nabble.com/Affinity-Key-tp9772p9775.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.
>

Re: Affinity Key

Posted by dkarachentsev <dk...@gridgain.com>.
Hi Tejas,

You may do the following:

cache1.put(eqID, value1); or cache1.put(new AffinityKey<>(pk0, eqID),
value2);
cache2.put(new AffinityKey<>(pk, eqID), value2);

In that case keys in Cache 2 will be collocated with keys in Cache 1.



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Affinity-Key-tp9772p9775.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.