1

I have a query re. the setup of the GridGain near cache, we have a single server node with the config as listed below and have a single thick client connecting successfully to it ~

    <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean class="org.apache.ignite.configuration.IgniteConfiguration">

<!-- PEER CLASS LOADING -->
        <property name="peerClassLoadingEnabled" value="true"/>
        
<!-- CACHE CONFIG-->
        <property name="cacheConfiguration">
            <list>
<!-- ENTER CACHE TEMPLATE-->
                <bean class="org.apache.ignite.configuration.CacheConfiguration">
                    <property name="name" value="cache1"/>
                    <property name="cacheMode" value="PARTITIONED"/>
                    <property name="rebalanceMode" value="SYNC"/>
                    <property name="nearConfiguration">
                    <bean class="org.apache.ignite.configuration.NearCacheConfiguration">
                        <property name="nearEvictionPolicyFactory">
                            <bean class="org.apache.ignite.cache.eviction.lru.LruEvictionPolicyFactory">
                                <property name="maxSize" value="100000"/>
                            </bean>
                        </property>
                    </bean>
                    </property>
                </bean>
                <bean class="org.apache.ignite.configuration.CacheConfiguration">
                    <property name="name" value="cache2"/>
                    <property name="cacheMode" value="PARTITIONED"/>
                    <property name="rebalanceMode" value="SYNC"/>
                    <property name="nearConfiguration">
                    <bean class="org.apache.ignite.configuration.NearCacheConfiguration">
                        <property name="nearEvictionPolicyFactory">
                            <bean class="org.apache.ignite.cache.eviction.lru.LruEvictionPolicyFactory">
                                <property name="maxSize" value="100000"/>
                            </bean>
                        </property>
                    </bean>
                    </property>
                </bean>      
                <bean class="org.apache.ignite.configuration.CacheConfiguration">
                    <property name="name" value="cache3"/>
                    <property name="cacheMode" value="PARTITIONED"/>
                    <property name="rebalanceMode" value="SYNC"/>
                    <property name="nearConfiguration">
                    <bean class="org.apache.ignite.configuration.NearCacheConfiguration">
                        <property name="nearEvictionPolicyFactory">
                            <bean class="org.apache.ignite.cache.eviction.lru.LruEvictionPolicyFactory">
                                <property name="maxSize" value="100000"/>
                            </bean>
                        </property>
                    </bean>
                    </property>
                </bean>                            
            </list>
        </property>

<!-- DISCOVERY-->
        <property name="discoverySpi">
            <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
                <property name="ipFinder">
                    <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.kubernetes.TcpDiscoveryKubernetesIpFinder">
                        <property name="namespace" value="gridgain"/>
                        <property name="serviceName" value="gridgain-service"/>
                    </bean>
                </property>
            </bean>
        </property>
    </bean>
</beans>

In setting the server up like this it was my understanding that as per the documentation here , that "Once configured in this way, the near cache is created on any node that requests data from the underlying cache, including both server nodes and client nodes. When you get an instance of the cache, as shown in the following example, the data requests go through the near cache.

IgniteCache<Integer, Integer> cache = ignite.cache("myCache");

int value = cache.get(1);

Based on this I do not believe that I have any need to create the near cache config on our client? and have just implemented code as ~ IgniteCache<Object, Object> cache = ignite.cache(ourCacheName);

The issue I see is that when I peek at the local cache to try and find values in there, after searching for them ~ cache_.localPeek(key, CachePeekMode.NEAR)

The objects are not found, despite being searched for several times, and it looks like they are not added to our near cache setup, everything just refers to the underlying cache. Previously we had programmatically created the Near cache on the client and it had worked, but we would like to config the solution on the server if possible. Our client node is just using default config, if this makes a difference.

Any thoughts why we are not seeing a near cache?

Thanks, LS

Vladimir Pligin
  • 1,547
  • 11
  • 18
  • It's not clear from the description - does near cache work well for servers, but it is not working on clients, is that correct? Or it's not working for any node? – Alexandr Shapkin Dec 07 '22 at 11:20
  • I'm doing the cache_.localPeek(key, CachePeekMode.NEAR) on the client node and specifically can't see any indication that a near cache has been set up on the client i.e. size is always 0 on the client with CachePeekMode.NEAR. I guess I am wondering if the configuration listed above needs to be implemented on both server and the client? From the documentation it reads like it is only needed on the server and the near cache would automatically be created on anything that called that cache? – LostShepherd Dec 07 '22 at 11:28
  • I haven't checked it formally, but I'm pretty sure you need to add it to the client conf as well, or create dynamically https://www.gridgain.com/docs/latest/developers-guide/near-cache#creating-near-cache-dynamically-on-client-nodes – Vladimir Pligin Dec 07 '22 at 12:06
  • I see, yes, as far as I remember, this API is super confusing, I'll try to wrap it up in an answer. – Alexandr Shapkin Dec 07 '22 at 12:11

1 Answers1

1

In order to use the cache I suggest you create the near cache explicitly using the following syntax:

IgniteCache<Integer, Integer> clientCache = client.getOrCreateNearCache(cacheCfg.getName(), nearCfg);
    ...
clientCache.get(1);
System.out.println(clientCache.localPeek(1,  CachePeekMode.NEAR));

There are some tickets like IGNITE-15960 or IGNITE-1163 with discussions about the API improvements. I suppose the cache has to be declared on the servers first and then you would be able to create it explicitly on the clients. Agree, the docs and API are super confusing and have to be reworked.

Also, the near cache is local to a node, i.e. you might have them for some clients/servers and do not want to create it for other ones.

Alexandr Shapkin
  • 2,350
  • 1
  • 6
  • 10
  • Thanks all, your help is much appreciated as I was not sure if I was just misinterpreting the docs, is clear now. I had the code working previously by programmatically enabling the near cache on the client nodes as described so I will revert back to that, leaving the xml config minus near cache config on the server. It seems for now at least my initial interpretation was incorrect i.e. setting up the near cache config on the server node does not auto create near caches on clients that connect. – LostShepherd Dec 07 '22 at 12:49