Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ class PooledClusterConnectionProvider<K, V>

private static final InternalLogger logger = InternalLoggerFactory.getInstance(PooledClusterConnectionProvider.class);

// Contains NodeId-identified and HostAndPort-identified connections.
private final Lock stateLock = new ReentrantLock();

private final boolean debugEnabled = logger.isDebugEnabled();
Expand Down Expand Up @@ -158,46 +157,38 @@ public CompletableFuture<StatefulRedisConnection<K, V>> getConnectionAsync(Conne

private CompletableFuture<StatefulRedisConnection<K, V>> getWriteConnection(int slot) {

CompletableFuture<StatefulRedisConnection<K, V>> writer;// avoid races when reconfiguring partitions.

stateLock.lock();
try {
writer = writers[slot];
} finally {
stateLock.unlock();
CompletableFuture<StatefulRedisConnection<K, V>> writer = writers[slot];
if (writer != null) {
return writer;
}

if (writer == null) {
RedisClusterNode master = partitions.getMasterBySlot(slot);
if (master == null) {
clusterEventListener.onUncoveredSlot(slot);
return Futures.failed(new PartitionSelectorException("Cannot determine a partition for slot " + slot + ".",
partitions.clone()));
}
RedisClusterNode master = partitions.getMasterBySlot(slot);
if (master == null) {
clusterEventListener.onUncoveredSlot(slot);
return Futures.failed(
new PartitionSelectorException("Cannot determine a partition for slot " + slot + ".", partitions.clone()));
}

// Use always host and port for slot-oriented operations. We don't want to get reconnected on a different
// host because the nodeId can be handled by a different host.
RedisURI uri = master.getUri();
ConnectionKey key = new ConnectionKey(ConnectionIntent.WRITE, uri.getHost(), uri.getPort());
// Use always host and port for slot-oriented operations. We don't want to get reconnected on a different
// host because the nodeId can be handled by a different host.
RedisURI uri = master.getUri();
ConnectionKey key = new ConnectionKey(ConnectionIntent.WRITE, uri.getHost(), uri.getPort());

ConnectionFuture<StatefulRedisConnection<K, V>> future = getConnectionAsync(key);
ConnectionFuture<StatefulRedisConnection<K, V>> future = getConnectionAsync(key);

return future.thenApply(connection -> {
return future.thenApply(connection -> {

stateLock.lock();
try {
if (writers[slot] == null) {
writers[slot] = CompletableFuture.completedFuture(connection);
}
} finally {
stateLock.unlock();
stateLock.lock();
try {
if (writers[slot] == null) {
writers[slot] = CompletableFuture.completedFuture(connection);
}
} finally {
stateLock.unlock();
}

return connection;
}).toCompletableFuture();
}

return writer;
return connection;
}).toCompletableFuture();
}

private CompletableFuture<StatefulRedisConnection<K, V>> getReadConnection(int slot) {
Expand Down Expand Up @@ -654,7 +645,6 @@ public ReadFrom getReadFrom() {
}

/**
*
* @return number of connections.
*/
long getConnectionCount() {
Expand Down