Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.1.0 a41d5270f -> a0923dbc0


Don't send schema change msg for no-op DDL stmts

Patch by Tyler Hobbs; review by Mikhail Stepura for CASSANDRA-7600


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

Branch: refs/heads/cassandra-2.1.0
Commit: e4d5edae72838533445efadc001d2b6b656fd0ce
Parents: fe39eb7
Author: Tyler Hobbs <ty...@datastax.com>
Authored: Thu Aug 21 14:18:40 2014 -0500
Committer: Tyler Hobbs <ty...@datastax.com>
Committed: Thu Aug 21 14:20:15 2014 -0500

----------------------------------------------------------------------
 CHANGES.txt                                          |  2 ++
 .../cql3/statements/AlterKeyspaceStatement.java      |  3 ++-
 .../cql3/statements/AlterTableStatement.java         |  3 ++-
 .../cql3/statements/CreateIndexStatement.java        |  5 +++--
 .../cql3/statements/CreateKeyspaceStatement.java     |  8 +++++---
 .../cql3/statements/CreateTableStatement.java        | 10 ++++++----
 .../cql3/statements/CreateTriggerStatement.java      |  3 ++-
 .../cql3/statements/DropIndexStatement.java          |  5 +++--
 .../cql3/statements/DropKeyspaceStatement.java       |  8 +++++---
 .../cql3/statements/DropTableStatement.java          |  8 +++++---
 .../cql3/statements/DropTriggerStatement.java        |  3 ++-
 .../cql3/statements/SchemaAlteringStatement.java     | 15 +++++++++++++--
 12 files changed, 50 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/e4d5edae/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 71cfca0..9aeeb29 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,6 @@
 2.0.10
+ * Don't send schema change responses and events for no-op DDL
+   statements (CASSANDRA-7600)
  * (Hadoop) fix cluster initialisation for a split fetching (CASSANDRA-7774)
  * Configure system.paxos with LeveledCompactionStrategy (CASSANDRA-7753)
  * Fix ALTER clustering column type from DateType to TimestampType when

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e4d5edae/src/java/org/apache/cassandra/cql3/statements/AlterKeyspaceStatement.java
----------------------------------------------------------------------
diff --git 
a/src/java/org/apache/cassandra/cql3/statements/AlterKeyspaceStatement.java 
b/src/java/org/apache/cassandra/cql3/statements/AlterKeyspaceStatement.java
index 39d1cde..4f6d1f2 100644
--- a/src/java/org/apache/cassandra/cql3/statements/AlterKeyspaceStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/AlterKeyspaceStatement.java
@@ -79,7 +79,7 @@ public class AlterKeyspaceStatement extends 
SchemaAlteringStatement
         }
     }
 
-    public void announceMigration() throws RequestValidationException
+    public boolean announceMigration() throws RequestValidationException
     {
         KSMetaData ksm = Schema.instance.getKSMetaData(name);
         // In the (very) unlikely case the keyspace was dropped since 
validate()
@@ -87,6 +87,7 @@ public class AlterKeyspaceStatement extends 
SchemaAlteringStatement
             throw new InvalidRequestException("Unknown keyspace " + name);
 
         MigrationManager.announceKeyspaceUpdate(attrs.asKSMetadataUpdate(ksm));
+        return true;
     }
 
     public ResultMessage.SchemaChange.Change changeType()

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e4d5edae/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
----------------------------------------------------------------------
diff --git 
a/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java 
b/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
index 136c430..dfcd601 100644
--- a/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
@@ -76,7 +76,7 @@ public class AlterTableStatement extends 
SchemaAlteringStatement
         // validated in announceMigration()
     }
 
-    public void announceMigration() throws RequestValidationException
+    public boolean announceMigration() throws RequestValidationException
     {
         CFMetaData meta = validateColumnFamily(keyspace(), columnFamily());
         CFMetaData cfm = meta.clone();
@@ -266,6 +266,7 @@ public class AlterTableStatement extends 
SchemaAlteringStatement
         }
 
         MigrationManager.announceColumnFamilyUpdate(cfm, false);
