【发布时间】: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;
}
【问题讨论】: