Updated Branches: refs/heads/cassandra-1.2 a330716d4 -> 85443ec5c
Gentler version for CASSANDRA-5172 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/85443ec5 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/85443ec5 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/85443ec5 Branch: refs/heads/cassandra-1.2 Commit: 85443ec5c160e1778cc49edb791f48ad3fa5b535 Parents: a330716 Author: Sylvain Lebresne <[email protected]> Authored: Mon Jan 21 17:04:39 2013 +0100 Committer: Sylvain Lebresne <[email protected]> Committed: Mon Jan 21 17:04:39 2013 +0100 ---------------------------------------------------------------------- NEWS.txt | 10 ++-- .../org/apache/cassandra/service/ClientState.java | 2 +- .../apache/cassandra/thrift/CassandraServer.java | 45 +++++++++++++- 3 files changed, 47 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/85443ec5/NEWS.txt ---------------------------------------------------------------------- diff --git a/NEWS.txt b/NEWS.txt index e1e842c..072b647 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -21,11 +21,11 @@ Upgrading representation), but the new dateOf method can be used instead. Please refer to the reference documentation (http://cassandra.apache.org/doc/cql3/CQL.html) for more detail. - - Calling the set_cql_version of the thrift interface with a version that - don't start with 2 now raise an error (instead of being a no-op). Not - raising an error in that case makes it hard for CQL3 client that haven't - upgraded to use the new thrift CQL3 methods to understand what is going - wrong. + - For client implementors: CQL3 client using the thrift interface should + use the new execute_cql3_query, prepare_cql3_query and execute_prepared_cql3_query + since 1.2.0. However, Cassandra 1.2.0 was not complaining if CQL3 was set + through set_cql_version but the now CQL2 only methods were used. This is + now the case. 1.2 http://git-wip-us.apache.org/repos/asf/cassandra/blob/85443ec5/src/java/org/apache/cassandra/service/ClientState.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/service/ClientState.java b/src/java/org/apache/cassandra/service/ClientState.java index d0cf0ba..d7b394a 100644 --- a/src/java/org/apache/cassandra/service/ClientState.java +++ b/src/java/org/apache/cassandra/service/ClientState.java @@ -63,7 +63,7 @@ public class ClientState private volatile AuthenticatedUser user; private String keyspace; - private SemanticVersion cqlVersion = DEFAULT_CQL_VERSION; + private SemanticVersion cqlVersion; // internalCall is used to mark ClientState as used by some internal component // that should have an ability to modify system keyspace http://git-wip-us.apache.org/repos/asf/cassandra/blob/85443ec5/src/java/org/apache/cassandra/thrift/CassandraServer.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/thrift/CassandraServer.java b/src/java/org/apache/cassandra/thrift/CassandraServer.java index ce533f4..557ba2c 100644 --- a/src/java/org/apache/cassandra/thrift/CassandraServer.java +++ b/src/java/org/apache/cassandra/thrift/CassandraServer.java @@ -59,6 +59,7 @@ import org.apache.cassandra.service.*; import org.apache.cassandra.tracing.Tracing; import org.apache.cassandra.utils.ByteBufferUtil; import org.apache.cassandra.utils.Pair; +import org.apache.cassandra.utils.SemanticVersion; import org.apache.cassandra.utils.UUIDGen; import org.apache.thrift.TException; @@ -1658,9 +1659,32 @@ public class CassandraServer implements Cassandra.Iface return queryString; } + private void validateCQLVersion(int major) throws InvalidRequestException + { + /* + * The rules are: + * - If no version are set, we don't validate anything. The reason is + * that 1) old CQL2 client might not have called set_cql_version + * and 2) some client may have removed the set_cql_version for CQL3 + * when updating to 1.2.0. A CQL3 client upgrading from pre-1.2 + * shouldn't be in that case however since set_cql_version uses to + * be mandatory (for CQL3). + * - Otherwise, checks the major matches whatever was set. + */ + SemanticVersion versionSet = state().getCQLVersion(); + if (versionSet == null) + return; + + if (versionSet.major != major) + throw new InvalidRequestException( + "Cannot execute/prepare CQL" + major + " statement since the CQL has been set to CQL" + versionSet.major + + "(This might mean your client hasn't been upgraded correctly to use the new CQL3 methods introduced in Cassandra 1.2+)."); + } + public CqlResult execute_cql_query(ByteBuffer query, Compression compression) throws InvalidRequestException, UnavailableException, TimedOutException, SchemaDisagreementException, TException { + validateCQLVersion(2); try { String queryString = uncompress(query, compression); @@ -1694,6 +1718,7 @@ public class CassandraServer implements Cassandra.Iface public CqlResult execute_cql3_query(ByteBuffer query, Compression compression, ConsistencyLevel cLevel) throws InvalidRequestException, UnavailableException, TimedOutException, SchemaDisagreementException, TException { + validateCQLVersion(3); try { String queryString = uncompress(query, compression); @@ -1731,6 +1756,8 @@ public class CassandraServer implements Cassandra.Iface if (logger.isDebugEnabled()) logger.debug("prepare_cql_query"); + validateCQLVersion(2); + try { ThriftClientState cState = state(); @@ -1749,6 +1776,8 @@ public class CassandraServer implements Cassandra.Iface if (logger.isDebugEnabled()) logger.debug("prepare_cql3_query"); + validateCQLVersion(3); + try { ThriftClientState cState = state(); @@ -1764,6 +1793,8 @@ public class CassandraServer implements Cassandra.Iface public CqlResult execute_prepared_cql_query(int itemId, List<ByteBuffer> bindVariables) throws InvalidRequestException, UnavailableException, TimedOutException, SchemaDisagreementException, TException { + validateCQLVersion(2); + if (startSessionIfRequested()) { // TODO we don't have [typed] access to CQL bind variables here. CASSANDRA-4560 is open to add support. @@ -1803,6 +1834,8 @@ public class CassandraServer implements Cassandra.Iface public CqlResult execute_prepared_cql3_query(int itemId, List<ByteBuffer> bindVariables, ConsistencyLevel cLevel) throws InvalidRequestException, UnavailableException, TimedOutException, SchemaDisagreementException, TException { + validateCQLVersion(3); + if (startSessionIfRequested()) { // TODO we don't have [typed] access to CQL bind variables here. CASSANDRA-4560 is open to add support. @@ -1850,10 +1883,14 @@ public class CassandraServer implements Cassandra.Iface */ public void set_cql_version(String version) throws InvalidRequestException { - if (version.trim().startsWith("2")) - return; - - throw new InvalidRequestException("Invalid use of the CQL thrift interface. This most likely mean the client you are using has not been updated for Cassandra 1.2"); + try + { + state().setCQLVersion(version); + } + catch (org.apache.cassandra.exceptions.InvalidRequestException e) + { + throw new InvalidRequestException(e.getMessage()); + } } public ByteBuffer trace_next_query() throws TException
