看起来你正在使用一个过期的缓存代理。
如果你正在使用内存集群,并且从客户端动态创建了一个缓存,那么当集群重新启动时,这个缓存将消失。
下面的代码在客户端对内存集群执行时,如果所涉及的缓存不是服务器配置的一部分,而是在客户端上动态创建的,则在集群重新启动时会生成异常。
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("Waiting for activation");
Thread.sleep(5000);
}
重新连接后,您可能需要重新初始化您的缓存代理。
cache = ignite.getOrCreateCache(cachecfg);
}