【问题标题】:Apache Ignite: Caches unusable after reconnecting to Ignite serversApache Ignite:重新连接到 Ignite 服务器后缓存无法使用
【发布时间】:2021-02-05 21:58:01
【问题描述】:

我使用 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 finder 的 Ignite 2.7.6。

【问题讨论】:

    标签: java ignite


    【解决方案1】:

    看起来您使用的是陈旧的缓存代理。
    如果您使用的是内存集群,并从客户端动态创建了缓存,那么给定的缓存将在集群重新启动时消失。

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

           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)
    

    您需要注意断开连接事件/异常

    见: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);
      }
    
    

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

           cache = ignite.getOrCreateCache(cachecfg); 
    }   
    

    【讨论】:

    • 感谢您的回复。我想我希望这一切都能在后台自动完成,就像我们的数据库或队列连接在服务重新上线时正常工作一样。
    • 我想我可以构建一个抽象层,用逻辑来包装所有 ignite 缓存方法,以处理断开连接并重新初始化缓存代理。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-10
    • 2023-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-05
    • 1970-01-01
    相关资源
    最近更新 更多