refactoring

pull/6439/merge
mrniko 5 days ago
parent 0f44d9221b
commit 7d6d8fcab3

@ -115,8 +115,6 @@ public class MasterSlaveEntry {
}
private void removeSlaveEntry(ClientConnectionsEntry entry) {
slaveConnectionPool.removeEntry(entry);
slavePubSubConnectionPool.removeEntry(entry);
client2Entry.remove(entry.getClient());
if (config.getSubscriptionMode() == SubscriptionMode.SLAVE) {
@ -125,12 +123,7 @@ public class MasterSlaveEntry {
}
private void addSlaveEntry(ClientConnectionsEntry entry) {
if (client2Entry.get(entry.getClient()) != null) {
return;
}
slaveConnectionPool.addEntry(entry);
slavePubSubConnectionPool.addEntry(entry);
client2Entry.put(entry.getClient(), entry);
client2Entry.putIfAbsent(entry.getClient(), entry);
}
private boolean hasNoSlaves() {

@ -29,11 +29,10 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.InetSocketAddress;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentLinkedQueue;
/**
* Base connection pool class
@ -46,8 +45,6 @@ abstract class ConnectionPool<T extends RedisConnection> {
private final Logger log = LoggerFactory.getLogger(getClass());
final Queue<ClientConnectionsEntry> entries = new ConcurrentLinkedQueue<>();
final ConnectionManager connectionManager;
final MasterSlaveServersConfig config;
@ -60,17 +57,10 @@ abstract class ConnectionPool<T extends RedisConnection> {
this.connectionManager = connectionManager;
}
public final void addEntry(ClientConnectionsEntry entry) {
entries.add(entry);
}
public final void removeEntry(ClientConnectionsEntry entry) {
entries.remove(entry);
}
protected abstract ConnectionsHolder<T> getConnectionHolder(ClientConnectionsEntry entry, boolean trackChanges);
public CompletableFuture<T> get(RedisCommand<?> command, boolean trackChanges) {
Collection<ClientConnectionsEntry> entries = masterSlaveEntry.getAllEntries();
List<ClientConnectionsEntry> entriesCopy = new LinkedList<>(entries);
entriesCopy.removeIf(n -> n.isFreezed() || !isHealthy(n));
if (!entriesCopy.isEmpty()) {

Loading…
Cancel
Save