fix: set freezed when slaveConnectionPool and pubSubConnectionPool all inited completed

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

@ -56,7 +56,7 @@ public class ClientConnectionsEntry {
private final AtomicLong firstFailTime = new AtomicLong(0); private final AtomicLong firstFailTime = new AtomicLong(0);
private volatile boolean initing = false; private volatile boolean inited = 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) {
@ -84,12 +84,12 @@ public class ClientConnectionsEntry {
&& getNodeType() == NodeType.MASTER; && getNodeType() == NodeType.MASTER;
} }
public boolean isIniting() { public boolean isInited() {
return this.initing; return this.inited;
} }
public void setIniting(boolean isIniting) { public void setInited(boolean isInited) {
this.initing = isIniting; this.inited = isInited;
} }
public void setNodeType(NodeType nodeType) { public void setNodeType(NodeType nodeType) {
@ -126,7 +126,7 @@ public class ClientConnectionsEntry {
public void setFreezeReason(FreezeReason freezeReason) { public void setFreezeReason(FreezeReason freezeReason) {
this.freezeReason = freezeReason; this.freezeReason = freezeReason;
if (freezeReason != null) { if (freezeReason != null) {
this.initing = false; this.inited = false;
} }
} }

@ -20,6 +20,8 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiConsumer;
import org.redisson.api.NodeType; import org.redisson.api.NodeType;
import org.redisson.api.RFuture; import org.redisson.api.RFuture;
@ -138,16 +140,27 @@ public class LoadBalancerManager {
if (freezeReason != FreezeReason.RECONNECT if (freezeReason != FreezeReason.RECONNECT
|| entry.getFreezeReason() == FreezeReason.RECONNECT) { || entry.getFreezeReason() == FreezeReason.RECONNECT) {
if (!entry.isIniting()) { if (!entry.isInited()) {
entry.setIniting(true); entry.setInited(true);
entry.resetFirstFail(); AtomicInteger initedCounter = new AtomicInteger(2);
slaveConnectionPool.initConnections(entry).onComplete((r, ex) -> { RPromise<Void> promise = new RedissonPromise<Void>();
entry.setIniting(false); promise.onComplete((r, ex) -> {
if (ex == null) { if (ex == null) {
entry.setFreezeReason(null); entry.setFreezeReason(null);
} }
}); });
pubSubConnectionPool.initConnections(entry); BiConsumer<Void, Throwable> initCallBack = (r, ex) -> {
if (ex == null) {
if (initedCounter.decrementAndGet() == 0) {
promise.trySuccess(null);
}
} else {
promise.tryFailure(ex);
}
};
entry.resetFirstFail();
slaveConnectionPool.initConnections(entry).onComplete(initCallBack);
pubSubConnectionPool.initConnections(entry).onComplete(initCallBack);
return true; return true;
} }
} }

Loading…
Cancel
Save