Updated Branches: refs/heads/trunk 5f5905d51 -> 45bb92467
Reject CAS queries with the native protocol v1 patch by slebresne; reviewed by iamaleksey for CASSANDRA-6270 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/4169aa3d Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/4169aa3d Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/4169aa3d Branch: refs/heads/trunk Commit: 4169aa3d448c402da32ff5b10f687fbd460fc1e1 Parents: 392be16 Author: Sylvain Lebresne <sylv...@datastax.com> Authored: Wed Oct 30 17:20:55 2013 +0100 Committer: Sylvain Lebresne <sylv...@datastax.com> Committed: Wed Oct 30 17:22:17 2013 +0100 ---------------------------------------------------------------------- CHANGES.txt | 1 + .../org/apache/cassandra/cql3/QueryOptions.java | 27 +++++++++++++++++--- .../cql3/statements/ModificationStatement.java | 3 +++ .../cassandra/transport/SimpleClient.java | 5 ++-- .../transport/messages/ExecuteMessage.java | 7 +---- .../transport/messages/QueryMessage.java | 7 +---- 6 files changed, 31 insertions(+), 19 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/4169aa3d/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index b9b93fe..6aad468 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -9,6 +9,7 @@ * Provide hooks around CQL2/CQL3 statement execution (CASSANDRA-6252) * Require Permission.SELECT for CAS updates (CASSANDRA-6247) * New CQL-aware SSTableWriter (CASSANDRA-5894) + * Reject CAS operation when the protocol v1 is used (CASSANDRA-6270) Merged from 1.2: * Require logging in for Thrift CQL2/3 statement preparation (CASSANDRA-6254) * restrict max_num_tokens to 1536 (CASSANDRA-6267) http://git-wip-us.apache.org/repos/asf/cassandra/blob/4169aa3d/src/java/org/apache/cassandra/cql3/QueryOptions.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/cql3/QueryOptions.java b/src/java/org/apache/cassandra/cql3/QueryOptions.java index c8c6b8e..72edfbf 100644 --- a/src/java/org/apache/cassandra/cql3/QueryOptions.java +++ b/src/java/org/apache/cassandra/cql3/QueryOptions.java @@ -45,9 +45,13 @@ public class QueryOptions private final SpecificOptions options; + // The protocol version of incoming queries. This is set during deserializaion and will be 0 + // if the QueryOptions does not come from a user message (or come from thrift). + private final transient int protocolVersion; + public QueryOptions(ConsistencyLevel consistency, List<ByteBuffer> values) { - this(consistency, values, false, SpecificOptions.DEFAULT); + this(consistency, values, false, SpecificOptions.DEFAULT, 0); } public QueryOptions(ConsistencyLevel consistency, @@ -57,15 +61,21 @@ public class QueryOptions PagingState pagingState, ConsistencyLevel serialConsistency) { - this(consistency, values, skipMetadata, new SpecificOptions(pageSize, pagingState, serialConsistency)); + this(consistency, values, skipMetadata, new SpecificOptions(pageSize, pagingState, serialConsistency), 0); } - private QueryOptions(ConsistencyLevel consistency, List<ByteBuffer> values, boolean skipMetadata, SpecificOptions options) + private QueryOptions(ConsistencyLevel consistency, List<ByteBuffer> values, boolean skipMetadata, SpecificOptions options, int protocolVersion) { this.consistency = consistency; this.values = values; this.skipMetadata = skipMetadata; this.options = options; + this.protocolVersion = protocolVersion; + } + + public static QueryOptions fromProtocolV1(ConsistencyLevel consistency, List<ByteBuffer> values) + { + return new QueryOptions(consistency, values, false, SpecificOptions.DEFAULT, 1); } public ConsistencyLevel getConsistency() @@ -107,6 +117,15 @@ public class QueryOptions return options.serialConsistency; } + /** + * The protocol version for the query. Will be 0 if the object don't come from + * a native protocol request (i.e. it's been allocated locally or by CQL-over-thrift). + */ + public int getProtocolVersion() + { + return protocolVersion; + } + // Options that are likely to not be present in most queries private static class SpecificOptions { @@ -179,7 +198,7 @@ public class QueryOptions ConsistencyLevel serialConsistency = flags.contains(Flag.SERIAL_CONSISTENCY) ? CBUtil.readConsistencyLevel(body) : ConsistencyLevel.SERIAL; options = new SpecificOptions(pageSize, pagingState, serialConsistency); } - return new QueryOptions(consistency, values, skipMetadata, options); + return new QueryOptions(consistency, values, skipMetadata, options, version); } public void encode(QueryOptions options, ChannelBuffer dest, int version) http://git-wip-us.apache.org/repos/asf/cassandra/blob/4169aa3d/src/java/org/apache/cassandra/cql3/statements/ModificationStatement.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/cql3/statements/ModificationStatement.java b/src/java/org/apache/cassandra/cql3/statements/ModificationStatement.java index 7aebc48..f5cff1d 100644 --- a/src/java/org/apache/cassandra/cql3/statements/ModificationStatement.java +++ b/src/java/org/apache/cassandra/cql3/statements/ModificationStatement.java @@ -363,6 +363,9 @@ public abstract class ModificationStatement implements CQLStatement if (options.getConsistency() == null) throw new InvalidRequestException("Invalid empty consistency level"); + if (hasConditions() && options.getProtocolVersion() == 1) + throw new InvalidRequestException("Conditional updates are not supported by the protocol version in use. You need to upgrade to a driver using the native protocol v2."); + return hasConditions() ? executeWithCondition(queryState, options) : executeWithoutCondition(queryState, options); http://git-wip-us.apache.org/repos/asf/cassandra/blob/4169aa3d/src/java/org/apache/cassandra/transport/SimpleClient.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/transport/SimpleClient.java b/src/java/org/apache/cassandra/transport/SimpleClient.java index 94be162..5f2efda 100644 --- a/src/java/org/apache/cassandra/transport/SimpleClient.java +++ b/src/java/org/apache/cassandra/transport/SimpleClient.java @@ -20,6 +20,7 @@ package org.apache.cassandra.transport; import java.io.IOException; import java.net.InetSocketAddress; import java.nio.ByteBuffer; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -153,9 +154,7 @@ public class SimpleClient public ResultMessage execute(String query, ConsistencyLevel consistency) { - Message.Response msg = execute(new QueryMessage(query, consistency)); - assert msg instanceof ResultMessage; - return (ResultMessage)msg; + return execute(query, Collections.<ByteBuffer>emptyList(), consistency); } public ResultMessage execute(String query, List<ByteBuffer> values, ConsistencyLevel consistencyLevel) http://git-wip-us.apache.org/repos/asf/cassandra/blob/4169aa3d/src/java/org/apache/cassandra/transport/messages/ExecuteMessage.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/transport/messages/ExecuteMessage.java b/src/java/org/apache/cassandra/transport/messages/ExecuteMessage.java index 887806a..c090f9f 100644 --- a/src/java/org/apache/cassandra/transport/messages/ExecuteMessage.java +++ b/src/java/org/apache/cassandra/transport/messages/ExecuteMessage.java @@ -48,7 +48,7 @@ public class ExecuteMessage extends Message.Request { List<ByteBuffer> values = CBUtil.readValueList(body); ConsistencyLevel consistency = CBUtil.readConsistencyLevel(body); - return new ExecuteMessage(id, values, consistency); + return new ExecuteMessage(MD5Digest.wrap(id), QueryOptions.fromProtocolV1(consistency, values)); } else { @@ -90,11 +90,6 @@ public class ExecuteMessage extends Message.Request public final MD5Digest statementId; public final QueryOptions options; - public ExecuteMessage(byte[] statementId, List<ByteBuffer> values, ConsistencyLevel consistency) - { - this(MD5Digest.wrap(statementId), new QueryOptions(consistency, values)); - } - public ExecuteMessage(MD5Digest statementId, QueryOptions options) { super(Message.Type.EXECUTE); http://git-wip-us.apache.org/repos/asf/cassandra/blob/4169aa3d/src/java/org/apache/cassandra/transport/messages/QueryMessage.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/transport/messages/QueryMessage.java b/src/java/org/apache/cassandra/transport/messages/QueryMessage.java index 6d312fb..744e0ea 100644 --- a/src/java/org/apache/cassandra/transport/messages/QueryMessage.java +++ b/src/java/org/apache/cassandra/transport/messages/QueryMessage.java @@ -47,7 +47,7 @@ public class QueryMessage extends Message.Request if (version == 1) { ConsistencyLevel consistency = CBUtil.readConsistencyLevel(body); - return new QueryMessage(query, consistency); + return new QueryMessage(query, QueryOptions.fromProtocolV1(consistency, Collections.<ByteBuffer>emptyList())); } else { @@ -83,11 +83,6 @@ public class QueryMessage extends Message.Request public final String query; public final QueryOptions options; - public QueryMessage(String query, ConsistencyLevel consistency) - { - this(query, new QueryOptions(consistency, Collections.<ByteBuffer>emptyList())); - } - public QueryMessage(String query, QueryOptions options) { super(Type.QUERY);