Hello!

1) The best way of preloading data is to add CacheLoader (or CacheStore) to
cache configuration and call loadCache().

2) Data will be collocated as long as both caches use same affinity field
(via annotation, AffinityKey or configuration).
Then if you join tables by that field Ignite will know.
This of course requires that other settings of AffinityFunction are the
same.

Regards,
-- 
Ilya Kasnacheev


пн, 18 февр. 2019 г. в 09:43, xmw45688 <xw...@procurant.com>:

> Hi All,
>
> Apache Ignite recommends to collocate data with data, which is a very nice
> feature.  This works well if you insert data through APIs provided by
> Ignite
> (see the following code I copy from Ignite Doc).  However, I don't know how
> to handle the following cases
>   1. the data (company and person) exist in the other databases such as
> Cassandra.  How do I pre-cache company and person from pre-existed data?
> Do
> I have to use JDBC to load company, person data row by row, insert into
> person and cache objects, such as
>    for org: orgs {
>        find persons for org {
>            personCache.put(affinityKey(p.id, org.id), org);
>        }
>        orgCache.put(org.id, org);
>    }
>
>    If I used Ignite native persistence store, how does Ignite cluster know
> that both company and person are collocated?
>
>   2. How do I know that @AffinityKeyMapped annotated key comes from the
> cache I need to map.  I don't see the logic to define relationship between
> person.companyId and company.id.  If I have two separated two methods to
> load company and person cache separately, will the collocation of persons
> with companies still work?
> preloadCompany();
> preloadPerson(long companyId);
>
> preloadAllPersons() {
>     1. get all companies from the companyCache
>     // how personsCache will know this companyId is the same cluster node
> as
> companyCache?
>     for (c: companies) {
>        preloadPerson(c.companyId);
>     }
> }
>
> The following code is excerpted from
> https://apacheignite.readme.io/docs/affinity-collocation.
>
>
> public class PersonKey {
>     // Person ID used to identify a person.
>     private String personId;
>
>     // Company ID which will be used for affinity.
>     @AffinityKeyMapped
>     private String companyId;
>     ...
> }
>
> // Instantiate person keys with the same company ID which is used as
> affinity key.
> Object personKey1 = new PersonKey("myPersonId1", "myCompanyId");
> Object personKey2 = new PersonKey("myPersonId2", "myCompanyId");
>
> Person p1 = new Person(personKey1, ...);
> Person p2 = new Person(personKey2, ...);
>
> // Both, the company and the person objects will be cached on the same
> node.
> comCache.put("myCompanyId", new Company(...));
> perCache.put(personKey1, p1);
> perCache.put(personKey2, p2);
>
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>

Reply via email to