我使用 Apache Ignite 作为分布式缓存,但遇到了一些基本的健壮性问题。如果我们的 Ignite 服务器出于任何原因重新启动,这似乎会破坏我们所有的 Ignite 客户端,即使在 Ignite 服务器重新联机之后也是如此。
这是在服务器重新启动和客户端重新连接后客户端与缓存交互时看到的错误:
Caused by: org.apache.ignite.internal.processors.cache.CacheStoppedException: Failed to perform cache operation (cache is stopped): <redacted>
Run Code Online (Sandbox Code Playgroud)
我的期望是 Ignite 客户端会重新连接到 Ignite 服务器并在服务器联机后继续工作。从我读到的胖客户端应该这样做,但我没有看到这种情况发生。为什么缓存仍然被认为是停止的?
我们将 Ignite 2.7.6 与 Kubernetes IP 查找器一起使用。
看起来您正在使用陈旧的缓存代理。
如果您使用内存集群,并从客户端动态创建缓存,则给定的缓存将在集群重新启动时消失。
以下代码从客户端针对内存集群执行,如果有问题的缓存不是服务器配置的一部分,而是在客户端动态创建,则在集群重新启动时将生成异常。
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();
}
}
Run Code Online (Sandbox Code Playgroud)
产生
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)
Run Code Online (Sandbox Code Playgroud)
您需要注意断开连接事件/异常
请参阅: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
Run Code Online (Sandbox Code Playgroud)
如果这是一个由多个基线节点组成的持久集群,您应该等到集群激活。
https://ignite.apache.org/docs/latest/clustering/baseline-topology
while (!ignite.cluster().active()) {
System.out.println("Waiting for activation");
Thread.sleep(5000);
}
Run Code Online (Sandbox Code Playgroud)
重新连接后,您可能需要重新初始化缓存代理
cache = ignite.getOrCreateCache(cachecfg);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
184 次 |
| 最近记录: |