diff --git a/src/main/java/org/redisson/connection/MasterSlaveEntry.java b/src/main/java/org/redisson/connection/MasterSlaveEntry.java index a5a0acc31..816a7ff32 100644 --- a/src/main/java/org/redisson/connection/MasterSlaveEntry.java +++ b/src/main/java/org/redisson/connection/MasterSlaveEntry.java @@ -33,7 +33,7 @@ import org.redisson.connection.ClientConnectionsEntry.FreezeReason; import org.redisson.connection.ClientConnectionsEntry.NodeType; import org.redisson.connection.balancer.LoadBalancerManager; import org.redisson.connection.balancer.LoadBalancerManagerImpl; -import org.redisson.misc.MasterConnectionPool; +import org.redisson.connection.pool.MasterConnectionPool; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/org/redisson/connection/SingleEntry.java b/src/main/java/org/redisson/connection/SingleEntry.java index e77b5236f..b35de20db 100644 --- a/src/main/java/org/redisson/connection/SingleEntry.java +++ b/src/main/java/org/redisson/connection/SingleEntry.java @@ -25,8 +25,7 @@ import org.redisson.client.RedisConnection; import org.redisson.client.RedisPubSubConnection; import org.redisson.cluster.ClusterSlotRange; import org.redisson.connection.ClientConnectionsEntry.NodeType; -import org.redisson.misc.ConnectionPool; -import org.redisson.misc.PubSubConnectionPoll; +import org.redisson.connection.pool.PubSubConnectionPool; import io.netty.util.concurrent.Future; import io.netty.util.concurrent.FutureListener; @@ -34,11 +33,11 @@ import io.netty.util.concurrent.Promise; public class SingleEntry extends MasterSlaveEntry { - final ConnectionPool pubSubConnectionHolder; + final PubSubConnectionPool pubSubConnectionHolder; public SingleEntry(Set slotRanges, ConnectionManager connectionManager, MasterSlaveServersConfig config) { super(slotRanges, connectionManager, config); - pubSubConnectionHolder = new PubSubConnectionPoll(config, connectionManager, this) { + pubSubConnectionHolder = new PubSubConnectionPool(config, connectionManager, this) { protected ClientConnectionsEntry getEntry() { return entries.get(0); } diff --git a/src/main/java/org/redisson/connection/balancer/LoadBalancerManagerImpl.java b/src/main/java/org/redisson/connection/balancer/LoadBalancerManagerImpl.java index c454ed888..45f55ecc0 100644 --- a/src/main/java/org/redisson/connection/balancer/LoadBalancerManagerImpl.java +++ b/src/main/java/org/redisson/connection/balancer/LoadBalancerManagerImpl.java @@ -27,11 +27,11 @@ import org.redisson.client.RedisConnection; import org.redisson.client.RedisConnectionException; import org.redisson.client.RedisPubSubConnection; import org.redisson.connection.ClientConnectionsEntry; +import org.redisson.connection.ClientConnectionsEntry.FreezeReason; import org.redisson.connection.ConnectionManager; import org.redisson.connection.MasterSlaveEntry; -import org.redisson.connection.ClientConnectionsEntry.FreezeReason; -import org.redisson.misc.ConnectionPool; -import org.redisson.misc.PubSubConnectionPoll; +import org.redisson.connection.pool.PubSubConnectionPool; +import org.redisson.connection.pool.SlaveConnectionPool; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -45,13 +45,13 @@ public class LoadBalancerManagerImpl implements LoadBalancerManager { private final ConnectionManager connectionManager; private final Map addr2Entry = PlatformDependent.newConcurrentHashMap(); - private final PubSubConnectionPoll pubSubEntries; - private final ConnectionPool entries; + private final PubSubConnectionPool pubSubEntries; + private final SlaveConnectionPool entries; public LoadBalancerManagerImpl(MasterSlaveServersConfig config, ConnectionManager connectionManager, MasterSlaveEntry entry) { this.connectionManager = connectionManager; - entries = new ConnectionPool(config, connectionManager, entry); - pubSubEntries = new PubSubConnectionPoll(config, connectionManager, entry); + entries = new SlaveConnectionPool(config, connectionManager, entry); + pubSubEntries = new PubSubConnectionPool(config, connectionManager, entry); } public Future add(final ClientConnectionsEntry entry) { diff --git a/src/main/java/org/redisson/misc/ConnectionPool.java b/src/main/java/org/redisson/connection/pool/ConnectionPool.java similarity index 88% rename from src/main/java/org/redisson/misc/ConnectionPool.java rename to src/main/java/org/redisson/connection/pool/ConnectionPool.java index 6b27d37e3..7c9ba47b9 100644 --- a/src/main/java/org/redisson/misc/ConnectionPool.java +++ b/src/main/java/org/redisson/connection/pool/ConnectionPool.java @@ -13,8 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.redisson.misc; +package org.redisson.connection.pool; +import java.net.InetSocketAddress; +import java.util.LinkedList; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.TimeUnit; @@ -29,6 +31,8 @@ import org.redisson.connection.ClientConnectionsEntry.FreezeReason; import org.redisson.connection.ClientConnectionsEntry.NodeType; import org.redisson.connection.ConnectionManager; import org.redisson.connection.MasterSlaveEntry; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import io.netty.util.Timeout; import io.netty.util.TimerTask; @@ -36,7 +40,9 @@ import io.netty.util.concurrent.Future; import io.netty.util.concurrent.FutureListener; import io.netty.util.concurrent.Promise; -public class ConnectionPool { +abstract class ConnectionPool { + + private final Logger log = LoggerFactory.getLogger(getClass()); protected final List entries = new CopyOnWriteArrayList(); @@ -107,9 +113,7 @@ public class ConnectionPool { } } - protected int getMinimumIdleSize(ClientConnectionsEntry entry) { - return config.getSlaveConnectionMinimumIdleSize(); - } + protected abstract int getMinimumIdleSize(ClientConnectionsEntry entry); protected ClientConnectionsEntry getEntry() { return config.getLoadBalancer().getEntry(entries); @@ -123,8 +127,26 @@ public class ConnectionPool { } } - RedisConnectionException exception = new RedisConnectionException( - "Can't aquire connection from pool! " + entries); + List zeroConnectionsAmount = new LinkedList(); + List freezed = new LinkedList(); + for (ClientConnectionsEntry entry : entries) { + if (entry.isFreezed()) { + freezed.add(entry.getClient().getAddr()); + } else { + zeroConnectionsAmount.add(entry.getClient().getAddr()); + } + } + + StringBuilder errorMsg = new StringBuilder("Connection pool exhausted!"); + if (!freezed.isEmpty()) { + errorMsg.append(" disconnected hosts: " + freezed); + } + if (!zeroConnectionsAmount.isEmpty()) { + errorMsg.append(" hosts with (available connections amount) = 0 : " + zeroConnectionsAmount); + } + errorMsg.append(" Try to increase connection pool size."); + + RedisConnectionException exception = new RedisConnectionException(errorMsg.toString()); return connectionManager.newFailedFuture(exception); } @@ -238,9 +260,11 @@ public class ConnectionPool { if (entry.getNodeType() == NodeType.SLAVE) { connectionManager.slaveDown(masterSlaveEntry, entry.getClient().getAddr().getHostName(), entry.getClient().getAddr().getPort(), FreezeReason.RECONNECT); + log.warn("slave {} disconnected due to failedAttempts={} limit reached", entry.getClient().getAddr(), config.getFailedAttempts()); scheduleCheck(entry); } else { if (entry.freezeMaster(FreezeReason.RECONNECT)) { + log.warn("host {} disconnected due to failedAttempts={} limit reached", entry.getClient().getAddr(), config.getFailedAttempts()); scheduleCheck(entry); } } @@ -297,11 +321,13 @@ public class ConnectionPool { throws Exception { if (entry.getNodeType() == NodeType.SLAVE) { masterSlaveEntry.slaveUp(entry.getClient().getAddr().getHostName(), entry.getClient().getAddr().getPort(), FreezeReason.RECONNECT); + log.info("slave {} successfully reconnected", entry.getClient().getAddr()); } else { synchronized (entry) { if (entry.getFreezeReason() == FreezeReason.RECONNECT) { entry.setFreezed(false); entry.setFreezeReason(null); + log.info("host {} successfully reconnected", entry.getClient().getAddr()); } } } diff --git a/src/main/java/org/redisson/misc/MasterConnectionPool.java b/src/main/java/org/redisson/connection/pool/MasterConnectionPool.java similarity index 97% rename from src/main/java/org/redisson/misc/MasterConnectionPool.java rename to src/main/java/org/redisson/connection/pool/MasterConnectionPool.java index 19b959ed9..d61d6411c 100644 --- a/src/main/java/org/redisson/misc/MasterConnectionPool.java +++ b/src/main/java/org/redisson/connection/pool/MasterConnectionPool.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.redisson.misc; +package org.redisson.connection.pool; import org.redisson.MasterSlaveServersConfig; import org.redisson.client.RedisConnection; @@ -21,8 +21,8 @@ import org.redisson.connection.ConnectionManager; import org.redisson.connection.MasterSlaveEntry; import org.redisson.connection.ClientConnectionsEntry; -public class MasterConnectionPool extends ConnectionPool { +public class MasterConnectionPool extends ConnectionPool { public MasterConnectionPool(MasterSlaveServersConfig config, ConnectionManager connectionManager, MasterSlaveEntry masterSlaveEntry) { super(config, connectionManager, masterSlaveEntry); diff --git a/src/main/java/org/redisson/misc/PubSubConnectionPoll.java b/src/main/java/org/redisson/connection/pool/PubSubConnectionPool.java similarity index 92% rename from src/main/java/org/redisson/misc/PubSubConnectionPoll.java rename to src/main/java/org/redisson/connection/pool/PubSubConnectionPool.java index 7228d4daa..4914c8322 100644 --- a/src/main/java/org/redisson/misc/PubSubConnectionPoll.java +++ b/src/main/java/org/redisson/connection/pool/PubSubConnectionPool.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.redisson.misc; +package org.redisson.connection.pool; import org.redisson.MasterSlaveServersConfig; import org.redisson.client.RedisPubSubConnection; @@ -23,9 +23,9 @@ import org.redisson.connection.ClientConnectionsEntry; import io.netty.util.concurrent.Future; -public class PubSubConnectionPoll extends ConnectionPool { +public class PubSubConnectionPool extends ConnectionPool { - public PubSubConnectionPoll(MasterSlaveServersConfig config, ConnectionManager connectionManager, MasterSlaveEntry masterSlaveEntry) { + public PubSubConnectionPool(MasterSlaveServersConfig config, ConnectionManager connectionManager, MasterSlaveEntry masterSlaveEntry) { super(config, connectionManager, masterSlaveEntry); }