Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it use DCAwareRoundRobinPolicy unless rack is provided #21

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 @@ -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