Checking enough connections amount according settings during Redisson start.

pull/337/head
Nikita 9 years ago
parent 15838bbfa5
commit ec53659eec

@ -60,6 +60,10 @@ public class SingleEntry extends MasterSlaveEntry {
AtomicInteger counter = new AtomicInteger(2); AtomicInteger counter = new AtomicInteger(2);
@Override @Override
public void operationComplete(Future<Void> future) throws Exception { public void operationComplete(Future<Void> future) throws Exception {
if (!future.isSuccess()) {
res.setFailure(future.cause());
return;
}
if (counter.decrementAndGet() == 0) { if (counter.decrementAndGet() == 0) {
res.setSuccess(null); res.setSuccess(null);
} }

@ -54,31 +54,30 @@ public class ConnectionPool<T extends RedisConnection> {
public Future<Void> add(final ClientConnectionsEntry entry) { public Future<Void> add(final ClientConnectionsEntry entry) {
final Promise<Void> promise = connectionManager.newPromise(); final Promise<Void> promise = connectionManager.newPromise();
initConnections(entry, new Runnable() { promise.addListener(new FutureListener<Void>() {
@Override @Override
public void run() { public void operationComplete(Future<Void> future) throws Exception {
entries.add(entry); entries.add(entry);
promise.setSuccess(null);
} }
}, true); });
initConnections(entry, promise, true);
return promise; return promise;
} }
private void initConnections(final ClientConnectionsEntry entry, final Runnable runnable, boolean checkFreezed) { private void initConnections(final ClientConnectionsEntry entry, final Promise<Void> initPromise, boolean checkFreezed) {
int minimumIdleSize = getMinimumIdleSize(entry); int minimumIdleSize = getMinimumIdleSize(entry);
if (minimumIdleSize == 0 || (checkFreezed && entry.isFreezed())) { if (minimumIdleSize == 0 || (checkFreezed && entry.isFreezed())) {
runnable.run(); initPromise.setSuccess(null);
return; return;
} }
final AtomicInteger completedConnections = new AtomicInteger(minimumIdleSize); final AtomicInteger initializedConnections = new AtomicInteger(minimumIdleSize);
for (int i = 0; i < minimumIdleSize; i++) { for (int i = 0; i < minimumIdleSize; i++) {
if ((checkFreezed && entry.isFreezed()) || !tryAcquireConnection(entry)) { if ((checkFreezed && entry.isFreezed()) || !tryAcquireConnection(entry)) {
if (completedConnections.decrementAndGet() == 0) { Throwable cause = new RedisConnectionException("Can't init enough connections amount! from " + entry.getClient().getAddr());
runnable.run(); initPromise.tryFailure(cause);
} return;
continue;
} }
Promise<T> promise = connectionManager.newPromise(); Promise<T> promise = connectionManager.newPromise();
@ -91,9 +90,14 @@ public class ConnectionPool<T extends RedisConnection> {
releaseConnection(entry, conn); releaseConnection(entry, conn);
} }
releaseConnection(entry); releaseConnection(entry);
if (!future.isSuccess()) {
Throwable cause = new RedisConnectionException("Can't init enough connections amount! from " + entry.getClient().getAddr());
initPromise.tryFailure(cause);
return;
}
if (completedConnections.decrementAndGet() == 0) { if (initializedConnections.decrementAndGet() == 0) {
runnable.run(); initPromise.setSuccess(null);
} }
} }
}); });
@ -272,9 +276,11 @@ public class ConnectionPool<T extends RedisConnection> {
if (future.isSuccess() && "PONG".equals(future.getNow())) { if (future.isSuccess() && "PONG".equals(future.getNow())) {
entry.resetFailedAttempts(); entry.resetFailedAttempts();
initConnections(entry, new Runnable() { Promise<Void> promise = connectionManager.newPromise();
promise.addListener(new FutureListener<Void>() {
@Override @Override
public void run() { public void operationComplete(Future<Void> future)
throws Exception {
if (entry.getNodeType() == NodeType.SLAVE) { if (entry.getNodeType() == NodeType.SLAVE) {
masterSlaveEntry.slaveUp(entry.getClient().getAddr().getHostName(), entry.getClient().getAddr().getPort(), FreezeReason.RECONNECT); masterSlaveEntry.slaveUp(entry.getClient().getAddr().getHostName(), entry.getClient().getAddr().getPort(), FreezeReason.RECONNECT);
} else { } else {
@ -286,8 +292,8 @@ public class ConnectionPool<T extends RedisConnection> {
} }
} }
} }
}, false); });
initConnections(entry, promise, false);
} else { } else {
scheduleCheck(entry); scheduleCheck(entry);
} }

Loading…
Cancel
Save