+        return true;
     }
 
     public String toString()

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e4d5edae/src/java/org/apache/cassandra/cql3/statements/CreateIndexStatement.java
----------------------------------------------------------------------
diff --git 
a/src/java/org/apache/cassandra/cql3/statements/CreateIndexStatement.java 
b/src/java/org/apache/cassandra/cql3/statements/CreateIndexStatement.java
index 376fa4a..8b40978 100644
--- a/src/java/org/apache/cassandra/cql3/statements/CreateIndexStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/CreateIndexStatement.java
@@ -103,14 +103,14 @@ public class CreateIndexStatement extends 
SchemaAlteringStatement
             throw new InvalidRequestException(String.format("Cannot add 
secondary index to already primarily indexed column %s", columnName));
     }
 
-    public void announceMigration() throws RequestValidationException
+    public boolean announceMigration() throws RequestValidationException
     {
         logger.debug("Updating column {} definition for index {}", columnName, 
indexName);
         CFMetaData cfm = Schema.instance.getCFMetaData(keyspace(), 
columnFamily()).clone();
         ColumnDefinition cd = cfm.getColumnDefinition(columnName.key);
 
         if (cd.getIndexType() != null && ifNotExists)
-            return;
+            return false;
 
         if (properties.isCustom)
             cd.setIndexType(IndexType.CUSTOM, properties.getOptions());
@@ -122,6 +122,7 @@ public class CreateIndexStatement extends 
SchemaAlteringStatement
         cd.setIndexName(indexName);
         cfm.addDefaultIndexNames();
         MigrationManager.announceColumnFamilyUpdate(cfm, false);
+        return true;
     }
 
     public ResultMessage.SchemaChange.Change changeType()

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e4d5edae/src/java/org/apache/cassandra/cql3/statements/CreateKeyspaceStatement.java
----------------------------------------------------------------------
diff --git 
a/src/java/org/apache/cassandra/cql3/statements/CreateKeyspaceStatement.java 
b/src/java/org/apache/cassandra/cql3/statements/CreateKeyspaceStatement.java
index 2ed1d91..7a8473a 100644
--- a/src/java/org/apache/cassandra/cql3/statements/CreateKeyspaceStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/CreateKeyspaceStatement.java
@@ -97,16 +97,18 @@ public class CreateKeyspaceStatement extends 
SchemaAlteringStatement
                                                                 
attrs.getReplicationOptions());
     }
 
-    public void announceMigration() throws RequestValidationException
+    public boolean announceMigration() throws RequestValidationException
     {
         try
         {
             MigrationManager.announceNewKeyspace(attrs.asKSMetadata(name));
+            return true;
         }
         catch (AlreadyExistsException e)
         {
-            if (!ifNotExists)
-                throw e;
+            if (ifNotExists)
+                return false;
+            throw e;
         }
     }
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e4d5edae/src/java/org/apache/cassandra/cql3/statements/CreateTableStatement.java
----------------------------------------------------------------------
diff --git 
a/src/java/org/apache/cassandra/cql3/statements/CreateTableStatement.java 
b/src/java/org/apache/cassandra/cql3/statements/CreateTableStatement.java
index 08ad069..b7f43d3 100644
--- a/src/java/org/apache/cassandra/cql3/statements/CreateTableStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/CreateTableStatement.java
@@ -114,16 +114,18 @@ public class CreateTableStatement extends 
SchemaAlteringStatement
         return columnDefs;
     }
 
-    public void announceMigration() throws RequestValidationException
+    public boolean announceMigration() throws RequestValidationException
     {
         try
         {
-           MigrationManager.announceNewColumnFamily(getCFMetaData());
+            MigrationManager.announceNewColumnFamily(getCFMetaData());
+            return true;
         }
         catch (AlreadyExistsException e)
         {
-            if (!ifNotExists)
-                throw e;
+            if (ifNotExists)
+                return false;
+            throw e;
         }
     }
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e4d5edae/src/java/org/apache/cassandra/cql3/statements/CreateTriggerStatement.java
----------------------------------------------------------------------
diff --git 
a/src/java/org/apache/cassandra/cql3/statements/CreateTriggerStatement.java 
b/src/java/org/apache/cassandra/cql3/statements/CreateTriggerStatement.java
index 760d870..70b3acb 100644
--- a/src/java/org/apache/cassandra/cql3/statements/CreateTriggerStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/CreateTriggerStatement.java
@@ -65,12 +65,13 @@ public class CreateTriggerStatement extends 
SchemaAlteringStatement
         }
     }
 
-    public void announceMigration() throws ConfigurationException
+    public boolean announceMigration() throws ConfigurationException
     {
         CFMetaData cfm = Schema.instance.getCFMetaData(keyspace(), 
columnFamily()).clone();
         cfm.addTriggerDefinition(TriggerDefinition.create(triggerName, 
triggerClass));
         logger.info("Adding trigger with name {} and class {}", triggerName, 
triggerClass);
         MigrationManager.announceColumnFamilyUpdate(cfm, false);
+        return true;
     }
 
     public ResultMessage.SchemaChange.Change changeType()

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e4d5edae/src/java/org/apache/cassandra/cql3/statements/DropIndexStatement.java
----------------------------------------------------------------------
diff --git 
a/src/java/org/apache/cassandra/cql3/statements/DropIndexStatement.java 
b/src/java/org/apache/cassandra/cql3/statements/DropIndexStatement.java
index c62ad47..ac5262e 100644
--- a/src/java/org/apache/cassandra/cql3/statements/DropIndexStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/DropIndexStatement.java
@@ -60,14 +60,15 @@ public class DropIndexStatement extends 
SchemaAlteringStatement
         return ResultMessage.SchemaChange.Change.UPDATED;
     }
 
-    public void announceMigration() throws InvalidRequestException, 
ConfigurationException
+    public boolean announceMigration() throws InvalidRequestException, 
ConfigurationException
     {
         CFMetaData cfm = findIndexedCF();
         if (cfm == null)
-            return;
+            return false;
 
         CFMetaData updatedCfm = updateCFMetadata(cfm);
         MigrationManager.announceColumnFamilyUpdate(updatedCfm, false);
+        return true;
     }
 
     private CFMetaData updateCFMetadata(CFMetaData cfm)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e4d5edae/src/java/org/apache/cassandra/cql3/statements/DropKeyspaceStatement.java
