kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | f9a61083aeb028d6c46193deea888df088bf8fdcc094c787824590e667522011 |
|---|---|
| Author | Robbie Strickland <rstrickland@weather.com> · 2014-09-16 09:13 -04:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2014-10-23 11:11 +02:00 |
| Parents | acf22f7ca55b |
2 files changed
modified driver-core/CHANGELOG.rst +2 −0
| @@ -22,6 +22,8 @@ | ||
| 22 | 22 | - [improvement] Document how to inject the driver metrics into another registry (JAVA-494) |
| 23 | 23 | - [improvement] Add idle timeout to the connection pool (JAVA-419) |
| 24 | 24 | - [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). | |
| 25 | 27 | |
| 26 | 28 | |
| 27 | 29 | 2.0.6: |
modified driver-core/src/main/java/com/datastax/driver/core/policies/DCAwareRoundRobinPolicy.java +20 −3
| @@ -25,6 +25,8 @@ | ||
| 25 | 25 | import java.util.concurrent.atomic.AtomicInteger; |
| 26 | 26 | |
| 27 | 27 | import com.google.common.annotations.VisibleForTesting; |
| 28 | +import com.google.common.base.Joiner; | |
| 29 | +import com.google.common.base.Strings; | |
| 28 | 30 | import com.google.common.collect.AbstractIterator; |
| 29 | 31 | import org.slf4j.Logger; |
| 30 | 32 | import org.slf4j.LoggerFactory; |
| @@ -85,7 +87,7 @@ | ||
| 85 | 87 | * and as such will ignore all hosts in remote data-centers. |
| 86 | 88 | */ |
| 87 | 89 | public DCAwareRoundRobinPolicy() { |
| 88 | - this(null); | |
| 90 | + this(null, 0, false, true); | |
| 89 | 91 | } |
| 90 | 92 | |
| 91 | 93 | /** |
| @@ -103,7 +105,7 @@ | ||
| 103 | 105 | * data-center of the first node connected to. |
| 104 | 106 | */ |
| 105 | 107 | public DCAwareRoundRobinPolicy(String localDc) { |
| 106 | - this(localDc, 0); | |
| 108 | + this(localDc, 0, false, false); | |
| 107 | 109 | } |
| 108 | 110 | |
| 109 | 111 | /** |
| @@ -135,7 +137,7 @@ | ||
| 135 | 137 | * connections to them will be maintained). |
| 136 | 138 | */ |
| 137 | 139 | public DCAwareRoundRobinPolicy(String localDc, int usedHostsPerRemoteDc) { |
| 138 | - this(localDc, usedHostsPerRemoteDc, false); | |
| 140 | + this(localDc, usedHostsPerRemoteDc, false, false); | |
| 139 | 141 | } |
| 140 | 142 | |
| 141 | 143 | /** |
| @@ -168,6 +170,12 @@ | ||
| 168 | 170 | * having consitency {@code LOCAL_ONE} and {@code LOCAL_QUORUM}. |
| 169 | 171 | */ |
| 170 | 172 | 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"); | |
| 171 | 179 | this.localDc = localDc == null ? UNSET : localDc; |
| 172 | 180 | this.usedHostsPerRemoteDc = usedHostsPerRemoteDc; |
| 173 | 181 | this.dontHopForLocalCL = !allowRemoteDCsForLocalConsistencyLevel; |
| @@ -180,9 +188,13 @@ | ||
| 180 | 188 | |
| 181 | 189 | this.configuration = cluster.getConfiguration(); |
| 182 | 190 | |
| 191 | + ArrayList<String> notInLocalDC = new ArrayList<String>(); | |
| 192 | + | |
| 183 | 193 | for (Host host : hosts) { |
| 184 | 194 | String dc = dc(host); |
| 185 | 195 | |
| 196 | + if (!dc.equals(localDc)) notInLocalDC.add(String.format("%s (%s)", host.toString(), host.getDatacenter())); | |
| 197 | + | |
| 186 | 198 | // If the localDC was in "auto-discover" mode and it's the first host for which we have a DC, use it. |
| 187 | 199 | if (localDc == UNSET && dc != UNSET) { |
| 188 | 200 | 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 @@ | ||
| 195 | 207 | else |
| 196 | 208 | prev.addIfAbsent(host); |
| 197 | 209 | } |
| 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 | + } | |
| 198 | 215 | } |
| 199 | 216 | |
| 200 | 217 | private String dc(Host host) { |