fix: add initing status in entry, and set entry freezed status null when all connection inited

Signed-off-by: xujie <mikawudi@qq.com>
pull/3295/head
xujie 4 years ago
parent bf76f30c2a
commit b7cfd1ff0f

@ -56,6 +56,8 @@ public class ClientConnectionsEntry {
private final AtomicLong firstFailTime = new AtomicLong(0); private final AtomicLong firstFailTime = new AtomicLong(0);
private volatile boolean initing = false;
public ClientConnectionsEntry(RedisClient client, int poolMinSize, int poolMaxSize, int subscribePoolMinSize, int subscribePoolMaxSize, public ClientConnectionsEntry(RedisClient client, int poolMinSize, int poolMaxSize, int subscribePoolMinSize, int subscribePoolMaxSize,
ConnectionManager connectionManager, NodeType nodeType) { ConnectionManager connectionManager, NodeType nodeType) {
this.client = client; this.client = client;
@ -81,10 +83,19 @@ public class ClientConnectionsEntry {
&& connectionManager.getConfig().getReadMode() == ReadMode.MASTER_SLAVE && connectionManager.getConfig().getReadMode() == ReadMode.MASTER_SLAVE
&& getNodeType() == NodeType.MASTER; && getNodeType() == NodeType.MASTER;
} }
public boolean isIniting() {
return this.initing;
}
public void setIniting(boolean isIniting) {
this.initing = isIniting;
}
public void setNodeType(NodeType nodeType) { public void setNodeType(NodeType nodeType) {
this.nodeType = nodeType; this.nodeType = nodeType;
} }
public NodeType getNodeType() { public NodeType getNodeType() {
return nodeType; return nodeType;
} }

@ -138,12 +138,18 @@ public class LoadBalancerManager {
if (freezeReason != FreezeReason.RECONNECT if (freezeReason != FreezeReason.RECONNECT
|| entry.getFreezeReason() == FreezeReason.RECONNECT) { || entry.getFreezeReason() == FreezeReason.RECONNECT) {
entry.resetFirstFail(); if (!entry.isIniting()) {
entry.setFreezeReason(null); entry.setIniting(true);
entry.resetFirstFail();
slaveConnectionPool.initConnections(entry); slaveConnectionPool.initConnections(entry).onComplete((r, ex) -> {
pubSubConnectionPool.initConnections(entry); entry.setIniting(false);
return true; if (ex == null) {
entry.setFreezeReason(null);
}
});
pubSubConnectionPool.initConnections(entry);
return true;
}
} }
} }
return false; return false;

Loading…
Cancel
Save