cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tylerho...@apache.org
Subject cassandra git commit: Don't check other keyspaces when a UDT is altered
Date Tue, 14 Apr 2015 22:43:17 GMT
Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.1 f1115cfdf -> ca0761404


Don't check other keyspaces when a UDT is altered

Patch by Benjamin Lerer; reviewed by Tyler Hobbs for CASSANDRA-9187


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

Branch: refs/heads/cassandra-2.1
Commit: ca076140472bfde1209423946441f1bd5a35efc1
Parents: f1115cf
Author: blerer <benjamin.lerer@datastax.com>
Authored: Tue Apr 14 17:42:06 2015 -0500
Committer: Tyler Hobbs <tylerlhobbs@gmail.com>
Committed: Tue Apr 14 17:43:06 2015 -0500

----------------------------------------------------------------------
 CHANGES.txt                                     |  2 +
 .../cql3/statements/AlterTypeStatement.java     | 43 +++++++++-----------
 .../apache/cassandra/cql3/UserTypesTest.java    | 40 ++++++++++++++++--
 3 files changed, 59 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/ca076140/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index c3e6c6c..7ebaa89 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,6 @@
 2.1.5
+ * Don't check other keyspaces for schema changes when an user-defined
+   type is altered (CASSANDRA-9187)
  * Allow takeColumnFamilySnapshot to take a list of tables (CASSANDRA-8348)
  * Limit major sstable operations to their canonical representation (CASSANDRA-8669)
  * cqlsh: Add tests for INSERT and UPDATE tab completion (CASSANDRA-9125)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/ca076140/src/java/org/apache/cassandra/cql3/statements/AlterTypeStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/AlterTypeStatement.java b/src/java/org/apache/cassandra/cql3/statements/AlterTypeStatement.java
index 576011f..64e7627 100644
--- a/src/java/org/apache/cassandra/cql3/statements/AlterTypeStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/AlterTypeStatement.java
@@ -106,33 +106,30 @@ public abstract class AlterTypeStatement extends SchemaAlteringStatement
         // but we also need to find all existing user types and CF using it and change them.
         MigrationManager.announceTypeUpdate(updated, isLocalOnly);
 
-        for (KSMetaData ksm2 : Schema.instance.getKeyspaceDefinitions())
+        for (CFMetaData cfm : ksm.cfMetaData().values())
         {
-            for (CFMetaData cfm : ksm2.cfMetaData().values())
-            {
-                CFMetaData copy = cfm.copy();
-                boolean modified = false;
-                for (ColumnDefinition def : copy.allColumns())
-                    modified |= updateDefinition(copy, def, toUpdate.keyspace, toUpdate.name,
updated);
-                if (modified)
-                    MigrationManager.announceColumnFamilyUpdate(copy, false, isLocalOnly);
-            }
+            CFMetaData copy = cfm.copy();
+            boolean modified = false;
+            for (ColumnDefinition def : copy.allColumns())
+                modified |= updateDefinition(copy, def, toUpdate.keyspace, toUpdate.name,
updated);
+            if (modified)
+                MigrationManager.announceColumnFamilyUpdate(copy, false, isLocalOnly);
+        }
 
-            // Other user types potentially using the updated type
-            for (UserType ut : ksm2.userTypes.getAllTypes().values())
+        // Other user types potentially using the updated type
+        for (UserType ut : ksm.userTypes.getAllTypes().values())
+        {
+            // Re-updating the type we've just updated would be harmless but useless so we
avoid it.
+            // Besides, we use the occasion to drop the old version of the type if it's a
type rename
+            if (ut.keyspace.equals(toUpdate.keyspace) && ut.name.equals(toUpdate.name))
             {
-                // Re-updating the type we've just updated would be harmless but useless
so we avoid it.
-                // Besides, we use the occasion to drop the old version of the type if it's
a type rename
-                if (ut.keyspace.equals(toUpdate.keyspace) && ut.name.equals(toUpdate.name))
-                {
-                    if (!ut.keyspace.equals(updated.keyspace) || !ut.name.equals(updated.name))
-                        MigrationManager.announceTypeDrop(ut);
-                    continue;
-                }
-                AbstractType<?> upd = updateWith(ut, toUpdate.keyspace, toUpdate.name,
updated);
-                if (upd != null)
-                    MigrationManager.announceTypeUpdate((UserType)upd, isLocalOnly);
+                if (!ut.keyspace.equals(updated.keyspace) || !ut.name.equals(updated.name))
+                    MigrationManager.announceTypeDrop(ut);
+                continue;
             }
+            AbstractType<?> upd = updateWith(ut, toUpdate.keyspace, toUpdate.name,
updated);
+            if (upd != null)
+                MigrationManager.announceTypeUpdate((UserType) upd, isLocalOnly);
         }
         return true;
     }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/ca076140/test/unit/org/apache/cassandra/cql3/UserTypesTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/UserTypesTest.java b/test/unit/org/apache/cassandra/cql3/UserTypesTest.java
index 184de19..76315cf 100644
--- a/test/unit/org/apache/cassandra/cql3/UserTypesTest.java
+++ b/test/unit/org/apache/cassandra/cql3/UserTypesTest.java
@@ -71,10 +71,44 @@ public class UserTypesTest extends CQLTester
     }
 
     @Test
-    public void testNonFrozenUDT() throws Throwable
+    public void testCreateInvalidTablesWithUDT() throws Throwable
     {
-        // Using a UDT without frozen shouldn't work
         String myType = createType("CREATE TYPE %s (f int)");
-        assertInvalid("CREATE TABLE wrong (k int PRIMARY KEY, v " + myType + ")");
+
+        // Using a UDT without frozen shouldn't work
+        assertInvalidMessage("Non-frozen User-Defined types are not supported, please use
frozen<>",
+                             "CREATE TABLE " + KEYSPACE + ".wrong (k int PRIMARY KEY, v "
+ KEYSPACE + '.' + myType + ")");
+
+        assertInvalidMessage("Statement on keyspace " + KEYSPACE + " cannot refer to a user
type in keyspace otherkeyspace;" +
+                             " user types can only be used in the keyspace they are defined
in",
+                             "CREATE TABLE " + KEYSPACE + ".wrong (k int PRIMARY KEY, v frozen<otherKeyspace.myType>)");
+
+        assertInvalidMessage("Unknown type " + KEYSPACE + ".unknowntype",
+                             "CREATE TABLE " + KEYSPACE + ".wrong (k int PRIMARY KEY, v frozen<"
+ KEYSPACE + '.' + "unknownType>)");
+    }
+
+    @Test
+    public void testAlterUDT() throws Throwable
+    {
+        String myType = KEYSPACE + '.' + createType("CREATE TYPE %s (a int)");
+        createTable("CREATE TABLE %s (a int PRIMARY KEY, b frozen<" + myType + ">)");
+        execute("INSERT INTO %s (a, b) VALUES (1, {a: 1})");
+
+        assertRows(execute("SELECT b.a FROM %s"), row(1));
+
+        flush();
+
+        execute("ALTER TYPE " + myType + " ADD b int");
+        execute("INSERT INTO %s (a, b) VALUES (2, {a: 2, b :2})");
+
+        assertRows(execute("SELECT b.a, b.b FROM %s"),
+                   row(1, null),
+                   row(2, 2));
+
+        flush();
+
+        assertRows(execute("SELECT b.a, b.b FROM %s"),
+                   row(1, null),
+                   row(2, 2));
     }
 }


Mime
View raw message