Not able to perform cache queries

classic Classic list List threaded Threaded
6 messages Options
gauri.jagtap gauri.jagtap
Reply | Threaded
Open this post in threaded view
|

Not able to perform cache queries

This post has NOT been accepted by the mailing list yet.
Idea is to query the distributed cache by enabling the readThrough and writeThrough cache configurations.

Problem:
  Able to load cache using ignite cache API but not able to query the cache

 
 Cache Configuration
               
               
        if (ignite == null) {
                        ignite = Ignition .start("C:/workspace/consoleresource/cache.service.impl/src/main/resources/example-ignite.xml");
                } else {
                        log.info("ignite instance already exists");
                }

                CacheConfiguration<Integer, PersonCache> cfg = new CacheConfiguration(
                                CACHE_NAME);
                cfg.setIndexedTypes(Integer.class, PersonCache.class);
                cfg.setCacheMode(CacheMode.PARTITIONED);
                cfg.setAtomicityMode(TRANSACTIONAL);
                cfg.setCacheStoreFactory((Factory<? extends CacheStore<? super Integer, ? super PersonCache>>) FactoryBuilder
                                .factoryOf(ProtocolStore.class));

                cfg.setCacheStoreSessionListenerFactories(new Factory<CacheStoreSessionListener>() {
                        @Override
                        public CacheStoreSessionListener create() {
                                CacheJdbcStoreSessionListener lsnr = new CacheJdbcStoreSessionListener();

                                lsnr.setDataSource(datasource);

                                return lsnr;
                        }
                });

                cfg.setReadThrough(true);
                cfg.setWriteThrough(true);

                try {
                        IgniteCache<Integer, PersonCache> cache = ignite
                                        .createCache(cfg);
                       
                        loadCache(cache);
                        }


               
Sample Cache Query
       
IgniteCache<Integer, ProtocolCache> cache = Ignition.ignite().cache(CACHE_NAME);
String sql =  "select * from PersonCache";
QueryCursor<Entry<Integer, PersonCache>> cursor = cache.query(new SqlQuery<Integer, PersonCache>(PersonCache.class,sql));

List<Entry<Integer, PersonCache>> cursResult = cursor.getAll();


                       
Denis Magda Denis Magda
Reply | Threaded
Open this post in threaded view
|

Re: Not able to perform cache queries

Hi,

What do you mean saying that you're not able to perform SQL queries?
Do you get an error, empty or partial result set? Please be more specific.

In any case I want to draw your attention that if there is still some data in a cache storage that has to be loaded then it won't be loaded automatically during a SQL query execution regardless whether readThrough is enabled or not.

If you're sure that all the data is loaded please make a call like this to check the cache size:
cache.size(CachePeekMode.PRIMARY).

And please properly subscribe to the user list (this way we will not have to manually approve your emails). All you need to do is send an email to “user-subscribe@ignite.apache.org” and follow simple instructions in the reply.

Regards,
Denis
gauri.jagtap gauri.jagtap
Reply | Threaded
Open this post in threaded view
|

Re: Not able to perform cache queries

Hi,

I am getting empty result set, but I can see cache is loaded with all data.
Checked the cache size using "cache.size(CachePeekMode.PRIMARY)" and I am getting expected cache size.
But when I am performing "select * " operation using "cache.query(...)" I am getting empty resultset.

Thank you
Denis Magda Denis Magda
Reply | Threaded
Open this post in threaded view
|

Re: Not able to perform cache queries

The only strange thing I see in your code is the following line

IgniteCache<Integer, ProtocolCache> cache = Ignition.ignite().cache(CACHE_NAME);

Here you get instance of a cache name CACHE_NAME, that according to the generic holds ProtocolCache, but right after tries to query PersonCache objects. Probably CACHE_NAME is not a valid one, please double-check that this is not your case.

BTW, open CacheQueryExample, that is a part of Ignite, add the function below to it and execute it

    private static void personsQuery() {
        IgniteCache<Integer, Person> cache = Ignition.ignite().cache(PERSON_CACHE);

        String sql = "select * from Person";

        QueryCursor<Cache.Entry<Integer, Person>> cursor = cache.query(new SqlQuery<Integer,
            Person>(Person.class, sql));

        List<Cache.Entry<Integer, Person>> cursResult = cursor.getAll();

        System.out.println("size persons = " + cursResult.size());
    }

Everything should work fine on your side and if it's so then I would recommend you look into how the example works. Probably the example will help you to find something that is missing on your side.

If nothing helps then please send me a reproducible example.

--
Denis
gauri.jagtap gauri.jagtap
Reply | Threaded
Open this post in threaded view
|

Re: Not able to perform cache queries

Hi,

I was able to execute queries on cache after disabling Readthrough, WriteThrough configuration. But with the same query when I use Readthrough, WriteThrough configuration I am getting empty result set.
I am referring to ignite examples, there I couldn't find queries executed after enabling store configuration.
It will be great help if you can provide me such example.

Thank you
Denis Magda Denis Magda
Reply | Threaded
Open this post in threaded view
|

Re: Not able to perform cache queries

Hi,

Could you share a runnable example, that demonstrates the issue, over GitHub or some other way?

For me it's unclear how readThrough or writeThrough can affect a result of a SQL query having in mind that the full data set has already been loaded from the storage and the data set is not being changed while queries are being executed. This is exactly your case, correct?

As an example to can refer to CacheDummyStoreExample. However you need to modify it a bit:

1) Activate indexing for the cache used in the example
cacheCfg.setIndexedTypes(Long.class, Person.class);

2) Add and call the following function

    private static void personsQuery() {
        IgniteCache<Integer, Person> cache =
            Ignition.ignite().cache("CacheDummyStoreExample");

        String sql = "select * from Person";

        QueryCursor<Cache.Entry<Integer, Person>> cursor =
            cache.query(new SqlQuery<Integer,
                            Person>(Person.class, sql));

        List<Cache.Entry<Integer, Person>> cursResult = cursor.getAll();

        System.out.println("size persons = " + cursResult.size());
    }

--
Denis