Apache Ignite: 在重新连接到Ignite服务器后,缓存无法使用。

huangapple go评论67阅读模式
英文:

Apache Ignite: Caches unusable after reconnecting to Ignite servers

问题

我正在使用Apache Ignite作为分布式缓存,但遇到了一些基本的稳定性问题。如果我们的Ignite服务器因任何原因重新启动,似乎会导致所有的Ignite客户端失效,即使在Ignite服务器恢复在线后也是如此。

在服务器重新启动并且客户端重新连接之后,客户端看到的错误如下:

Caused by: org.apache.ignite.internal.processors.cache.CacheStoppedException: Failed to perform cache operation (cache is stopped): <redacted>

我预期Ignite客户端会在Ignite服务器恢复在线后重新连接,并继续正常工作。根据我所阅读的内容,厚客户端应该会这样做,但实际情况并非如此。为什么缓存仍然被视为已停止?

我们正在使用带有Kubernetes IP查找器的Ignite 2.7.6版本。

英文:

I am using Apache Ignite as a distributed cache and I am running into some fundamental robustness issues. If our Ignite servers reboot for any reason it seems like this breaks all of our Ignite clients, even after the Ignite servers come back online.

This is the error the clients see when interacting with caches after the servers reboot and the clients reconnect:

Caused by: org.apache.ignite.internal.processors.cache.CacheStoppedException: Failed to perform cache operation (cache is stopped): <redacted>

My expectation is that the Ignite clients would reconnect to the Ignite servers and continue working once the servers are online. From what I've read thick clients should do this, but I don't see this happening. Why is the cache still considered to be stopped?

We are using Ignite 2.7.6 with Kubernetes IP finder.

答案1

得分: 6

看起来你正在使用过期的缓存代理。
如果你正在使用内存集群,并且从客户端动态创建缓存,那么当集群重新启动时,所给定的缓存将会消失。

以下代码在客户端针对内存集群执行,如果所讨论的缓存不是服务器配置的一部分,而是在客户端上动态创建的,则在集群重新启动时将生成异常。

Ignition.setClientMode(true);
Ignite = Ignition.start();

IgniteCache cache = ignite.getOrCreateCache("mycache"); //动态创建的缓存

int counter = 0;
while(true) {
    try {
        cache.put(counter, counter);
        System.out.println("added counter: " + counter);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

生成的异常:

java.lang.IllegalStateException: class org.apache.ignite.internal.processors.cache.CacheStoppedException: Failed to perform cache operation (cache is stopped): mycache
	at org.apache.ignite.internal.processors.cache.GridCacheGateway.enter(GridCacheGateway.java:164)
	at org.apache.ignite.internal.processors.cache.GatewayProtectedCacheProxy.onEnter(GatewayProtectedCacheProxy.java:1555)

你需要注意断开连接的事件/异常。

参见:https://ignite.apache.org/docs/latest/clustering/connect-client-nodes

IgniteCache cache = ignite.getOrCreateCache(cachecfg);

try {
    cache.put(1, "value");
} catch (IgniteClientDisconnectedException e) {
    if (e.getCause() instanceof IgniteClientDisconnectedException) {
        IgniteClientDisconnectedException cause = (IgniteClientDisconnectedException) e.getCause();

        cause.reconnectFuture().get(); // 等待客户端重新连接。
        // 继续操作

如果这是一个由多个基准节点组成的持久性集群,
你应该等到集群激活。

https://ignite.apache.org/docs/latest/clustering/baseline-topology

while (!ignite.cluster().active()) {
    System.out.println("等待激活");
    Thread.sleep(5000);
}

在重新连接后,您可能需要重新初始化缓存代理

cache = ignite.getOrCreateCache(cachecfg); 
}   
英文:

Looks like you are using a stale cache proxy. <br>
If you are using an in memory-cluster, and created a cache dynamically from a client, then the given cache will disappear when the cluster restarts.

The following code, executed from a client against an in-memory cluster, will generate an exception when the cluster restarts, if the cache in question is not part of a server config, but created dynamically on the client.

       Ignition.setClientMode(true);
       Ignite = Ignition.start();

       IgniteCache cache = ignite.getOrCreateCache(&quot;mycache&quot;); //dynamically created cache


        int counter = 0;
        while(true) {
            try {
                cache.put(counter, counter);
                System.out.println(&quot;added counter: &quot; + counter);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

generates

java.lang.IllegalStateException: class org.apache.ignite.internal.processors.cache.CacheStoppedException: Failed to perform cache operation (cache is stopped): mycache
	at org.apache.ignite.internal.processors.cache.GridCacheGateway.enter(GridCacheGateway.java:164)
	at org.apache.ignite.internal.processors.cache.GatewayProtectedCacheProxy.onEnter(GatewayProtectedCacheProxy.java:1555)

You need to watch for disconnect events/exceptions

see: https://ignite.apache.org/docs/latest/clustering/connect-client-nodes

IgniteCache cache = ignite.getOrCreateCache(cachecfg);

try {
    cache.put(1, &quot;value&quot;);
} catch (IgniteClientDisconnectedException e) {
    if (e.getCause() instanceof IgniteClientDisconnectedException) {
        IgniteClientDisconnectedException cause = (IgniteClientDisconnectedException) e.getCause();

        cause.reconnectFuture().get(); // Wait until the client is reconnected.
        // proceed

If this is a persistent cluster consisting of multiple baseline nodes,
you should wait until the cluster activates.
<br>
https://ignite.apache.org/docs/latest/clustering/baseline-topology

  while (!ignite.cluster().active()) {
      System.out.println(&quot;Waiting for activation&quot;);
      Thread.sleep(5000);
  }

After re-connect you might need to reinitialize your cache proxy

       cache = ignite.getOrCreateCache(cachecfg); 
}   

huangapple
  • 本文由 发表于 2020年10月23日 04:06:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/64489779.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定