cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tylerho...@apache.org
Subject [1/3] cassandra git commit: Freeze UDTs and nested UDTs/collections during schema upgrade
Date Wed, 18 May 2016 20:18:26 GMT
Repository: cassandra
Updated Branches:
  refs/heads/trunk 0f483d8ff -> 5bdf3184b


Freeze UDTs and nested UDTs/collections during schema upgrade

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


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

Branch: refs/heads/trunk
Commit: dee84ccc59bc5ce76e568bf94ab70c772c079041
Parents: c17cbe1
Author: Tyler Hobbs <tylerlhobbs@gmail.com>
Authored: Wed May 18 15:15:35 2016 -0500
Committer: Tyler Hobbs <tylerlhobbs@gmail.com>
Committed: Wed May 18 15:15:35 2016 -0500

----------------------------------------------------------------------
 CHANGES.txt                                            |  2 ++
 .../org/apache/cassandra/db/marshal/AbstractType.java  |  8 ++++----
 src/java/org/apache/cassandra/db/marshal/ListType.java | 11 +++++++----
 src/java/org/apache/cassandra/db/marshal/MapType.java  | 13 ++++++++-----
 src/java/org/apache/cassandra/db/marshal/SetType.java  | 11 +++++++----
 src/java/org/apache/cassandra/db/marshal/UserType.java |  5 ++++-
 .../apache/cassandra/schema/LegacySchemaMigrator.java  |  9 ++++++---
 7 files changed, 38 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/dee84ccc/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 1690e09..a2b472a 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,6 @@
 3.6
+ * Correctly migrate schema for frozen UDTs during 2.x -> 3.x upgrades
+   (does not affect any released versions) (CASSANDRA-11613)
  * Allow server startup if JMX is configured directly (CASSANDRA-11725)
  * Prevent direct memory OOM on buffer pool allocations (CASSANDRA-11710)
  * Enhanced Compaction Logging (CASSANDRA-10805)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/dee84ccc/src/java/org/apache/cassandra/db/marshal/AbstractType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/AbstractType.java b/src/java/org/apache/cassandra/db/marshal/AbstractType.java
index fc4ec3b..af2cc07 100644
--- a/src/java/org/apache/cassandra/db/marshal/AbstractType.java
+++ b/src/java/org/apache/cassandra/db/marshal/AbstractType.java
@@ -333,14 +333,14 @@ public abstract class AbstractType<T> implements Comparator<ByteBuffer>
     }
 
     /**
-     * Returns an AbstractType instance that is equivalent to this one, but with all nested
UDTs explicitly frozen and
-     * all collections in UDTs explicitly frozen.
+     * Returns an AbstractType instance that is equivalent to this one, but with all nested
UDTs and collections
+     * explicitly frozen.
      *
      * This is only necessary for {@code 2.x -> 3.x} schema migrations, and can be removed
in Cassandra 4.0.
      *
-     * See CASSANDRA-11609
+     * See CASSANDRA-11609 and CASSANDRA-11613.
      */
-    public AbstractType<?> freezeNestedUDTs()
+    public AbstractType<?> freezeNestedMulticellTypes()
     {
         return this;
     }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/dee84ccc/src/java/org/apache/cassandra/db/marshal/ListType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/ListType.java b/src/java/org/apache/cassandra/db/marshal/ListType.java
index b3fc4f5..ed843b1 100644
--- a/src/java/org/apache/cassandra/db/marshal/ListType.java
+++ b/src/java/org/apache/cassandra/db/marshal/ListType.java
@@ -110,12 +110,15 @@ public class ListType<T> extends CollectionType<List<T>>
     }
 
     @Override
-    public AbstractType<?> freezeNestedUDTs()
+    public AbstractType<?> freezeNestedMulticellTypes()
     {
-        if (elements.isUDT() && elements.isMultiCell())
+        if (!isMultiCell())
+            return this;
+
+        if (elements.isFreezable() && elements.isMultiCell())
             return getInstance(elements.freeze(), isMultiCell);
-        else
-            return getInstance(elements.freezeNestedUDTs(), isMultiCell);
+
+        return getInstance(elements.freezeNestedMulticellTypes(), isMultiCell);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cassandra/blob/dee84ccc/src/java/org/apache/cassandra/db/marshal/MapType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/MapType.java b/src/java/org/apache/cassandra/db/marshal/MapType.java
index 3c5af99..d5cf959 100644
--- a/src/java/org/apache/cassandra/db/marshal/MapType.java
+++ b/src/java/org/apache/cassandra/db/marshal/MapType.java
@@ -117,15 +117,18 @@ public class MapType<K, V> extends CollectionType<Map<K,
V>>
     }
 
     @Override
