Search code examples
joinignite

Getting incomplete data when running 6 ignite servers


I am running 6 Ignite servers on version 2.7.5. The problem is when I am hitting queries using my client API I am not getting all records. Only some records are coming. I am using partitioned cache. I don't want to use replicated mode. When queried with DBeaver it show all records have been fetched.

The following code is used to fetch the data:

public List<Long> getGroupIdsByUserId(Long createdBy) {
    final String query = "select g.groupId from groups g where g.createdBy = ? and g.isActive = 1";
    SqlFieldsQuery sql = new SqlFieldsQuery(query);
    sql.setArgs(createdBy);
    List<List<?>> rsList = groupsCache.query(sql).getAll();
    List<Long> ids = new ArrayList<>();
    for (List<?> l : rsList) {
        ids.add((Long)l.get(0));
    }
    return ids;
}

Ignite Version - 2.7.5

Client Query method

And the join Query is :

    final String query = "select distinct u.userId from 
    groupusers gu "
                + "inner join \"GroupsCache\".groups g on gu.groupId = g.groupId 
"
                + "inner join \"OrganizationsCache\".organizations o on 
gu.organizationId = o.organizationId "
                + "inner join \"UsersCache\".users u on gu.userId = u.userId 
where "     + "g.groupId = ? and "
                + "g.isActive = 1 and " + "gu.isActive = 1 and " + 
"gu.createdBy 
    = ? and " + "o.organizationId = ? and "
                + "o.isActive = 1 and " + "u.isActive = 1";

For the join query Actual records in db is 120 but with ignite client only 3-4 records are comming .and they are not consistent. sometime it comes 3 records and some time it is 4 records. And for query

select g.groupId from groups g where g.createdBy = ? and g.isActive = 1 

actual records are 27 but comming records are sometimes 20 sometimes 19 and sometimes complete. Please Help me with this and with collocated joins..


Solution

  • Most likely this would mean that your affinity is incorrect.

    Apache Ignite assumes that your data has proper affinity, i.e. when joining two tables, rows to join will always be available on the same node. This works when you either join by primary key, or by a part of primary key which is marked as affinity column (e.g. by @AffinityKeyMapped annotation). There's a documentation page about affinity.

    You can check that by setting distribtedJoins connection setting to true. If you see all the records after that, it means you need to fix your affinity.