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/