Failed to start near cache (a cache with the same name without near cache is already started

classic Classic list List threaded Threaded
4 messages Options
sherryhw sherryhw
Reply | Threaded
Open this post in threaded view
|

Failed to start near cache (a cache with the same name without near cache is already started

Hi there,
I have an issue with near cache.
I deploy an ignite cluster on server side and run a ignite client in my
local.
I would like to use NearCache for my local client.
Lets say, I have 4 Near cache configuration which corresponding to 4 cache
"CacheA", "CacheB", "CacheC",and "CacheD". And these 4 caches is related to
TableA, TableB, TableC and TableD.

If I use  " ignite.getOrCreateNearCache("CacheA", nearCacheAConfiguration)"
seperately, everything works fine for all these 4 different cache.
However, I also have a use case to use Cross-Cache Queries,
for eg:  "
SqlFieldsQuery sql = new SqlFieldsQuery("SELECT A.COLUMN1, B.COLUMN2 FROM
TableA AS A LEFT JOIN TableB AS B ON A.COLUMN3 = b.COLUMN4 WHERE ... ");
this.ignite.getOrCreateNearCache("CacheA",nearCacheAConfiguration
).query(sql).getAll()...
"
And if I run the second method, it will show error logs like
"javax.cache.CacheException: class org.apache.ignite.IgniteCheckedException:
Failed to start near cache (a cache with the same name without near cache is
already started)"
And also everytime if i run cross caches queries, it will start all caches.

So my question is, if i want to use near cache for single cache and also
cross cache query, is there a way to config?
Thanks!
Sherry



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Alexey Kukushkin Alexey Kukushkin
Reply | Threaded
Open this post in threaded view
|

Re: Failed to start near cache (a cache with the same name without near cache is already started

Hi,

Near caches are configured per cache and not per query. You cannot start different near caches for the same distributed cache. Start separate near caches for TableA and TableB. 
sherryhw sherryhw
Reply | Threaded
Open this post in threaded view
|

Re: Failed to start near cache (a cache with the same name without near cache is already started

Hi Alex,
Thank you for your reply.
But I am not quite clear about how to create near cache for TableA and
TableB?
Thanks,
Sherry



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Alexey Kukushkin Alexey Kukushkin
Reply | Threaded
Open this post in threaded view
|

Re: Failed to start near cache (a cache with the same name without near cache is already started

Hi,

Near caches are transparent for you - there is no user API to get reference to or work with near caches. The purpose of a near cache is to "cache the cache", that is to be a local cache for a distributed cache. Ignite transparently fills near cache with the most recent data when you work with the underlying distributed cache. That also means you should not use near cache if you use co-located (server-side) data access/computations since near cache is local by definition.

There are two kinds of API to create a near cache:
  1. Create near cache for existing distributed cache: ignite.getOrCreateNearCache(existnigDistibutedCacheName, nearCacheConfiguration). This will return the exiting distributed cache and start a near cache for it or fail if the distributed cache does not exist.
  2. Create a new distributed cache with near cache:  ignite.createCache(newDistibutedCacheName, nearCacheConfiguration)
  3. ignite.getOrCreateCache(distibutedCacheName, nearCacheConfiguration) - this behaves like option 1 or 2 depending on whether the distributed cache exists.
Thus, answering your question - use any of the API above to create a near cache for "TableA". for example:

Cache<?, ?> tableA = ignite.getOrCreateCache("TableA", new NearCacheConfiguration));