【问题标题】:Ignite Java Thin Client - Connection fails when one node is downIgnite Java Thin Client - 一个节点关闭时连接失败
【发布时间】:2019-09-24 00:30:11
【问题描述】:

我们有一个包含 3 个节点的 ignite 集群,所有服务都使用 java 瘦客户端连接到集群。

当其中一个服务器节点出现故障并且服务正在尝试连接时,很少有人获得连接成功,并且很少有人因 ignite cluster 不可用错误而失败。于是我们调试源码发现,在ReliableChannel对象构造过程中,随机选择了一个节点进行连接,如果该节点不可用,则抛出客户端连接异常。

理想情况下,我们希望它回退到其他节点,因为集群中有其他节点可用。我们看到上面提到的逻辑是在 ReliableChannel 类的 service 方法中实现的。

在对象构造期间没有实现回退并且仅在服务方法上使用它(任何连接到其他节点的选项)是否有任何具体原因?

另外,我们是否可以控制节点的连接顺序?

ReliableChannel 代码 sn-p

ReliableChannel(
        Function<ClientChannelConfiguration, Result<ClientChannel>> chFactory,
        ClientConfiguration clientCfg
    ) throws ClientException {
        if (chFactory == null)
            throw new NullPointerException("chFactory");

        if (clientCfg == null)
            throw new NullPointerException("clientCfg");

        this.chFactory = chFactory;
        this.clientCfg = clientCfg;

        List<InetSocketAddress> addrs = parseAddresses(clientCfg.getAddresses());

        primary = addrs.get(new Random().nextInt(addrs.size())); // we already verified there is at least one address

        ch = chFactory.apply(new ClientChannelConfiguration(clientCfg).setAddress(primary)).get();

        for (InetSocketAddress a : addrs)
            if (a != primary)
                this.backups.add(a);
    }


    public <T> T service(
        ClientOperation op,
        Consumer<BinaryOutputStream> payloadWriter,
        Function<BinaryInputStream, T> payloadReader
    ) throws ClientException {
        ClientConnectionException failure = null;

        T res = null;

        int totalSrvs = 1 + backups.size();

        svcLock.lock();
        try {
            for (int i = 0; i < totalSrvs; i++) {
                try {
                    if (failure != null)
                        changeServer();

                    if (ch == null)
                        ch = chFactory.apply(new ClientChannelConfiguration(clientCfg).setAddress(primary)).get();

                    long id = ch.send(op, payloadWriter);

                    res = ch.receive(op, id, payloadReader);

                    failure = null;

                    break;
                }
                catch (ClientConnectionException e) {
                    if (failure == null)
                        failure = e;
                    else
                        failure.addSuppressed(e);
                }
            }
        }
        finally {
            svcLock.unlock();
        }

        if (failure != null)
            throw failure;

        return res;
    }

【问题讨论】:

    标签: java ignite


    【解决方案1】:

    这个问题将在 Apache Ignite 2.8 中修复:IGNITE-11599

    也许它已经在 GridGain 中修复,向后移植此类修复。

    【讨论】:

      猜你喜欢
      • 2021-07-23
      • 1970-01-01
      • 2015-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-28
      • 1970-01-01
      • 2016-01-27
      相关资源
      最近更新 更多