failedAttempts setting should be applied to Slave nodes only

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

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