Skip to content

Commit

Permalink
Merge pull request #21 from dkropachev/dk/use-dc-aware-policy-unless-…
Browse files Browse the repository at this point in the history
…rack-is-provided

Make it use DCAwareRoundRobinPolicy unless rack is provided
  • Loading branch information
CodeLieutenant authored Sep 6, 2024
2 parents d37cbc6 + f87206a commit 6bf5aff
Showing 1 changed file with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import com.datastax.driver.core.*;
import com.datastax.driver.core.policies.RackAwareRoundRobinPolicy;
import com.datastax.driver.core.policies.DCAwareRoundRobinPolicy;
import com.datastax.driver.core.policies.LoadBalancingPolicy;
import com.datastax.driver.core.policies.TokenAwarePolicy;
import com.datastax.driver.core.policies.TokenAwarePolicy.ReplicaOrdering;
Expand Down Expand Up @@ -94,21 +95,23 @@ public JavaDriverClient(StressSettings settings, List<String> hosts, int port, E

private LoadBalancingPolicy loadBalancingPolicy(StressSettings settings)
{
RackAwareRoundRobinPolicy.Builder policyBuilder = RackAwareRoundRobinPolicy.builder();

if (settings.node.datacenter != null)
policyBuilder.withLocalDc(settings.node.datacenter);
if (settings.node.rack != null)
policyBuilder.withLocalRack(settings.node.rack);

LoadBalancingPolicy ret = null;
if (settings.node.datacenter != null)
ret = policyBuilder.build();

if (settings.node.rack != null) {
RackAwareRoundRobinPolicy.Builder policyBuilder = RackAwareRoundRobinPolicy.builder();
if (settings.node.datacenter != null)
policyBuilder.withLocalDc(settings.node.datacenter);
policyBuilder = policyBuilder.withLocalRack(settings.node.rack);
ret = policyBuilder.build();
} else {
DCAwareRoundRobinPolicy.Builder policyBuilder = DCAwareRoundRobinPolicy.builder();
if (settings.node.datacenter != null)
policyBuilder.withLocalDc(settings.node.datacenter);
ret = policyBuilder.build();
}
if (settings.node.isWhiteList)
ret = new WhiteListPolicy(ret == null ? policyBuilder.build() : ret, settings.node.resolveAll(settings.port.nativePort));

return new TokenAwarePolicy(ret == null ? policyBuilder.build() : ret, ReplicaOrdering.NEUTRAL);
ret = new WhiteListPolicy(ret, settings.node.resolveAll(settings.port.nativePort));
return new TokenAwarePolicy(ret, ReplicaOrdering.NEUTRAL);
}

public PreparedStatement prepare(String query)
Expand Down

0 comments on commit 6bf5aff

Please sign in to comment.