----------------------------------------------------------------------
diff --git 
a/src/java/org/apache/cassandra/cql3/statements/DropKeyspaceStatement.java 
b/src/java/org/apache/cassandra/cql3/statements/DropKeyspaceStatement.java
index 30fd964..7582af0 100644
--- a/src/java/org/apache/cassandra/cql3/statements/DropKeyspaceStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/DropKeyspaceStatement.java
@@ -55,16 +55,18 @@ public class DropKeyspaceStatement extends 
SchemaAlteringStatement
         return keyspace;
     }
 
-    public void announceMigration() throws ConfigurationException
+    public boolean announceMigration() throws ConfigurationException
     {
         try
         {
             MigrationManager.announceKeyspaceDrop(keyspace);
+            return true;
         }
         catch(ConfigurationException e)
         {
-            if (!ifExists)
-                throw e;
+            if (ifExists)
+                return false;
+            throw e;
         }
     }
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e4d5edae/src/java/org/apache/cassandra/cql3/statements/DropTableStatement.java
----------------------------------------------------------------------
diff --git 
a/src/java/org/apache/cassandra/cql3/statements/DropTableStatement.java 
b/src/java/org/apache/cassandra/cql3/statements/DropTableStatement.java
index d27261c..65a3f14 100644
--- a/src/java/org/apache/cassandra/cql3/statements/DropTableStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/DropTableStatement.java
@@ -54,16 +54,18 @@ public class DropTableStatement extends 
SchemaAlteringStatement
         // validated in announceMigration()
     }
 
-    public void announceMigration() throws ConfigurationException
+    public boolean announceMigration() throws ConfigurationException
     {
         try
         {
             MigrationManager.announceColumnFamilyDrop(keyspace(), 
columnFamily());
+            return true;
         }
         catch (ConfigurationException e)
         {
-            if (!ifExists)
-                throw e;
+            if (ifExists)
+                return false;
+            throw e;
         }
     }
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e4d5edae/src/java/org/apache/cassandra/cql3/statements/DropTriggerStatement.java
----------------------------------------------------------------------
diff --git 
a/src/java/org/apache/cassandra/cql3/statements/DropTriggerStatement.java 
b/src/java/org/apache/cassandra/cql3/statements/DropTriggerStatement.java
index ce17047..f0bd637 100644
--- a/src/java/org/apache/cassandra/cql3/statements/DropTriggerStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/DropTriggerStatement.java
@@ -53,13 +53,14 @@ public class DropTriggerStatement extends 
SchemaAlteringStatement
         ThriftValidation.validateColumnFamily(keyspace(), columnFamily());
     }
 
-    public void announceMigration() throws ConfigurationException
+    public boolean announceMigration() throws ConfigurationException
     {
         CFMetaData cfm = Schema.instance.getCFMetaData(keyspace(), 
columnFamily()).clone();
         if (!cfm.removeTrigger(triggerName))
             throw new ConfigurationException(String.format("Trigger %s was not 
found", triggerName));
         logger.info("Dropping trigger with name {}", triggerName);
         MigrationManager.announceColumnFamilyUpdate(cfm, false);
+        return true;
     }
 
     public ResultMessage.SchemaChange.Change changeType()

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e4d5edae/src/java/org/apache/cassandra/cql3/statements/SchemaAlteringStatement.java
----------------------------------------------------------------------
diff --git 
a/src/java/org/apache/cassandra/cql3/statements/SchemaAlteringStatement.java 
b/src/java/org/apache/cassandra/cql3/statements/SchemaAlteringStatement.java
index 94df854..845d8cc 100644
--- a/src/java/org/apache/cassandra/cql3/statements/SchemaAlteringStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/SchemaAlteringStatement.java
@@ -64,11 +64,22 @@ public abstract class SchemaAlteringStatement extends 
CFStatement implements CQL
 
     public abstract ResultMessage.SchemaChange.Change changeType();
 
-    public abstract void announceMigration() throws RequestValidationException;
+    /**
+     * Announces the migration to other nodes in the cluster.
+     * @return true if the execution of this statement resulted in a schema 
change, false otherwise (when IF NOT EXISTS
+     * is used, for example)
+     * @throws RequestValidationException
+     */
+    public abstract boolean announceMigration() throws 
RequestValidationException;
 
     public ResultMessage execute(QueryState state, QueryOptions options) 
throws RequestValidationException
     {
-        announceMigration();
+        // If an IF [NOT] EXISTS clause was used, this may not result in an 
actual schema change.  To avoid doing
+        // extra work in the drivers to handle schema changes, we return an 
empty message in this case. (CASSANDRA-7600)
+        boolean didChangeSchema = announceMigration();
+        if (!didChangeSchema)
+            return new ResultMessage.Void();
+
         String tableName = cfName == null || columnFamily() == null ? "" : 
columnFamily();
         return new ResultMessage.SchemaChange(changeType(), keyspace(), 
tableName);
     }

Reply via email to