cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alek...@apache.org
Subject [1/3] cassandra git commit: Check for hash conflicts in prepared statements.
Date Tue, 11 Oct 2016 13:34:44 GMT
Repository: cassandra
Updated Branches:
  refs/heads/cassandra-3.X 830954304 -> c7fb95c98
  refs/heads/trunk dffe27077 -> 231a93706


Check for hash conflicts in prepared statements.

Patch by Jeremiah Jordan; reviewed by Alex Petrov for CASSANDRA-12733


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

Branch: refs/heads/cassandra-3.X
Commit: c7fb95c98d2c370fcdb8e0389528ce6668f3a58c
Parents: 8309543
Author: Jeremiah D Jordan <jeremiah@datastax.com>
Authored: Thu Sep 29 13:55:17 2016 -0500
Committer: Aleksey Yeschenko <aleksey@apache.org>
Committed: Tue Oct 11 14:33:05 2016 +0100

----------------------------------------------------------------------
 CHANGES.txt                                         |  1 +
 .../org/apache/cassandra/cql3/QueryProcessor.java   | 16 ++++++++++++++--
 2 files changed, 15 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/c7fb95c9/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 2f517e0..5907c74 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 3.10
+ * Check for hash conflicts in prepared statements (CASSANDRA-12733)
  * Exit query parsing upon first error (CASSANDRA-12598)
  * Fix cassandra-stress to use single seed in UUID generation (CASSANDRA-12729)
  * CQLSSTableWriter does not allow Update statement (CASSANDRA-12450)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/c7fb95c9/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 5313a1a..1d5a024 100644
--- a/src/java/org/apache/cassandra/cql3/QueryProcessor.java
+++ b/src/java/org/apache/cassandra/cql3/QueryProcessor.java
@@ -57,6 +57,8 @@ import org.apache.cassandra.transport.Server;
 import org.apache.cassandra.transport.messages.ResultMessage;
 import org.apache.cassandra.utils.*;
 
+import static org.apache.cassandra.cql3.statements.RequestValidations.checkTrue;
+
 public class QueryProcessor implements QueryHandler
 {
     public static final CassandraVersion CQL_VERSION = new CassandraVersion("3.4.3");
@@ -437,13 +439,23 @@ public class QueryProcessor implements QueryHandler
         {
             Integer thriftStatementId = computeThriftId(queryString, keyspace);
             ParsedStatement.Prepared existing = thriftPreparedStatements.get(thriftStatementId);
-            return existing == null ? null : ResultMessage.Prepared.forThrift(thriftStatementId,
existing.boundNames);
+            if (existing == null)
+                return null;
+
+            checkTrue(queryString.equals(existing.rawCQLStatement),
+                      String.format("MD5 hash collision: query with the same MD5 hash was
already prepared. \n Existing: '%s'", existing.rawCQLStatement));
+            return ResultMessage.Prepared.forThrift(thriftStatementId, existing.boundNames);
         }
         else
         {
             MD5Digest statementId = computeId(queryString, keyspace);
             ParsedStatement.Prepared existing = preparedStatements.get(statementId);
-            return existing == null ? null : new ResultMessage.Prepared(statementId, existing);
+            if (existing == null)
+                return null;
+
+            checkTrue(queryString.equals(existing.rawCQLStatement),
+                      String.format("MD5 hash collision: query with the same MD5 hash was
already prepared. \n Existing: '%s'", existing.rawCQLStatement));
+            return new ResultMessage.Prepared(statementId, existing);
         }
     }
 


Mime
View raw message