帖子链接: meta服务心跳失败以及leader changed
现场快照:
问题: 应用程序运行一段时间后,依旧出现以上异常.
如有需要其他信息,请提出.
SessionPool 代码案例:
public class AlephNebulaSessionPool {
private final int borrowWaitTime;
private final NebulaPool nebulaPool;
private final ArrayBlockingQueue<Session> sessionArrayBlockingQueue;
public AlephNebulaSessionPool(NebulaPool nebulaPool, int maxConnSize, int borrowWaitTime) {
this.nebulaPool = nebulaPool;
this.borrowWaitTime = borrowWaitTime;
this.sessionArrayBlockingQueue = new ArrayBlockingQueue<>(maxConnSize);
}
public Session borrow(String userName, String password, boolean reconnect) {
Session session;
// if not supported reconnect, skip borrow session from queue.
if (!reconnect) return newSession(userName, password, reconnect);
if (sessionArrayBlockingQueue.isEmpty()) return newSession(userName, password, reconnect);
try {
session = sessionArrayBlockingQueue.poll(borrowWaitTime, TimeUnit.MILLISECONDS);
// if session exists, then inspect the session whether it has been released by idle timeout.
// if not then return the session, otherwise release the unused session, and create a new session or not polling from queue.
if (session != null) {
if (session.ping()) return session;
session.release();
}
return newSession(userName, password, reconnect);
} catch (InterruptedException e) {
return newSession(userName, password, reconnect);
}
}
public void release(Session session) {
if (session == null) return;
// inspect the session valid in stern.
if (!session.ping()) return;
boolean offered = sessionArrayBlockingQueue.offer(session);
// if overflow the session queue capacity, deprecated it.
if (!offered) session.release();
}
Session newSession(String userName, String password, boolean reconnect) {
try {
return nebulaPool.getSession(userName, password, reconnect);
} catch (NotValidConnectionException | AuthFailedException | ClientServerIncompatibleException | IOErrorException e) {
throw new AlephSessionException("Error opening session. Cause: " + e.getMessage(), e);
}
}
}