Elffuss BraidHub

kikocis/java-driver public

Changed default in DCAwareRoundRobinPolicy so it throws an exception when explicitly specified DC is invalid (JAVA-451).
Changesetf9a61083aeb028d6c46193deea888df088bf8fdcc094c787824590e667522011
AuthorRobbie Strickland <rstrickland@weather.com> · 2014-09-16 09:13 -04:00
Committerolim7t <omichallat+github@gmail.com> · 2014-10-23 11:11 +02:00
Parentsacf22f7ca55b

Browse the files at this changeset

2 files changed

modified driver-core/CHANGELOG.rst +2 −0
@@ -22,6 +22,8 @@
2222 - [improvement] Document how to inject the driver metrics into another registry (JAVA-494)
2323 - [improvement] Add idle timeout to the connection pool (JAVA-419)
2424 - [bug] LatencyAwarePolicy does not shutdown executor on invocation of close (JAVA-516)
25+- [improvement] Throw an exception when DCAwareRoundRobinPolicy is built with
26+ an explicit but null or empty local datacenter (JAVA-451).
2527
2628
2729 2.0.6:
modified driver-core/src/main/java/com/datastax/driver/core/policies/DCAwareRoundRobinPolicy.java +20 −3
@@ -25,6 +25,8 @@
2525 import java.util.concurrent.atomic.AtomicInteger;
2626
2727 import com.google.common.annotations.VisibleForTesting;
28+import com.google.common.base.Joiner;
29+import com.google.common.base.Strings;
2830 import com.google.common.collect.AbstractIterator;
2931 import org.slf4j.Logger;
3032 import org.slf4j.LoggerFactory;
@@ -85,7 +87,7 @@
8587 * and as such will ignore all hosts in remote data-centers.
8688 */
8789 public DCAwareRoundRobinPolicy() {
88- this(null);
90+ this(null, 0, false, true);
8991 }
9092
9193 /**
@@ -103,7 +105,7 @@
103105 * data-center of the first node connected to.
104106 */
105107 public DCAwareRoundRobinPolicy(String localDc) {
106- this(localDc, 0);
108+ this(localDc, 0, false, false);
107109 }
108110
109111 /**
@@ -135,7 +137,7 @@
135137 * connections to them will be maintained).
136138 */
137139 public DCAwareRoundRobinPolicy(String localDc, int usedHostsPerRemoteDc) {
138- this(localDc, usedHostsPerRemoteDc, false);
140+ this(localDc, usedHostsPerRemoteDc, false, false);
139141 }
140142
141143 /**
@@ -168,6 +170,12 @@
168170 * having consitency {@code LOCAL_ONE} and {@code LOCAL_QUORUM}.
169171 */
170172 public DCAwareRoundRobinPolicy(String localDc, int usedHostsPerRemoteDc, boolean allowRemoteDCsForLocalConsistencyLevel) {
173+ this(localDc, usedHostsPerRemoteDc, allowRemoteDCsForLocalConsistencyLevel, false);
174+ }
175+
176+ private DCAwareRoundRobinPolicy(String localDc, int usedHostsPerRemoteDc, boolean allowRemoteDCsForLocalConsistencyLevel, boolean allowEmptyLocalDc) {
177+ if (!allowEmptyLocalDc && Strings.isNullOrEmpty(localDc))
178+ throw new IllegalArgumentException("Null or empty data center specified for DC-aware policy");
171179 this.localDc = localDc == null ? UNSET : localDc;
172180 this.usedHostsPerRemoteDc = usedHostsPerRemoteDc;
173181 this.dontHopForLocalCL = !allowRemoteDCsForLocalConsistencyLevel;
@@ -180,9 +188,13 @@
180188
181189 this.configuration = cluster.getConfiguration();
182190
191+ ArrayList<String> notInLocalDC = new ArrayList<String>();
192+
183193 for (Host host : hosts) {
184194 String dc = dc(host);
185195
196+ if (!dc.equals(localDc)) notInLocalDC.add(String.format("%s (%s)", host.toString(), host.getDatacenter()));
197+
186198 // If the localDC was in "auto-discover" mode and it's the first host for which we have a DC, use it.
187199 if (localDc == UNSET && dc != UNSET) {
188200 logger.info("Using data-center name '{}' for DCAwareRoundRobinPolicy (if this is incorrect, please provide the correct datacenter name with DCAwareRoundRobinPolicy constructor)", dc);
@@ -195,6 +207,11 @@
195207 else
196208 prev.addIfAbsent(host);
197209 }
210+
211+ if (notInLocalDC.size() > 0) {
212+ String nonLocalHosts = Joiner.on(",").join(notInLocalDC);
213+ logger.warn("Some contact points don't match specified local data center. Local DC = {}. Non-conforming contact points: {}", localDc, nonLocalHosts);
214+ }
198215 }
199216
200217 private String dc(Host host) {