Elffuss BraidHub

kikocis/java-driver public

Merge branch '2.0' into 2.1
Changesetafd83c38482e87541ef658350d7702e20865b2567aef2f2a908c5e0b14dc799b
Authorolim7t <omichallat+github@gmail.com> · 2015-06-26 22:52 +02:00
Committerolim7t <omichallat+github@gmail.com> · 2015-06-26 22:55 +02:00
Parentsf7b60ca29eb5, c7bbffe1167f

Browse the files at this changeset

13 files changed

modified changelog/README.md +31 −4
@@ -10,16 +10,29 @@
1010 - [improvement] Create values() function for Insert builder using List (JAVA-225)
1111 - [improvement] HashMap throws an OOM Exception when logging level is set to TRACE (JAVA-713)
1212 - [bug] Support bind marker in QueryBuilder DELETE's list index (JAVA-679)
13-- [bug] DowngradingConsistencyRetryPolicy ignores write timeouts (JAVA-737)
14-- [bug] Forbid bind marker in QueryBuilder add/append/prepend (JAVA-736)
1513 - [improvement] Expose KEYS and FULL indexing options in IndexMetadata (JAVA-732)
16-- [bug] Prevent QueryBuilder.quote() from applying duplicate double quotes (JAVA-712)
17-- [bug] Prevent QueryBuilder from trying to serialize raw string (JAVA-688)
1814 - [improvement] Allow @Enumerated in Accessor method parameters (JAVA-589)
1915 - [improvement] Allow access to table metadata from Mapper (JAVA-554)
2016 - [improvement] Provide a way to map computed fields (JAVA-661)
2117 - [improvement] Ignore missing columns in mapper (JAVA-824)
2218
19+Merged from 2.0 branch:
20+
21+- [bug] DowngradingConsistencyRetryPolicy ignores write timeouts (JAVA-737)
22+- [bug] Forbid bind marker in QueryBuilder add/append/prepend (JAVA-736)
23+- [bug] Prevent QueryBuilder.quote() from applying duplicate double quotes (JAVA-712)
24+- [bug] Prevent QueryBuilder from trying to serialize raw string (JAVA-688)
25+- [bug] Support bind marker in QueryBuilder DELETE's list index (JAVA-679)
26+- [improvement] Improve QueryBuilder API for SELECT DISTINCT (JAVA-475)
27+- [improvement] Create values() function for Insert builder using List (JAVA-225)
28+- [improvement] Warn when ReplicationStrategy encounters invalid
29+ replication factors (JAVA-702)
30+- [improvement] Add PoolingOptions method to set both core and max
31+ connections (JAVA-662).
32+- [improvement] Do not include epoll JAR in binary distribution (JAVA-766)
33+- [improvement] Optimize internal copies of Request objects (JAVA-726)
34+- [bug] Preserve tracing across retries (JAVA-815)
35+
2336
2437 ### 2.1.6
2538
@@ -239,6 +252,20 @@
239252 - [improvement] Suppress unnecessary warning at shutdown (JAVA-710)
240253 - [improvement] Allow DNS name with multiple A-records as contact point (#340)
241254 - [bug] Allow tracing across multiple result pages (JAVA-794)
255+- [bug] DowngradingConsistencyRetryPolicy ignores write timeouts (JAVA-737)
256+- [bug] Forbid bind marker in QueryBuilder add/append/prepend (JAVA-736)
257+- [bug] Prevent QueryBuilder.quote() from applying duplicate double quotes (JAVA-712)
258+- [bug] Prevent QueryBuilder from trying to serialize raw string (JAVA-688)
259+- [bug] Support bind marker in QueryBuilder DELETE's list index (JAVA-679)
260+- [improvement] Improve QueryBuilder API for SELECT DISTINCT (JAVA-475)
261+- [improvement] Create values() function for Insert builder using List (JAVA-225)
262+- [improvement] Warn when ReplicationStrategy encounters invalid
263+ replication factors (JAVA-702)
264+- [improvement] Add PoolingOptions method to set both core and max
265+ connections (JAVA-662).
266+- [improvement] Do not include epoll JAR in binary distribution (JAVA-766)
267+- [improvement] Optimize internal copies of Request objects (JAVA-726)
268+- [bug] Preserve tracing across retries (JAVA-815)
242269
243270 Merged from 2.0.10_fixes branch:
244271
modified driver-core/src/main/java/com/datastax/driver/core/Message.java +13 −4
@@ -82,14 +82,15 @@
8282 }
8383
8484 public final Type type;
85- protected boolean tracingRequested;
85+ private final boolean tracingRequested;
8686
8787 protected Request(Type type) {
88- this.type = type;
88+ this(type, false);
8989 }
9090
91- public void setTracingRequested() {
92- this.tracingRequested = true;
91+ protected Request(Type type, boolean tracingRequested) {
92+ this.type = type;
93+ this.tracingRequested = tracingRequested;
9394 }
9495
9596 public boolean isTracingRequested() {
@@ -130,6 +131,14 @@
130131 default: return null;
131132 }
132133 }
134+
135+ Request copy() {
136+ throw new UnsupportedOperationException();
137+ }
138+
139+ Request copy(ConsistencyLevel newConsistencyLevel) {
140+ throw new UnsupportedOperationException();
141+ }
133142 }
134143
135144 public static abstract class Response extends Message {
modified driver-core/src/main/java/com/datastax/driver/core/PoolingOptions.java +24 −0
@@ -256,6 +256,30 @@
256256 return this;
257257 }
258258
259+ /**
260+ * Sets the core and maximum number of connections per host in one call.
261+ * <p>
262+ * This is a convenience method that is equivalent to calling {@link #setCoreConnectionsPerHost(HostDistance, int)}
263+ * and {@link #setMaxConnectionsPerHost(HostDistance, int)}.
264+ *
265+ * @param distance the {@code HostDistance} for which to set these threshold.
266+ * @param core the core number of connections.
267+ * @param max the max number of connections.
268+ * @return this {@code PoolingOptions}.
269+ *
270+ * @throws IllegalArgumentException if {@code distance == HostDistance.IGNORED},
271+ * or if {@code core} > {@code max}.
272+ */
273+ public synchronized PoolingOptions setConnectionsPerHost(HostDistance distance, int core, int max) {
274+ if (distance == HostDistance.IGNORED)
275+ throw new IllegalArgumentException("Cannot set connections per host for " + distance + " hosts");
276+
277+ checkConnectionsPerHostOrder(core, max, distance);
278+ coreConnections[distance.ordinal()] = core;
279+ maxConnections[distance.ordinal()] = max;
280+ return this;
281+ }
282+
259283 /**
260284 * Returns the timeout before an idle connection is removed.
261285 *
modified driver-core/src/main/java/com/datastax/driver/core/ReplicationStategy.java +26 −0
@@ -18,6 +18,9 @@
1818 import java.util.*;
1919
2020 import com.google.common.collect.ImmutableSet;
21+import com.google.common.collect.Sets;
22+import org.slf4j.Logger;
23+import org.slf4j.LoggerFactory;
2124
2225 /*
2326 * Computes the token->list<replica> association, given the token ring and token->primary token map.
@@ -87,6 +90,7 @@
8790 }
8891
8992 static class NetworkTopologyStrategy extends ReplicationStrategy {
93+ private static final Logger logger = LoggerFactory.getLogger(NetworkTopologyStrategy.class);
9094
9195 private final Map<String, Integer> replicationFactors;
9296
@@ -99,6 +103,9 @@
99103 // This is essentially a copy of org.apache.cassandra.locator.NetworkTopologyStrategy
100104 Map<String, Set<String>> racks = getRacksInDcs(tokenToPrimary.values());
101105 Map<Token, Set<Host>> replicaMap = new HashMap<Token, Set<Host>>(tokenToPrimary.size());
106+
107+ Set<String> warnedDcs = Sets.newHashSetWithExpectedSize(replicationFactors.size());
108+
102109 for (int i = 0; i < ring.size(); i++) {
103110 Map<String, Set<Host>> allDcReplicas = new HashMap<String, Set<Host>>();
104111 Map<String, Set<String>> seenRacks = new HashMap<String, Set<String>>();
@@ -147,6 +154,25 @@
147154 }
148155 }
149156 }
157+
158+ // If we haven't found enough replicas after a whole trip around the ring, this probably
159+ // means that the replication factors are broken.
160+ // Warn the user because that leads to quadratic performance of this method (JAVA-702).
161+ for (Map.Entry<String, Set<Host>> entry : allDcReplicas.entrySet()) {
162+ String dcName = entry.getKey();
163+ int expectedFactor = replicationFactors.get(dcName);
164+ int achievedFactor = entry.getValue().size();
165+ if (achievedFactor < expectedFactor && !warnedDcs.contains(dcName)) {
166+ logger.warn("Error while computing token map for datacenter {}: "
167+ + "could not achieve replication factor {} (found {} replicas only), "
168+ + "check your keyspace replication settings. "
169+ + "Note that this can affect the performance of the driver.",
170+ dcName, expectedFactor, achievedFactor);
171+ // only warn once per DC
172+ warnedDcs.add(dcName);
173+ }
174+ }
175+
150176 replicaMap.put(ring.get(i), ImmutableSet.copyOf(replicas));
151177 }
152178 return replicaMap;
modified driver-core/src/main/java/com/datastax/driver/core/RequestHandler.java +2 −2
@@ -111,7 +111,7 @@
111111 // Clone the request after the first execution, since we set the streamId on it later and we
112112 // don't want to share that across executions.
113113 if (position > 1)
114- request = manager.makeRequestMessage(statement, request.pagingState()) ;
114+ request = request.copy();
115115
116116 SpeculativeExecution execution = new SpeculativeExecution(request, position);
117117 runningExecutions.add(execution);
@@ -405,7 +405,7 @@
405405 @Override
406406 public Message.Request request() {
407407 if (retryConsistencyLevel != null && retryConsistencyLevel != request.consistency())
408- return manager.makeRequestMessage(statement, retryConsistencyLevel, request.serialConsistency(), request.pagingState(), request.defaultTimestamp());
408+ return request.copy(retryConsistencyLevel);
409409 else
410410 return request;
411411 }
modified driver-core/src/main/java/com/datastax/driver/core/Requests.java +44 −7
@@ -125,15 +125,25 @@
125125 public final QueryProtocolOptions options;
126126
127127 public Query(String query) {
128- this(query, QueryProtocolOptions.DEFAULT);
128+ this(query, QueryProtocolOptions.DEFAULT, false);
129129 }
130130
131- public Query(String query, QueryProtocolOptions options) {
132- super(Type.QUERY);
131+ public Query(String query, QueryProtocolOptions options, boolean tracingRequested) {
132+ super(Type.QUERY, tracingRequested);
133133 this.query = query;
134134 this.options = options;
135135 }
136136
137+ @Override
138+ Request copy() {
139+ return new Query(this.query, options, isTracingRequested());
140+ }
141+
142+ @Override
143+ Request copy(ConsistencyLevel newConsistencyLevel) {
144+ return new Query(this.query, options.copy(newConsistencyLevel), isTracingRequested());
145+ }
146+
137147 @Override
138148 public String toString() {
139149 return "QUERY " + query + '(' + options + ')';
@@ -157,12 +167,22 @@
157167 public final MD5Digest statementId;
158168 public final QueryProtocolOptions options;
159169
160- public Execute(MD5Digest statementId, QueryProtocolOptions options) {
161- super(Message.Request.Type.EXECUTE);
170+ public Execute(MD5Digest statementId, QueryProtocolOptions options, boolean tracingRequested) {
171+ super(Message.Request.Type.EXECUTE, tracingRequested);
162172 this.statementId = statementId;
163173 this.options = options;
164174 }
165175
176+ @Override
177+ Request copy() {
178+ return new Execute(statementId, options, isTracingRequested());
179+ }
180+
181+ @Override
182+ Request copy(ConsistencyLevel newConsistencyLevel) {
183+ return new Execute(statementId, options.copy(newConsistencyLevel), isTracingRequested());
184+ }
185+
166186 @Override
167187 public String toString() {
168188 return "EXECUTE " + statementId + " (" + options + ')';
@@ -248,6 +268,10 @@
248268 flags.add(QueryFlag.DEFAULT_TIMESTAMP);
249269 }
250270
271+ public QueryProtocolOptions copy(ConsistencyLevel newConsistencyLevel) {
272+ return new QueryProtocolOptions(newConsistencyLevel, values, skipMetadata, pageSize, pagingState, serialConsistency, defaultTimestamp);
273+ }
274+
251275 public void encode(ByteBuf dest, ProtocolVersion version) {
252276 switch (version) {
253277 case V1:
@@ -360,14 +384,23 @@
360384 public final List<List<ByteBuffer>> values;
361385 public final BatchProtocolOptions options;
362386
363- public Batch(BatchStatement.Type type, List<Object> queryOrIdList, List<List<ByteBuffer>> values, BatchProtocolOptions options) {
364- super(Message.Request.Type.BATCH);
387+ public Batch(BatchStatement.Type type, List<Object> queryOrIdList, List<List<ByteBuffer>> values, BatchProtocolOptions options, boolean tracingRequested) {
388+ super(Message.Request.Type.BATCH, tracingRequested);
365389 this.type = type;
366390 this.queryOrIdList = queryOrIdList;
367391 this.values = values;
368392 this.options = options;
369393 }
370394
395+ @Override
396+ Request copy() {
397+ return new Batch(type, queryOrIdList, values, options, isTracingRequested());
398+ }
399+
400+ @Override
401+ Request copy(ConsistencyLevel newConsistencyLevel) {
402+ return new Batch(type, queryOrIdList, values, options.copy(newConsistencyLevel), isTracingRequested());
403+ }
371404 @Override
372405 public String toString() {
373406 StringBuilder sb = new StringBuilder();
@@ -398,6 +431,10 @@
398431 flags.add(QueryFlag.DEFAULT_TIMESTAMP);
399432 }
400433
434+ BatchProtocolOptions copy(ConsistencyLevel newConsistencyLevel) {
435+ return new BatchProtocolOptions(newConsistencyLevel, serialConsistency, defaultTimestamp);
436+ }
437+
401438 public void encode(ByteBuf dest, ProtocolVersion version) {
402439 switch (version) {
403440 case V2:
modified driver-core/src/main/java/com/datastax/driver/core/SessionManager.java +18 −27
@@ -471,26 +471,17 @@
471471 defaultTimestamp = cluster.getConfiguration().getPolicies().getTimestampGenerator().next();
472472 }
473473
474- Message.Request request = makeRequestMessage(statement, consistency, serialConsistency, pagingState, defaultTimestamp);
475- if (statement.isTracing())
476- request.setTracingRequested();
477-
478- return request;
479- }
480-
481- Message.Request makeRequestMessage(Statement statement, ConsistencyLevel cl, ConsistencyLevel scl, ByteBuffer pagingState, long defaultTimestamp) {
482- ProtocolVersion protoVersion = cluster.manager.protocolVersion();
483474 int fetchSize = statement.getFetchSize();
484475 ByteBuffer usedPagingState = pagingState;
485476
486- if (protoVersion == ProtocolVersion.V1) {
477+ if (version == ProtocolVersion.V1) {
487478 assert pagingState == null;
488479 // We don't let the user change the fetchSize globally if the proto v1 is used, so we just need to
489480 // check for the case of a per-statement override
490481 if (fetchSize <= 0)
491482 fetchSize = -1;
492483 else if (fetchSize != Integer.MAX_VALUE)
493- throw new UnsupportedFeatureException(protoVersion, "Paging is not supported");
484+ throw new UnsupportedFeatureException(version, "Paging is not supported");
494485 } else if (fetchSize <= 0) {
495486 fetchSize = configuration().getQueryOptions().getFetchSize();
496487 }
@@ -511,19 +502,19 @@
511502 // It saddens me that we special case for the query builder here, but for now this is simpler.
512503 // We could provide a general API in RegularStatement instead at some point but it's unclear what's
513504 // the cleanest way to do that is right now (and it's probably not really that useful anyway).
514- if (protoVersion == ProtocolVersion.V1 && rs instanceof com.datastax.driver.core.querybuilder.BuiltStatement)
505+ if (version == ProtocolVersion.V1 && rs instanceof com.datastax.driver.core.querybuilder.BuiltStatement)
515506 ((com.datastax.driver.core.querybuilder.BuiltStatement)rs).setForceNoValues(true);
516507
517- ByteBuffer[] rawValues = rs.getValues(protoVersion);
508+ ByteBuffer[] rawValues = rs.getValues(version);
518509
519- if (protoVersion == ProtocolVersion.V1 && rawValues != null)
520- throw new UnsupportedFeatureException(protoVersion, "Binary values are not supported");
510+ if (version == ProtocolVersion.V1 && rawValues != null)
511+ throw new UnsupportedFeatureException(version, "Binary values are not supported");
521512
522513 List<ByteBuffer> values = rawValues == null ? Collections.<ByteBuffer>emptyList() : Arrays.asList(rawValues);
523514 String qString = rs.getQueryString();
524- Requests.QueryProtocolOptions options = new Requests.QueryProtocolOptions(cl, values, false,
525- fetchSize, usedPagingState, scl, defaultTimestamp);
526- return new Requests.Query(qString, options);
515+ Requests.QueryProtocolOptions options = new Requests.QueryProtocolOptions(consistency, values, false,
516+ fetchSize, usedPagingState, serialConsistency, defaultTimestamp);
517+ return new Requests.Query(qString, options, statement.isTracing());
527518 } else if (statement instanceof BoundStatement) {
528519 BoundStatement bs = (BoundStatement)statement;
529520 if (!cluster.manager.preparedQueries.containsKey(bs.statement.getPreparedId().id)) {
@@ -531,22 +522,22 @@
531522 + "You may have used a PreparedStatement that was created with another Cluster instance.", bs.statement.getPreparedId().id));
532523 }
533524 bs.ensureAllSet();
534- boolean skipMetadata = protoVersion != ProtocolVersion.V1 && bs.statement.getPreparedId().resultSetMetadata != null;
535- Requests.QueryProtocolOptions options = new Requests.QueryProtocolOptions(cl, Arrays.asList(bs.wrapper.values), skipMetadata,
536- fetchSize, usedPagingState, scl, defaultTimestamp);
537- return new Requests.Execute(bs.statement.getPreparedId().id, options);
525+ boolean skipMetadata = version != ProtocolVersion.V1 && bs.statement.getPreparedId().resultSetMetadata != null;
526+ Requests.QueryProtocolOptions options = new Requests.QueryProtocolOptions(consistency, Arrays.asList(bs.wrapper.values), skipMetadata,
527+ fetchSize, usedPagingState, serialConsistency, defaultTimestamp);
528+ return new Requests.Execute(bs.statement.getPreparedId().id, options, statement.isTracing());
538529 } else {
539530 assert statement instanceof BatchStatement : statement;
540531 assert pagingState == null;
541532
542- if (protoVersion == ProtocolVersion.V1)
543- throw new UnsupportedFeatureException(protoVersion, "Protocol level batching is not supported");
533+ if (version == ProtocolVersion.V1)
534+ throw new UnsupportedFeatureException(version, "Protocol level batching is not supported");
544535
545536 BatchStatement bs = (BatchStatement)statement;
546537 bs.ensureAllSet();
547- BatchStatement.IdAndValues idAndVals = bs.getIdAndValues(protoVersion);
548- Requests.BatchProtocolOptions options = new Requests.BatchProtocolOptions(cl, scl, defaultTimestamp);
549- return new Requests.Batch(bs.batchType, idAndVals.ids, idAndVals.values, options);
538+ BatchStatement.IdAndValues idAndVals = bs.getIdAndValues(version);
539+ Requests.BatchProtocolOptions options = new Requests.BatchProtocolOptions(consistency, serialConsistency, defaultTimestamp);
540+ return new Requests.Batch(bs.batchType, idAndVals.ids, idAndVals.values, options, statement.isTracing());
550541 }
551542 }
552543
modified driver-core/src/main/java/com/datastax/driver/core/policies/DowngradingConsistencyRetryPolicy.java +1 −1
@@ -156,7 +156,7 @@
156156 case SIMPLE:
157157 case BATCH:
158158 // Since we provide atomicity there is no point in retrying
159- return requiredAcks > 0 ? RetryDecision.ignore() : RetryDecision.rethrow();
159+ return receivedAcks > 0 ? RetryDecision.ignore() : RetryDecision.rethrow();
160160 case UNLOGGED_BATCH:
161161 // Since only part of the batch could have been persisted,
162162 // retry with whatever consistency should allow to persist all
modified driver-core/src/main/java/com/datastax/driver/core/querybuilder/Delete.java +32 −7
@@ -344,7 +344,7 @@
344344 * @return this in-build DELETE Selection
345345 */
346346 public Selection listElt(String columnName, int idx) {
347- columns.add(new IndexedSelector(columnName, idx));
347+ columns.add(new CollectionElementSelector(columnName, idx));
348348 return this;
349349 }
350350
@@ -357,7 +357,32 @@
357357 * @return this in-build DELETE Selection
358358 */
359359 public Selection listElt(String columnName, BindMarker idx) {
360- columns.add(new IndexedSelector(columnName, idx));
360+ columns.add(new CollectionElementSelector(columnName, idx));
361+ return this;
362+ }
363+
364+ /**
365+ * Deletes the provided set element.
366+ *
367+ * @param columnName the name of the set column.
368+ * @param element the element to delete.
369+ * @return this in-build DELETE Selection
370+ */
371+ public Selection setElt(String columnName, Object element) {
372+ columns.add(new CollectionElementSelector(columnName, element));
373+ return this;
374+ }
375+
376+ /**
377+ * Deletes the provided set element,
378+ * specified as a bind marker.
379+ *
380+ * @param columnName the name of the set column.
381+ * @param element the element to delete.
382+ * @return this in-build DELETE Selection
383+ */
384+ public Selection setElt(String columnName, BindMarker element) {
385+ columns.add(new CollectionElementSelector(columnName, element));
361386 return this;
362387 }
363388
@@ -369,7 +394,7 @@
369394 * @return this in-build DELETE Selection
370395 */
371396 public Selection mapElt(String columnName, Object key) {
372- columns.add(new IndexedSelector(columnName, key));
397+ columns.add(new CollectionElementSelector(columnName, key));
373398 return this;
374399 }
375400 }
@@ -377,7 +402,7 @@
377402 /**
378403 * A selector in a DELETE selection clause.
379404 * A selector can be either a column name,
380- * a list element or a map entry.
405+ * a list element, a set element or a map entry.
381406 */
382407 static class Selector extends Utils.Appendeable {
383408
@@ -406,13 +431,13 @@
406431 }
407432
408433 /**
409- * A list element or a map entry in a DELETE selection clause.
434+ * A selector representing a list index, a set element or a map key in a DELETE selection clause.
410435 */
411- static class IndexedSelector extends Selector {
436+ static class CollectionElementSelector extends Selector {
412437
413438 private final Object key;
414439
415- IndexedSelector(String columnName, Object key) {
440+ CollectionElementSelector(String columnName, Object key) {
416441 super(columnName);
417442 this.key = key;
418443 }
modified driver-core/src/test/java/com/datastax/driver/core/NetworkTopologyStrategyTest.java +41 −0
@@ -22,8 +22,12 @@
2222 import com.google.common.collect.ImmutableList;
2323 import com.google.common.collect.ImmutableMap;
2424 import com.google.common.collect.ImmutableMap.Builder;
25+import org.apache.log4j.Level;
26+import org.apache.log4j.Logger;
2527 import org.testng.annotations.Test;
2628
29+import static org.assertj.core.api.Assertions.assertThat;
30+
2731 public class NetworkTopologyStrategyTest extends AbstractReplicationStrategyTest {
2832
2933 private static class ReplicationFactorDefinition {
@@ -589,4 +593,41 @@
589593 assertReplicaPlacement(replicaMap, TOKEN17, IP2, IP6, IP1, IP5, IP3, IP4);
590594 assertReplicaPlacement(replicaMap, TOKEN18, IP6, IP1, IP5, IP3, IP2, IP4);
591595 }
596+
597+ @Test(groups = "unit")
598+ public void should_warn_if_replication_factor_cannot_be_met() {
599+ Logger logger = Logger.getLogger(ReplicationStrategy.NetworkTopologyStrategy.class);
600+ MemoryAppender logs = new MemoryAppender();
601+ logger.setLevel(Level.WARN);
602+ logger.addAppender(logs);
603+
604+ List<Token> ring = ImmutableList.<Token>builder()
605+ .add(TOKEN01)
606+ .add(TOKEN02)
607+ .add(TOKEN03)
608+ .add(TOKEN04)
609+ .build();
610+
611+ Map<Token, Host> tokenToPrimary = ImmutableMap.<Token, Host>builder()
612+ .put(TOKEN01, host(IP1, DC1, RACK11))
613+ .put(TOKEN02, host(IP2, DC1, RACK12))
614+ .put(TOKEN03, host(IP3, DC2, RACK21))
615+ .put(TOKEN04, host(IP4, DC2, RACK22))
616+ .build();
617+
618+ // Wrong configuration: impossible replication factor for DC2
619+ networkTopologyStrategy(rf(DC1, 2), rf(DC2, 3))
620+ .computeTokenToReplicaMap(tokenToPrimary, ring);
621+ assertThat(logs.getNext())
622+ .contains("Error while computing token map for datacenter DC2");
623+
624+ // Wrong configuration: non-existing datacenter
625+ networkTopologyStrategy(rf(DC1, 2), rf("does_not_exist", 2))
626+ .computeTokenToReplicaMap(tokenToPrimary, ring);
627+ assertThat(logs.getNext())
628+ .contains("Error while computing token map for datacenter does_not_exist");
629+
630+ logger.setLevel(null);
631+ logger.removeAppender(logs);
632+ }
592633 }
modified driver-core/src/test/java/com/datastax/driver/core/TracingTest.java +25 −0
@@ -20,6 +20,7 @@
2020 import java.util.List;
2121 import java.util.UUID;
2222
23+import com.datastax.driver.core.policies.DowngradingConsistencyRetryPolicy;
2324 import com.datastax.driver.core.utils.CassandraVersion;
2425 import org.testng.annotations.BeforeClass;
2526 import org.testng.annotations.Test;
@@ -29,6 +30,11 @@
2930 @CassandraVersion(major=2.0)
3031 public class TracingTest extends CCMBridge.PerClassSingleNodeCluster {
3132
33+ @Override
34+ protected Cluster.Builder configure(Cluster.Builder builder) {
35+ return builder.withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE);
36+ }
37+
3238 public static final String KEY = "tracing_test";
3339
3440 @Override
@@ -69,5 +75,24 @@
6975 assertThat(result.getExecutionInfo().getQueryTrace().getEvents()).isNotNull()
7076 .isNotEmpty();
7177 }
78+
79+ /**
80+ * Validates that if a query gets retried, the second internal query will still have tracing enabled.
81+ *
82+ * To force a retry, we use the downgrading policy with an impossible CL.
83+ *
84+ * @test_category tracing
85+ * @jira_ticket JAVA-815
86+ * @expected_result {@link ResultSet} where {@link ExecutionInfo} contains trace information after a retry.
87+ */
88+ @Test(groups = "short")
89+ public void should_preserve_tracing_status_across_retries() {
90+ SimpleStatement st = new SimpleStatement(String.format("SELECT v FROM test WHERE k='%s'", KEY));
91+ st.setConsistencyLevel(ConsistencyLevel.THREE).enableTracing();
92+
93+ ResultSet result = session.execute(st);
94+
95+ assertThat(result.getExecutionInfo().getQueryTrace()).isNotNull();
96+ }
7297 }
7398
modified driver-core/src/test/java/com/datastax/driver/core/querybuilder/QueryBuilderExecutionTest.java +30 −5
@@ -38,7 +38,7 @@
3838 return Arrays.asList(
3939 String.format(TestUtils.CREATE_TABLE_SIMPLE_FORMAT, TABLE1),
4040 "CREATE TABLE dateTest (t timestamp PRIMARY KEY)",
41- "CREATE TABLE test_coll (k int PRIMARY KEY, a list<int>, b map<int,text>)");
41+ "CREATE TABLE test_coll (k int PRIMARY KEY, a list<int>, b map<int,text>, c set<text>)");
4242 }
4343
4444 @Test(groups = "short")
@@ -124,7 +124,7 @@
124124 @Test(groups = "short")
125125 public void should_delete_list_element_with_bind_marker() throws Exception {
126126 //given
127- session.execute("INSERT INTO test_coll (k, a, b) VALUES (1, [1,2,3], null)");
127+ session.execute("INSERT INTO test_coll (k, a) VALUES (1, [1,2,3])");
128128 //when
129129 BuiltStatement statement = delete().listElt("a", bindMarker()).from("test_coll").where(eq("k", 1));
130130 PreparedStatement ps = session.prepare(statement);
@@ -134,10 +134,35 @@
134134 assertThat(actual).containsExactly(1, 3);
135135 }
136136
137+ @Test(groups = "short")
138+ public void should_delete_set_element() throws Exception {
139+ //given
140+ session.execute("INSERT INTO test_coll (k, c) VALUES (1, {'foo','bar','qix'})");
141+ //when
142+ BuiltStatement statement = delete().setElt("c", "foo").from("test_coll").where(eq("k", 1));
143+ session.execute(statement);
144+ //then
145+ Set<String> actual = session.execute("SELECT c FROM test_coll WHERE k = 1").one().getSet("c", String.class);
146+ assertThat(actual).containsOnly("bar", "qix");
147+ }
148+
149+ @Test(groups = "short")
150+ public void should_delete_set_element_with_bind_marker() throws Exception {
151+ //given
152+ session.execute("INSERT INTO test_coll (k, c) VALUES (1, {'foo','bar','qix'})");
153+ //when
154+ BuiltStatement statement = delete().setElt("c", bindMarker()).from("test_coll").where(eq("k", 1));
155+ PreparedStatement ps = session.prepare(statement);
156+ session.execute(ps.bind("foo"));
157+ //then
158+ Set<String> actual = session.execute("SELECT c FROM test_coll WHERE k = 1").one().getSet("c", String.class);
159+ assertThat(actual).containsOnly("bar", "qix");
160+ }
161+
137162 @Test(groups = "short")
138163 public void should_delete_map_entry() throws Exception {
139164 //given
140- session.execute("INSERT INTO test_coll (k, a, b) VALUES (1, null, {1:'foo', 2:'bar'})");
165+ session.execute("INSERT INTO test_coll (k, b) VALUES (1, {1:'foo', 2:'bar'})");
141166 //when
142167 BuiltStatement statement = delete().mapElt("b", 1).from("test_coll").where(eq("k", 1));
143168 session.execute(statement);
@@ -151,9 +176,9 @@
151176 //given
152177 session.execute("INSERT INTO test_coll (k, a, b) VALUES (1, null, {1:'foo', 2:'bar'})");
153178 //when
154- BuiltStatement statement = delete().mapElt("b", bindMarker("mapEntry")).from("test_coll").where(eq("k", 1));
179+ BuiltStatement statement = delete().mapElt("b", bindMarker()).from("test_coll").where(eq("k", 1));
155180 PreparedStatement ps = session.prepare(statement);
156- session.execute(ps.bind().setInt("mapEntry", 1));
181+ session.execute(ps.bind().setInt(0, 1));
157182 //then
158183 Map<Integer, String> actual = session.execute("SELECT b FROM test_coll WHERE k = 1").one().getMap("b", Integer.class, String.class);
159184 assertThat(actual).containsExactly(entry(2, "bar"));
modified driver-dist/src/assembly/binary-tarball.xml +1 −0
@@ -37,6 +37,7 @@
3737 <outputDirectory>lib</outputDirectory>
3838 <excludes>
3939 <exclude>com.datastax.cassandra:*</exclude>
40+ <exclude>io.netty:netty-transport-native-epoll:*</exclude>
4041 </excludes>
4142 </dependencySet>
4243 </dependencySets>