0

I am trying to Store a Person Object in Ignite Cache in PARTITIONED Mode with backup as 1. There are 3 server nodes to cache Data

public class PersonImpl{
   private String name;
   private HashMap<Integer,String> attr = new HashMap<>();
   private HashMap<Integer,String> attr1 = new HashMap<>();
   private ArrayList<Integer> a;
   private ArrayList<Integer> b;
}

Including HashMap and ArrayList in the the Object gives duplicates using different Query features in Ignite while removing HashMap and ArrayList does not give duplicates. Is this issue related with Collections Object? Also changing the backup from 1 to 0 do not give inconsistent results. Did Anyone faced similar issue and how to resolve it

Below is the code that I am using to query : sqlQuery(PersonImpl.class,"true");

public List<V> sqlQuery(Class<V> persistentClass, String t){
    SqlQuery<K,V> sqlQuery = new SqlQuery<>(persistentClass,t);
    List<V> values = new ArrayList<V>();
    QueryCursor<Entry<K,V>> queryCursor= getCache.query(sqlQuery);
    for(Entry<K,V> entry : queryCursor){
         values.add(entry.getValue());
    }
return values;
}

To store the Object in Cache

store(T obj){
put(obj.getAffinityKey(), obj);
}
Krishna
  • 1
  • 1
  • 1
    What query do you use? – Vladimir Pligin Dec 01 '21 at 18:54
  • Tried both with sqlQuery and SqlFieldsQuery. Ignite version 2.6 – Krishna Dec 02 '21 at 07:53
  • I think Vladimir was asking if you can show your SQL query and table definitions. I think it just won't work without denormalization. – Alexandr Shapkin Dec 03 '21 at 23:36
  • @VladimirPligin I have added the code to store and retreive the objects above. To Test I am storing 10000 Objects of PersonImpl Object having different size of HashMap and List. The duplicates do not occur generallly when the size of HashMap and List is zero. Duplicates occur when the randomness in size of HashMap increases. Does Ignite do not provide the support for Collections Object inside an Object to be stored in Cache? – Krishna Dec 05 '21 at 07:06
  • @Krishna what is your table definition? You are inserting an object using cache API and are trying to read with SQL, for that a table definition needs to be declared, for sample using QueryEntities configuration https://ignite.apache.org/docs/latest/SQL/sql-api – Alexandr Shapkin Dec 12 '21 at 15:47
  • Regarding the duplicates, it's handled by your cache key definition. What's your obj.affinityKey for PersonImpl? I can't see any annotations for this POJO to be defined. To check for the duplicates consider using a SCAN query https://ignite.apache.org/docs/latest/key-value-api/using-scan-queries#executing-scan-queries or just the same cache API - cache.get(obj.getAffinityKey() – Alexandr Shapkin Dec 12 '21 at 15:50

0 Answers0