Apache Ignite:重新连接到 Ignite 服务器后缓存不可用
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 服务器并在服务器联机后继续工作。据我了解,胖客户端应该这样做,但我没有看到这种情况发生。为什么缓存仍然被认为已停止?
我们正在使用 Ignite 2.7.6 和 Kubernetes IP 查找器。
您似乎在使用过时的缓存代理。
如果您使用 in memory-cluster,并从客户端动态创建缓存,则当集群重新启动时,给定的缓存将消失。
以下代码从客户端针对 in-memory 集群执行,如果有问题的缓存不是服务器配置的一部分,而是在客户端动态创建,则集群重新启动时将生成异常.
Ignition.setClientMode(true);
Ignite = Ignition.start();
IgniteCache cache = ignite.getOrCreateCache("mycache"); //dynamically created cache
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)
您需要注意断开连接events/exceptions
参见: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(); // Wait until the client is reconnected.
// proceed
如果这是一个由多个基线节点组成的持久化集群,
您应该等到集群激活。
https://ignite.apache.org/docs/latest/clustering/baseline-topology
while (!ignite.cluster().active()) {
System.out.println("Waiting for activation");
Thread.sleep(5000);
}
在 re-connect 之后,您可能需要重新初始化缓存代理
cache = ignite.getOrCreateCache(cachecfg);
}
我正在使用 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 服务器并在服务器联机后继续工作。据我了解,胖客户端应该这样做,但我没有看到这种情况发生。为什么缓存仍然被认为已停止?
我们正在使用 Ignite 2.7.6 和 Kubernetes IP 查找器。
您似乎在使用过时的缓存代理。
如果您使用 in memory-cluster,并从客户端动态创建缓存,则当集群重新启动时,给定的缓存将消失。
以下代码从客户端针对 in-memory 集群执行,如果有问题的缓存不是服务器配置的一部分,而是在客户端动态创建,则集群重新启动时将生成异常.
Ignition.setClientMode(true);
Ignite = Ignition.start();
IgniteCache cache = ignite.getOrCreateCache("mycache"); //dynamically created cache
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)
您需要注意断开连接events/exceptions
参见: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(); // Wait until the client is reconnected.
// proceed
如果这是一个由多个基线节点组成的持久化集群,
您应该等到集群激活。
https://ignite.apache.org/docs/latest/clustering/baseline-topology
while (!ignite.cluster().active()) {
System.out.println("Waiting for activation");
Thread.sleep(5000);
}
在 re-connect 之后,您可能需要重新初始化缓存代理
cache = ignite.getOrCreateCache(cachecfg);
}