kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | afd83c38482e87541ef658350d7702e20865b2567aef2f2a908c5e0b14dc799b |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2015-06-26 22:52 +02:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2015-06-26 22:55 +02:00 |
| Parents | f7b60ca29eb5, c7bbffe1167f |
13 files changed
modified changelog/README.md +31 −4
| @@ -10,16 +10,29 @@ | ||
| 10 | 10 | - [improvement] Create values() function for Insert builder using List (JAVA-225) |
| 11 | 11 | - [improvement] HashMap throws an OOM Exception when logging level is set to TRACE (JAVA-713) |
| 12 | 12 | - [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) | |
| 15 | 13 | - [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) | |
| 18 | 14 | - [improvement] Allow @Enumerated in Accessor method parameters (JAVA-589) |
| 19 | 15 | - [improvement] Allow access to table metadata from Mapper (JAVA-554) |
| 20 | 16 | - [improvement] Provide a way to map computed fields (JAVA-661) |
| 21 | 17 | - [improvement] Ignore missing columns in mapper (JAVA-824) |
| 22 | 18 | |
| 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 | + | |
| 23 | 36 | |
| 24 | 37 | ### 2.1.6 |
| 25 | 38 | |
| @@ -239,6 +252,20 @@ | ||
| 239 | 252 | - [improvement] Suppress unnecessary warning at shutdown (JAVA-710) |
| 240 | 253 | - [improvement] Allow DNS name with multiple A-records as contact point (#340) |
| 241 | 254 | - [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) | |
| 242 | 269 | |
| 243 | 270 | Merged from 2.0.10_fixes branch: |
| 244 | 271 |
modified driver-core/src/main/java/com/datastax/driver/core/Message.java +13 −4
| @@ -82,14 +82,15 @@ | ||
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | public final Type type; |
| 85 | - protected boolean tracingRequested; | |
| 85 | + private final boolean tracingRequested; | |
| 86 | 86 | |
| 87 | 87 | protected Request(Type type) { |
| 88 | - this.type = type; | |
| 88 | + this(type, false); | |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - public void setTracingRequested() { | |
| 92 | - this.tracingRequested = true; | |
| 91 | + protected Request(Type type, boolean tracingRequested) { | |
| 92 | + this.type = type; | |
| 93 | + this.tracingRequested = tracingRequested; | |
| 93 | 94 | } |
| 94 | 95 | |
| 95 | 96 | public boolean isTracingRequested() { |
| @@ -130,6 +131,14 @@ | ||
| 130 | 131 | default: return null; |
| 131 | 132 | } |
| 132 | 133 | } |
| 134 | + | |
| 135 | + Request copy() { | |
| 136 | + throw new UnsupportedOperationException(); | |
| 137 | + } | |
| 138 | + | |
| 139 | + Request copy(ConsistencyLevel newConsistencyLevel) { | |
| 140 | + throw new UnsupportedOperationException(); | |
| 141 | + } | |
| 133 | 142 | } |
| 134 | 143 | |
| 135 | 144 | 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 @@ | ||
| 256 | 256 | return this; |
| 257 | 257 | } |
| 258 | 258 | |
| 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 | + | |
| 259 | 283 | /** |
| 260 | 284 | * Returns the timeout before an idle connection is removed. |
| 261 | 285 | * |
modified driver-core/src/main/java/com/datastax/driver/core/ReplicationStategy.java +26 −0
| @@ -18,6 +18,9 @@ | ||
| 18 | 18 | import java.util.*; |
| 19 | 19 | |
| 20 | 20 | import com.google.common.collect.ImmutableSet; |
| 21 | +import com.google.common.collect.Sets; | |
| 22 | +import org.slf4j.Logger; | |
| 23 | +import org.slf4j.LoggerFactory; | |
| 21 | 24 | |
| 22 | 25 | /* |
| 23 | 26 | * Computes the token->list<replica> association, given the token ring and token->primary token map. |
| @@ -87,6 +90,7 @@ | ||
| 87 | 90 | } |
| 88 | 91 | |
| 89 | 92 | static class NetworkTopologyStrategy extends ReplicationStrategy { |
| 93 | + private static final Logger logger = LoggerFactory.getLogger(NetworkTopologyStrategy.class); | |
| 90 | 94 | |
| 91 | 95 | private final Map<String, Integer> replicationFactors; |
| 92 | 96 | |
| @@ -99,6 +103,9 @@ | ||
| 99 | 103 | // This is essentially a copy of org.apache.cassandra.locator.NetworkTopologyStrategy |
| 100 | 104 | Map<String, Set<String>> racks = getRacksInDcs(tokenToPrimary.values()); |
| 101 | 105 | Map<Token, Set<Host>> replicaMap = new HashMap<Token, Set<Host>>(tokenToPrimary.size()); |
| 106 | + | |
| 107 | + Set<String> warnedDcs = Sets.newHashSetWithExpectedSize(replicationFactors.size()); | |
| 108 | + | |
| 102 | 109 | for (int i = 0; i < ring.size(); i++) { |
| 103 | 110 | Map<String, Set<Host>> allDcReplicas = new HashMap<String, Set<Host>>(); |
| 104 | 111 | Map<String, Set<String>> seenRacks = new HashMap<String, Set<String>>(); |
| @@ -147,6 +154,25 @@ | ||
| 147 | 154 | } |
| 148 | 155 | } |
| 149 | 156 | } |
| 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 | + | |
| 150 | 176 | replicaMap.put(ring.get(i), ImmutableSet.copyOf(replicas)); |
| 151 | 177 | } |
| 152 | 178 | return replicaMap; |
modified driver-core/src/main/java/com/datastax/driver/core/RequestHandler.java +2 −2
| @@ -111,7 +111,7 @@ | ||
| 111 | 111 | // Clone the request after the first execution, since we set the streamId on it later and we |
| 112 | 112 | // don't want to share that across executions. |
| 113 | 113 | if (position > 1) |
| 114 | - request = manager.makeRequestMessage(statement, request.pagingState()) ; | |
| 114 | + request = request.copy(); | |
| 115 | 115 | |
| 116 | 116 | SpeculativeExecution execution = new SpeculativeExecution(request, position); |
| 117 | 117 | runningExecutions.add(execution); |
| @@ -405,7 +405,7 @@ | ||
| 405 | 405 | @Override |
| 406 | 406 | public Message.Request request() { |
| 407 | 407 | if (retryConsistencyLevel != null && retryConsistencyLevel != request.consistency()) |
| 408 | - return manager.makeRequestMessage(statement, retryConsistencyLevel, request.serialConsistency(), request.pagingState(), request.defaultTimestamp()); | |
| 408 | + return request.copy(retryConsistencyLevel); | |
| 409 | 409 | else |
| 410 | 410 | return request; |
| 411 | 411 | } |
modified driver-core/src/main/java/com/datastax/driver/core/Requests.java +44 −7
| @@ -125,15 +125,25 @@ | ||
| 125 | 125 | public final QueryProtocolOptions options; |
| 126 | 126 | |
| 127 | 127 | public Query(String query) { |
| 128 | - this(query, QueryProtocolOptions.DEFAULT); | |
| 128 | + this(query, QueryProtocolOptions.DEFAULT, false); | |
| 129 | 129 | } |
| 130 | 130 | |
| 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); | |
| 133 | 133 | this.query = query; |
| 134 | 134 | this.options = options; |
| 135 | 135 | } |
| 136 | 136 | |
| 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 | + | |
| 137 | 147 | @Override |
| 138 | 148 | public String toString() { |
| 139 | 149 | return "QUERY " + query + '(' + options + ')'; |
| @@ -157,12 +167,22 @@ | ||
| 157 | 167 | public final MD5Digest statementId; |
| 158 | 168 | public final QueryProtocolOptions options; |
| 159 | 169 | |
| 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); | |
| 162 | 172 | this.statementId = statementId; |
| 163 | 173 | this.options = options; |
| 164 | 174 | } |
| 165 | 175 | |
| 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 | + | |
| 166 | 186 | @Override |
| 167 | 187 | public String toString() { |
| 168 | 188 | return "EXECUTE " + statementId + " (" + options + ')'; |
| @@ -248,6 +268,10 @@ | ||
| 248 | 268 | flags.add(QueryFlag.DEFAULT_TIMESTAMP); |
| 249 | 269 | } |
| 250 | 270 | |
| 271 | + public QueryProtocolOptions copy(ConsistencyLevel newConsistencyLevel) { | |
| 272 | + return new QueryProtocolOptions(newConsistencyLevel, values, skipMetadata, pageSize, pagingState, serialConsistency, defaultTimestamp); | |
| 273 | + } | |
| 274 | + | |
| 251 | 275 | public void encode(ByteBuf dest, ProtocolVersion version) { |
| 252 | 276 | switch (version) { |
| 253 | 277 | case V1: |
| @@ -360,14 +384,23 @@ | ||
| 360 | 384 | public final List<List<ByteBuffer>> values; |
| 361 | 385 | public final BatchProtocolOptions options; |
| 362 | 386 | |
| 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); | |
| 365 | 389 | this.type = type; |
| 366 | 390 | this.queryOrIdList = queryOrIdList; |
| 367 | 391 | this.values = values; |
| 368 | 392 | this.options = options; |
| 369 | 393 | } |
| 370 | 394 | |
| 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 | + } | |
| 371 | 404 | @Override |
| 372 | 405 | public String toString() { |
| 373 | 406 | StringBuilder sb = new StringBuilder(); |
| @@ -398,6 +431,10 @@ | ||
| 398 | 431 | flags.add(QueryFlag.DEFAULT_TIMESTAMP); |
| 399 | 432 | } |
| 400 | 433 | |
| 434 | + BatchProtocolOptions copy(ConsistencyLevel newConsistencyLevel) { | |
| 435 | + return new BatchProtocolOptions(newConsistencyLevel, serialConsistency, defaultTimestamp); | |
| 436 | + } | |
| 437 | + | |
| 401 | 438 | public void encode(ByteBuf dest, ProtocolVersion version) { |
| 402 | 439 | switch (version) { |
| 403 | 440 | case V2: |
modified driver-core/src/main/java/com/datastax/driver/core/SessionManager.java +18 −27
| @@ -471,26 +471,17 @@ | ||
| 471 | 471 | defaultTimestamp = cluster.getConfiguration().getPolicies().getTimestampGenerator().next(); |
| 472 | 472 | } |
| 473 | 473 | |
| 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(); | |
| 483 | 474 | int fetchSize = statement.getFetchSize(); |
| 484 | 475 | ByteBuffer usedPagingState = pagingState; |
| 485 | 476 | |
| 486 | - if (protoVersion == ProtocolVersion.V1) { | |
| 477 | + if (version == ProtocolVersion.V1) { | |
| 487 | 478 | assert pagingState == null; |
| 488 | 479 | // We don't let the user change the fetchSize globally if the proto v1 is used, so we just need to |
| 489 | 480 | // check for the case of a per-statement override |
| 490 | 481 | if (fetchSize <= 0) |
| 491 | 482 | fetchSize = -1; |
| 492 | 483 | else if (fetchSize != Integer.MAX_VALUE) |
| 493 | - throw new UnsupportedFeatureException(protoVersion, "Paging is not supported"); | |
| 484 | + throw new UnsupportedFeatureException(version, "Paging is not supported"); | |
| 494 | 485 | } else if (fetchSize <= 0) { |
| 495 | 486 | fetchSize = configuration().getQueryOptions().getFetchSize(); |
| 496 | 487 | } |
| @@ -511,19 +502,19 @@ | ||
| 511 | 502 | // It saddens me that we special case for the query builder here, but for now this is simpler. |
| 512 | 503 | // We could provide a general API in RegularStatement instead at some point but it's unclear what's |
| 513 | 504 | // 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) | |
| 515 | 506 | ((com.datastax.driver.core.querybuilder.BuiltStatement)rs).setForceNoValues(true); |
| 516 | 507 | |
| 517 | - ByteBuffer[] rawValues = rs.getValues(protoVersion); | |
| 508 | + ByteBuffer[] rawValues = rs.getValues(version); | |
| 518 | 509 | |
| 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"); | |
| 521 | 512 | |
| 522 | 513 | List<ByteBuffer> values = rawValues == null ? Collections.<ByteBuffer>emptyList() : Arrays.asList(rawValues); |
| 523 | 514 | 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()); | |
| 527 | 518 | } else if (statement instanceof BoundStatement) { |
| 528 | 519 | BoundStatement bs = (BoundStatement)statement; |
| 529 | 520 | if (!cluster.manager.preparedQueries.containsKey(bs.statement.getPreparedId().id)) { |
| @@ -531,22 +522,22 @@ | ||
| 531 | 522 | + "You may have used a PreparedStatement that was created with another Cluster instance.", bs.statement.getPreparedId().id)); |
| 532 | 523 | } |
| 533 | 524 | 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()); | |
| 538 | 529 | } else { |
| 539 | 530 | assert statement instanceof BatchStatement : statement; |
| 540 | 531 | assert pagingState == null; |
| 541 | 532 | |
| 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"); | |
| 544 | 535 | |
| 545 | 536 | BatchStatement bs = (BatchStatement)statement; |
| 546 | 537 | 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()); | |
| 550 | 541 | } |
| 551 | 542 | } |
| 552 | 543 |
modified driver-core/src/main/java/com/datastax/driver/core/policies/DowngradingConsistencyRetryPolicy.java +1 −1
| @@ -156,7 +156,7 @@ | ||
| 156 | 156 | case SIMPLE: |
| 157 | 157 | case BATCH: |
| 158 | 158 | // 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(); | |
| 160 | 160 | case UNLOGGED_BATCH: |
| 161 | 161 | // Since only part of the batch could have been persisted, |
| 162 | 162 | // 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 @@ | ||
| 344 | 344 | * @return this in-build DELETE Selection |
| 345 | 345 | */ |
| 346 | 346 | public Selection listElt(String columnName, int idx) { |
| 347 | - columns.add(new IndexedSelector(columnName, idx)); | |
| 347 | + columns.add(new CollectionElementSelector(columnName, idx)); | |
| 348 | 348 | return this; |
| 349 | 349 | } |
| 350 | 350 | |
| @@ -357,7 +357,32 @@ | ||
| 357 | 357 | * @return this in-build DELETE Selection |
| 358 | 358 | */ |
| 359 | 359 | 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)); | |
| 361 | 386 | return this; |
| 362 | 387 | } |
| 363 | 388 | |
| @@ -369,7 +394,7 @@ | ||
| 369 | 394 | * @return this in-build DELETE Selection |
| 370 | 395 | */ |
| 371 | 396 | public Selection mapElt(String columnName, Object key) { |
| 372 | - columns.add(new IndexedSelector(columnName, key)); | |
| 397 | + columns.add(new CollectionElementSelector(columnName, key)); | |
| 373 | 398 | return this; |
| 374 | 399 | } |
| 375 | 400 | } |
| @@ -377,7 +402,7 @@ | ||
| 377 | 402 | /** |
| 378 | 403 | * A selector in a DELETE selection clause. |
| 379 | 404 | * 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. | |
| 381 | 406 | */ |
| 382 | 407 | static class Selector extends Utils.Appendeable { |
| 383 | 408 | |
| @@ -406,13 +431,13 @@ | ||
| 406 | 431 | } |
| 407 | 432 | |
| 408 | 433 | /** |
| 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. | |
| 410 | 435 | */ |
| 411 | - static class IndexedSelector extends Selector { | |
| 436 | + static class CollectionElementSelector extends Selector { | |
| 412 | 437 | |
| 413 | 438 | private final Object key; |
| 414 | 439 | |
| 415 | - IndexedSelector(String columnName, Object key) { | |
| 440 | + CollectionElementSelector(String columnName, Object key) { | |
| 416 | 441 | super(columnName); |
| 417 | 442 | this.key = key; |
| 418 | 443 | } |
modified driver-core/src/test/java/com/datastax/driver/core/NetworkTopologyStrategyTest.java +41 −0
| @@ -22,8 +22,12 @@ | ||
| 22 | 22 | import com.google.common.collect.ImmutableList; |
| 23 | 23 | import com.google.common.collect.ImmutableMap; |
| 24 | 24 | import com.google.common.collect.ImmutableMap.Builder; |
| 25 | +import org.apache.log4j.Level; | |
| 26 | +import org.apache.log4j.Logger; | |
| 25 | 27 | import org.testng.annotations.Test; |
| 26 | 28 | |
| 29 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 30 | + | |
| 27 | 31 | public class NetworkTopologyStrategyTest extends AbstractReplicationStrategyTest { |
| 28 | 32 | |
| 29 | 33 | private static class ReplicationFactorDefinition { |
| @@ -589,4 +593,41 @@ | ||
| 589 | 593 | assertReplicaPlacement(replicaMap, TOKEN17, IP2, IP6, IP1, IP5, IP3, IP4); |
| 590 | 594 | assertReplicaPlacement(replicaMap, TOKEN18, IP6, IP1, IP5, IP3, IP2, IP4); |
| 591 | 595 | } |
| 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 | + } | |
| 592 | 633 | } |
modified driver-core/src/test/java/com/datastax/driver/core/TracingTest.java +25 −0
| @@ -20,6 +20,7 @@ | ||
| 20 | 20 | import java.util.List; |
| 21 | 21 | import java.util.UUID; |
| 22 | 22 | |
| 23 | +import com.datastax.driver.core.policies.DowngradingConsistencyRetryPolicy; | |
| 23 | 24 | import com.datastax.driver.core.utils.CassandraVersion; |
| 24 | 25 | import org.testng.annotations.BeforeClass; |
| 25 | 26 | import org.testng.annotations.Test; |
| @@ -29,6 +30,11 @@ | ||
| 29 | 30 | @CassandraVersion(major=2.0) |
| 30 | 31 | public class TracingTest extends CCMBridge.PerClassSingleNodeCluster { |
| 31 | 32 | |
| 33 | + @Override | |
| 34 | + protected Cluster.Builder configure(Cluster.Builder builder) { | |
| 35 | + return builder.withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE); | |
| 36 | + } | |
| 37 | + | |
| 32 | 38 | public static final String KEY = "tracing_test"; |
| 33 | 39 | |
| 34 | 40 | @Override |
| @@ -69,5 +75,24 @@ | ||
| 69 | 75 | assertThat(result.getExecutionInfo().getQueryTrace().getEvents()).isNotNull() |
| 70 | 76 | .isNotEmpty(); |
| 71 | 77 | } |
| 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 | + } | |
| 72 | 97 | } |
| 73 | 98 |
modified driver-core/src/test/java/com/datastax/driver/core/querybuilder/QueryBuilderExecutionTest.java +30 −5
| @@ -38,7 +38,7 @@ | ||
| 38 | 38 | return Arrays.asList( |
| 39 | 39 | String.format(TestUtils.CREATE_TABLE_SIMPLE_FORMAT, TABLE1), |
| 40 | 40 | "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>)"); | |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | @Test(groups = "short") |
| @@ -124,7 +124,7 @@ | ||
| 124 | 124 | @Test(groups = "short") |
| 125 | 125 | public void should_delete_list_element_with_bind_marker() throws Exception { |
| 126 | 126 | //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])"); | |
| 128 | 128 | //when |
| 129 | 129 | BuiltStatement statement = delete().listElt("a", bindMarker()).from("test_coll").where(eq("k", 1)); |
| 130 | 130 | PreparedStatement ps = session.prepare(statement); |
| @@ -134,10 +134,35 @@ | ||
| 134 | 134 | assertThat(actual).containsExactly(1, 3); |
| 135 | 135 | } |
| 136 | 136 | |
| 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 | + | |
| 137 | 162 | @Test(groups = "short") |
| 138 | 163 | public void should_delete_map_entry() throws Exception { |
| 139 | 164 | //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'})"); | |
| 141 | 166 | //when |
| 142 | 167 | BuiltStatement statement = delete().mapElt("b", 1).from("test_coll").where(eq("k", 1)); |
| 143 | 168 | session.execute(statement); |
| @@ -151,9 +176,9 @@ | ||
| 151 | 176 | //given |
| 152 | 177 | session.execute("INSERT INTO test_coll (k, a, b) VALUES (1, null, {1:'foo', 2:'bar'})"); |
| 153 | 178 | //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)); | |
| 155 | 180 | PreparedStatement ps = session.prepare(statement); |
| 156 | - session.execute(ps.bind().setInt("mapEntry", 1)); | |
| 181 | + session.execute(ps.bind().setInt(0, 1)); | |
| 157 | 182 | //then |
| 158 | 183 | Map<Integer, String> actual = session.execute("SELECT b FROM test_coll WHERE k = 1").one().getMap("b", Integer.class, String.class); |
| 159 | 184 | assertThat(actual).containsExactly(entry(2, "bar")); |
modified driver-dist/src/assembly/binary-tarball.xml +1 −0
| @@ -37,6 +37,7 @@ | ||
| 37 | 37 | <outputDirectory>lib</outputDirectory> |
| 38 | 38 | <excludes> |
| 39 | 39 | <exclude>com.datastax.cassandra:*</exclude> |
| 40 | + <exclude>io.netty:netty-transport-native-epoll:*</exclude> | |
| 40 | 41 | </excludes> |
| 41 | 42 | </dependencySet> |
| 42 | 43 | </dependencySets> |