You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by ty...@apache.org on 2015/01/21 00:48:56 UTC
cassandra git commit: Invalidate prepared batch stmts when tables are
dropped
Repository: cassandra
Updated Branches:
refs/heads/cassandra-2.1 e2d140fff -> caa4f3d34
Invalidate prepared batch stmts when tables are dropped
Patch by Edward Ribeiro; reviewed by Tyler Hobbs for CASSANDRA-8652
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/caa4f3d3
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/caa4f3d3
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/caa4f3d3
Branch: refs/heads/cassandra-2.1
Commit: caa4f3d34aea9016fe66059c39bea378b9ee4373
Parents: e2d140f
Author: Edward Ribeiro <ed...@gmail.com>
Authored: Tue Jan 20 17:47:58 2015 -0600
Committer: Tyler Hobbs <ty...@datastax.com>
Committed: Tue Jan 20 17:47:58 2015 -0600
----------------------------------------------------------------------
CHANGES.txt | 2 ++
.../org/apache/cassandra/cql3/QueryProcessor.java | 10 ++++++++++
.../cassandra/cql3/PreparedStatementsTest.java | 18 +++++++++++++-----
3 files changed, 25 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/caa4f3d3/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 1b14c62..296aa66 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,6 @@
2.1.3
+ * Invalidate prepared BATCH statements when related tables
+ or keyspaces are dropped (CASSANDRA-8652)
* Fix missing results in secondary index queries on collections
with ALLOW FILTERING (CASSANDRA-8421)
* Expose EstimatedHistogram metrics for range slices (CASSANDRA-8627)
http://git-wip-us.apache.org/repos/asf/cassandra/blob/caa4f3d3/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 3aee799..e6e6f7d 100644
--- a/src/java/org/apache/cassandra/cql3/QueryProcessor.java
+++ b/src/java/org/apache/cassandra/cql3/QueryProcessor.java
@@ -593,6 +593,16 @@ public class QueryProcessor implements QueryHandler
statementKsName = selectStatement.keyspace();
statementCfName = selectStatement.columnFamily();
}
+ else if (statement instanceof BatchStatement)
+ {
+ BatchStatement batchStatement = ((BatchStatement) statement);
+ for (ModificationStatement stmt : batchStatement.getStatements())
+ {
+ if (shouldInvalidate(ksName, cfName, stmt))
+ return true;
+ }
+ return false;
+ }
else
{
return false;
http://git-wip-us.apache.org/repos/asf/cassandra/blob/caa4f3d3/test/unit/org/apache/cassandra/cql3/PreparedStatementsTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/PreparedStatementsTest.java b/test/unit/org/apache/cassandra/cql3/PreparedStatementsTest.java
index f65ec18..b5a28df 100644
--- a/test/unit/org/apache/cassandra/cql3/PreparedStatementsTest.java
+++ b/test/unit/org/apache/cassandra/cql3/PreparedStatementsTest.java
@@ -53,14 +53,14 @@ public class PreparedStatementsTest extends SchemaLoader
// to wait slightly before trying to connect to it. We should fix this but in the meantime using a sleep.
Thread.sleep(500);
- cluster = Cluster.builder().addContactPoint("127.0.0.1")
+ cluster = Cluster.builder().addContactPoint("127.0.0.1")
.withPort(DatabaseDescriptor.getNativeTransportPort())
.build();
session = cluster.connect();
session.execute(dropKsStatement);
session.execute(createKsStatement);
- }
+ }
@AfterClass
public static void tearDown() throws Exception
@@ -75,19 +75,27 @@ public class PreparedStatementsTest extends SchemaLoader
String dropTableStatement = "DROP TABLE IF EXISTS " + KEYSPACE + ".qp_cleanup;";
session.execute(createTableStatement);
+
PreparedStatement prepared = session.prepare("INSERT INTO " + KEYSPACE + ".qp_cleanup (id, cid, val) VALUES (?, ?, ?)");
+ PreparedStatement preparedBatch = session.prepare("BEGIN BATCH " +
+ "INSERT INTO " + KEYSPACE + ".qp_cleanup (id, cid, val) VALUES (?, ?, ?);" +
+ "APPLY BATCH;");
session.execute(dropTableStatement);
session.execute(createTableStatement);
session.execute(prepared.bind(1, 1, "value"));
+ session.execute(preparedBatch.bind(2, 2, "value2"));
session.execute(dropKsStatement);
session.execute(createKsStatement);
session.execute(createTableStatement);
+
+ // The driver will get a response about the prepared statement being invalid, causing it to transparently
+ // re-prepare the statement. We'll rely on the fact that we get no errors while executing this to show that
+ // the statements have been invalidated.
session.execute(prepared.bind(1, 1, "value"));
+ session.execute(preparedBatch.bind(2, 2, "value2"));
session.execute(dropKsStatement);
-
- // FIXME: where is invalidation actually tested?
- }
+ }
@Test
public void testStatementRePreparationOnReconnect()