Search code examples
sqlignite

Ignite SqlQuery for two clients


I use next process for my Ignite cache with third party persistence:

  1. empty database
  2. start two instances in server mode
  3. start first instance in client mode.
  4. The client in cycle
    • creates entities
    • reads entities by a simple SqlQuery

So far all right. All the code works properly.

Then I start second instance in client mode. The code is the same. The second client also in cycle

  • creates entities
  • reads entities by the SqlQuery

And the second client gets empty ResultSet. While the first client still reads the data properly. BTW. Both clients can get entities by keys.

Off course all the data in memory.

So why the second client can't read by SqlQuery?

Three options of code are below. All of them work identically: The first started client always gets correct result. The second started client always gets empty ResultSet.

    SqlQuery<EntryKey, Entry> sql = new SqlQuery<>(Entry.class, "accNumber = ?");
    sql.setArgs(number);
    List<Cache.Entry<EntryKey, Entry>> res = entryCache.query(sql).getAll();

...

    SqlFieldsQuery sql = new SqlFieldsQuery("select d_c, summa from Entry where accNumber = ?");
    sql.setArgs(number);
    List<List<?>> res = entryCache.query(sql).getAll();

...

    SqlQuery<BinaryObject, BinaryObject> query = new SqlQuery<>(Entry.class, "accNumber = ?");
    QueryCursor<Cache.Entry<BinaryObject, BinaryObject>> entryCursor = binaryEntry
            .query(query.setArgs(number));
    List<javax.cache.Cache.Entry<BinaryObject, BinaryObject>> res = entryCursor.getAll();

XML configuration is below:

                <bean class="org.apache.ignite.configuration.CacheConfiguration">
                <!-- Set a cache name. -->
                <property name="name" value="entryCache" />
                <!-- Set cache mode. -->
                <property name="cacheMode" value="PARTITIONED" />
                <property name="atomicityMode" value="TRANSACTIONAL" />
                <!-- Number of backup nodes. -->
                <property name="backups" value="1" />

                <property name="cacheStoreFactory">
                    <bean class="javax.cache.configuration.FactoryBuilder"
                        factory-method="factoryOf">
                        <constructor-arg
                            value="ru.raiffeisen.cache.store.jdbc.CacheJdbcEntryStore" />
                    </bean>
                </property>
                <property name="readThrough" value="true" />
                <property name="writeThrough" value="true" />

                <property name="queryEntities">
                    <list>
                        <bean class="org.apache.ignite.cache.QueryEntity">
                            <!-- Setting indexed type's key class -->
                            <property name="keyType"
                                value="ru.raiffeisen.cache.repository.EntryKey" />
                            <!-- Setting indexed type's value class -->
                            <property name="valueType" value="ru.raiffeisen.cache.repository.Entry" />

                            <!-- Defining fields that will be either indexed or queryable. Indexed 
                                fields are added to 'indexes' list below. -->
                            <property name="fields">
                                <map>
                                    <entry key="key.accNumber" value="java.lang.String" />
                                    <entry key="key.d_c" value="ru.raiffeisen.cache.repository.EntryKey.DEB_CRE" />
                                    <entry key="key.valuedate" value="java.util.Date" />
                                    <entry key="summa" value="java.lang.Integer " />
                                </map>
                            </property>

                            <!-- Defining indexed fields. -->
                            <property name="indexes">
                                <list>
                                    <!-- Single field (aka. column) index -->
                                    <bean class="org.apache.ignite.cache.QueryIndex">
                                        <constructor-arg value="key.accNumber" />
                                    </bean>
                                </list>
                            </property>

                        </bean>
                    </list>
                </property>
            </bean>

Solution

  • Thanks to everyone for suggestions.

    I achieved an option which gives a stable and correct result.

    Actually I moved the field accNumber from the key class to the value class. So now select is filtered against a primitive field of the value class.

    Query configuration:

                            <bean class="org.apache.ignite.cache.QueryEntity">
                            <!-- Setting indexed type's key class -->
                            <property name="keyType"
                                value="ru.raiffeisen.cache.repository.EntryKey" />
                            <!-- Setting indexed type's value class -->
                            <property name="valueType" value="ru.raiffeisen.cache.repository.Entry" />
    
                            <!-- Defining fields that will be either indexed or queryable. Indexed 
                                fields are added to 'indexes' list below. -->
                            <property name="fields">
                                <map>
                                    <entry key="accNumber" value="java.lang.String" />
                                    <entry key="key.d_c" value="ru.raiffeisen.cache.repository.EntryKey.DEB_CRE" />
                                    <entry key="key.valuedate" value="java.util.Date" />
                                    <entry key="summa" value="java.lang.Integer " />
                                </map>
                            </property>
    
                            <!-- Defining indexed fields. -->
                            <property name="indexes">
                                <list>
                                    <!-- Single field (aka. column) index -->
                                    <bean class="org.apache.ignite.cache.QueryIndex">
                                        <constructor-arg value="accNumber" />
                                    </bean>
                                </list>
                            </property>
    
                        </bean>