failedAttempts setting should be applied to Slave nodes only

pull/1336/head
Nikita 7 years ago
parent 550d9700ce
commit 35cdfe5018

@ -238,8 +238,11 @@ abstract class ConnectionPool<T extends RedisConnection> {
}
protected boolean tryAcquireConnection(ClientConnectionsEntry entry) {
if (entry.getNodeType() == NodeType.SLAVE) {
return entry.getFailedAttempts() < config.getFailedAttempts();
}
return true;
}
protected T poll(ClientConnectionsEntry entry) {
return (T) entry.pollConnection();
@ -256,11 +259,6 @@ abstract class ConnectionPool<T extends RedisConnection> {
}
T conn = poll(entry);
if (conn != null) {
if (!conn.isActive()) {
promiseFailure(entry, promise, conn);
return;
}
connectedSuccessful(entry, promise, conn);
return;
}
@ -290,7 +288,9 @@ abstract class ConnectionPool<T extends RedisConnection> {
}
private void connectedSuccessful(ClientConnectionsEntry entry, RPromise<T> promise, T conn) {
if (entry.getNodeType() == NodeType.SLAVE) {
entry.resetFailedAttempts();
}
if (!promise.trySuccess(conn)) {
releaseConnection(entry, conn);
releaseConnection(entry);
@ -298,7 +298,8 @@ abstract class ConnectionPool<T extends RedisConnection> {
}
private void promiseFailure(ClientConnectionsEntry entry, RPromise<T> promise, Throwable cause) {
if (entry.incFailedAttempts() == config.getFailedAttempts()) {
if (entry.getNodeType() == NodeType.SLAVE
&& entry.incFailedAttempts() == config.getFailedAttempts()) {
checkForReconnect(entry, cause);
}
@ -308,6 +309,7 @@ abstract class ConnectionPool<T extends RedisConnection> {
}
private void promiseFailure(ClientConnectionsEntry entry, RPromise<T> promise, T conn) {
if (entry.getNodeType() == NodeType.SLAVE) {
int attempts = entry.incFailedAttempts();
if (attempts == config.getFailedAttempts()) {
conn.closeAsync();
@ -317,6 +319,9 @@ abstract class ConnectionPool<T extends RedisConnection> {
} else {
conn.closeAsync();
}
} else {
releaseConnection(entry, conn);
}
releaseConnection(entry);
@ -325,15 +330,9 @@ abstract class ConnectionPool<T extends RedisConnection> {
}
private void checkForReconnect(ClientConnectionsEntry entry, Throwable cause) {
if (entry.getNodeType() == NodeType.SLAVE) {
masterSlaveEntry.slaveDown(entry, FreezeReason.RECONNECT);
if (masterSlaveEntry.slaveDown(entry, FreezeReason.RECONNECT)) {
log.error("slave " + entry.getClient().getAddr() + " disconnected due to failedAttempts=" + config.getFailedAttempts() + " limit reached", cause);
scheduleCheck(entry);
} else {
if (entry.freezeMaster(FreezeReason.RECONNECT)) {
log.error("host " + entry.getClient().getAddr() + " disconnected due to failedAttempts=" + config.getFailedAttempts() + " limit reached", cause);
scheduleCheck(entry);
}
}
}

Loading…
Cancel
Save