Skip to content

Commit 33aea76

Browse files
committed
Make addMissingChannels use advanced shard awareness
It will now specify target shard when connecting.
1 parent 860f963 commit 33aea76

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

core/src/main/java/com/datastax/oss/driver/internal/core/pool/ChannelPool.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -489,9 +489,21 @@ private CompletionStage<Boolean> addMissingChannels() {
489489
channels.length * wantedCount - Arrays.stream(channels).mapToInt(ChannelSet::size).sum();
490490
LOG.debug("[{}] Trying to create {} missing channels", logPrefix, missing);
491491
DriverChannelOptions options = buildDriverOptions();
492-
for (int i = 0; i < missing; i++) {
493-
CompletionStage<DriverChannel> channelFuture = channelFactory.connect(node, options);
494-
pendingChannels.add(channelFuture);
492+
for (int shard = 0; shard < channels.length; shard++) {
493+
LOG.trace(
494+
"[{}] Missing {} channels for shard {}",
495+
logPrefix,
496+
wantedCount - channels[shard].size(),
497+
shard);
498+
for (int p = channels[shard].size(); p < wantedCount; p++) {
499+
CompletionStage<DriverChannel> channelFuture;
500+
if (node.getShardingInfo() != null) {
501+
channelFuture = channelFactory.connect(node, shard, options);
502+
} else {
503+
channelFuture = channelFactory.connect(node, options);
504+
}
505+
pendingChannels.add(channelFuture);
506+
}
495507
}
496508
return CompletableFutures.allDone(pendingChannels)
497509
.thenApplyAsync(this::onAllConnected, adminExecutor);

0 commit comments

Comments
 (0)