cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slebre...@apache.org
Subject [1/2] git commit: Fix mixing prepared statements between keyspaces
Date Mon, 18 Mar 2013 08:29:01 GMT
Fix mixing prepared statements between keyspaces

patch by David Sauer; reviewed by slebresne for CASSANDRA-5352


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/28be3837
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/28be3837
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/28be3837

Branch: refs/heads/trunk
Commit: 28be383769448520e80fa9df067f09b044f4c819
Parents: c67e501
Author: Sylvain Lebresne <sylvain@datastax.com>
Authored: Mon Mar 18 09:27:17 2013 +0100
Committer: Sylvain Lebresne <sylvain@datastax.com>
Committed: Mon Mar 18 09:27:17 2013 +0100

----------------------------------------------------------------------
 CHANGES.txt                                        |    3 +++
 .../org/apache/cassandra/cql3/QueryProcessor.java  |   11 +++++++----
 2 files changed, 10 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/28be3837/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 8e4e15b..b3fbf9b 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,3 +1,6 @@
+1.2.4
+ * Fix mixing prepared statements between keyspaces (CASSANDRA-5352)
+
 1.2.3
  * add check for sstable overlap within a level on startup (CASSANDRA-5327)
  * replace ipv6 colons in jmx object names (CASSANDRA-5298, 5328)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/28be3837/src/java/org/apache/cassandra/cql3/QueryProcessor.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/QueryProcessor.java b/src/java/org/apache/cassandra/cql3/QueryProcessor.java
index b612ceb..7dcd467 100644
--- a/src/java/org/apache/cassandra/cql3/QueryProcessor.java
+++ b/src/java/org/apache/cassandra/cql3/QueryProcessor.java
@@ -205,17 +205,20 @@ public class QueryProcessor
         logger.trace("CQL QUERY: {}", queryString);
 
         ParsedStatement.Prepared prepared = getStatement(queryString, clientState);
-        ResultMessage.Prepared msg = storePreparedStatement(queryString, prepared, forThrift);
+        ResultMessage.Prepared msg = storePreparedStatement(queryString, clientState.getKeyspace(),
prepared, forThrift);
 
         assert prepared.statement.getBoundsTerms() == prepared.boundNames.size();
         return msg;
     }
 
-    private static ResultMessage.Prepared storePreparedStatement(String queryString, ParsedStatement.Prepared
prepared, boolean forThrift)
+    private static ResultMessage.Prepared storePreparedStatement(String queryString, String
keyspace, ParsedStatement.Prepared prepared, boolean forThrift)
     {
+        // Concatenate the current keyspace so we don't mix prepared statements between keyspace
(#5352).
+        // (if the keyspace is null, queryString has to have a fully-qualified keyspace so
it's fine.
+        String toHash = keyspace == null ? queryString : keyspace + queryString;
         if (forThrift)
         {
-            int statementId = queryString.hashCode();
+            int statementId = toHash.hashCode();
             thriftPreparedStatements.put(statementId, prepared.statement);
             logger.trace(String.format("Stored prepared statement #%d with %d bind markers",
                                        statementId,
@@ -224,7 +227,7 @@ public class QueryProcessor
         }
         else
         {
-            MD5Digest statementId = MD5Digest.compute(queryString);
+            MD5Digest statementId = MD5Digest.compute(toHash);
             logger.trace(String.format("Stored prepared statement %s with %d bind markers",
                                        statementId,
                                        prepared.statement.getBoundsTerms()));


Mime
View raw message