-    public AbstractType<?> freezeNestedUDTs()
+    public AbstractType<?> freezeNestedMulticellTypes()
     {
-        AbstractType<?> keyType = (keys.isUDT() && keys.isMultiCell())
+        if (!isMultiCell())
+            return this;
+
+        AbstractType<?> keyType = (keys.isFreezable() && keys.isMultiCell())
                                 ? keys.freeze()
-                                : keys.freezeNestedUDTs();
+                                : keys.freezeNestedMulticellTypes();
 
-        AbstractType<?> valueType = (values.isUDT() && values.isMultiCell())
+        AbstractType<?> valueType = (values.isFreezable() && values.isMultiCell())
                                   ? values.freeze()
-                                  : values.freezeNestedUDTs();
+                                  : values.freezeNestedMulticellTypes();
 
         return getInstance(keyType, valueType, isMultiCell);
     }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/dee84ccc/src/java/org/apache/cassandra/db/marshal/SetType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/SetType.java b/src/java/org/apache/cassandra/db/marshal/SetType.java
index 46c0741..98f9f7e 100644
--- a/src/java/org/apache/cassandra/db/marshal/SetType.java
+++ b/src/java/org/apache/cassandra/db/marshal/SetType.java
@@ -105,12 +105,15 @@ public class SetType<T> extends CollectionType<Set<T>>
     }
 
     @Override
-    public AbstractType<?> freezeNestedUDTs()
+    public AbstractType<?> freezeNestedMulticellTypes()
     {
-        if (elements.isUDT() && elements.isMultiCell())
+        if (!isMultiCell())
+            return this;
+
+        if (elements.isFreezable() && elements.isMultiCell())
             return getInstance(elements.freeze(), isMultiCell);
-        else
-            return getInstance(elements.freezeNestedUDTs(), isMultiCell);
+
+        return getInstance(elements.freezeNestedMulticellTypes(), isMultiCell);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cassandra/blob/dee84ccc/src/java/org/apache/cassandra/db/marshal/UserType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/UserType.java b/src/java/org/apache/cassandra/db/marshal/UserType.java
index 433cb87..d2cf94b 100644
--- a/src/java/org/apache/cassandra/db/marshal/UserType.java
+++ b/src/java/org/apache/cassandra/db/marshal/UserType.java
@@ -304,8 +304,11 @@ public class UserType extends TupleType
     }
 
     @Override
-    public AbstractType<?> freezeNestedUDTs()
+    public AbstractType<?> freezeNestedMulticellTypes()
     {
+        if (!isMultiCell())
+            return this;
+
         // the behavior here doesn't exactly match the method name: we want to freeze everything
inside of UDTs
         List<AbstractType<?>> newTypes = fieldTypes().stream()
                 .map(subtype -> (subtype.isFreezable() && subtype.isMultiCell()
? subtype.freeze() : subtype))

http://git-wip-us.apache.org/repos/asf/cassandra/blob/dee84ccc/src/java/org/apache/cassandra/schema/LegacySchemaMigrator.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/schema/LegacySchemaMigrator.java b/src/java/org/apache/cassandra/schema/LegacySchemaMigrator.java
index ebe8006..abc3601 100644
--- a/src/java/org/apache/cassandra/schema/LegacySchemaMigrator.java
+++ b/src/java/org/apache/cassandra/schema/LegacySchemaMigrator.java
@@ -684,9 +684,12 @@ public final class LegacySchemaMigrator
         AbstractType<?> validator = parseType(row.getString("validator"));
 
         // In the 2.x schema we didn't store UDT's with a FrozenType wrapper because they
were implicitly frozen.  After
-        // CASSANDRA-7423 (non-frozen UDTs), this is no longer true, so we need to freeze
nested UDTs to properly
-        // migrate the schema.  See CASSANDRA-11609.
-        validator = validator.freezeNestedUDTs();
+        // CASSANDRA-7423 (non-frozen UDTs), this is no longer true, so we need to freeze
UDTs and nested freezable
+        // types (UDTs and collections) to properly migrate the schema.  See CASSANDRA-11609
and CASSANDRA-11613.
+        if (validator.isUDT() && validator.isMultiCell())
+            validator = validator.freeze();
+        else
+            validator = validator.freezeNestedMulticellTypes();
 
         return new ColumnDefinition(keyspace, table, name, validator, componentIndex, kind);
     }


Mime
View raw message