You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by sl...@apache.org on 2012/09/07 11:58:50 UTC

git commit: Fix update of CF comparator

Updated Branches:
  refs/heads/trunk f199fa39b -> ceca1997d


Fix update of CF comparator

patch by slebresne; reviewed by jbellis for CASSANDRA-4493


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

Branch: refs/heads/trunk
Commit: ceca1997d045c8f09b198e73a956bfaddc11485a
Parents: f199fa3
Author: Sylvain Lebresne <sy...@datastax.com>
Authored: Fri Sep 7 11:58:02 2012 +0200
Committer: Sylvain Lebresne <sy...@datastax.com>
Committed: Fri Sep 7 11:58:02 2012 +0200

----------------------------------------------------------------------
 CHANGES.txt                                        |    1 +
 .../cql3/statements/AlterTableStatement.java       |    8 +++++-
 .../org/apache/cassandra/db/ColumnFamilyStore.java |   17 +++++++++++++++
 3 files changed, 24 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/ceca1997/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 0905cf9..8245343 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -51,6 +51,7 @@
  * add Murmur3Partitioner and make it default for new installations (CASSANDRA-3772)
  * (cql3) update pseudo-map syntax to use map syntax (CASSANDRA-4497)
  * Finer grained exceptions hierarchy and provides error code with exceptions (CASSANDRA-3979)
+ * Adds events push to binary protocol (CASSANDRA-4480)
 
 
 1.1.6

http://git-wip-us.apache.org/repos/asf/cassandra/blob/ceca1997/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 3204e81..4e35adb 100644
--- a/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
@@ -77,15 +77,19 @@ public class AlterTableStatement extends SchemaAlteringStatement
                     }
                 }
 
+                Integer componentIndex = cfDef.isComposite ? ((CompositeType)meta.comparator).types.size() - 1 : null;
                 AbstractType<?> type = validator.getType();
                 if (type instanceof CollectionType)
                 {
                     if (!cfDef.isComposite)
                         throw new InvalidRequestException("Cannot use collection types with non-composite PRIMARY KEY");
 
+                    componentIndex--;
+
                     Map<ByteBuffer, CollectionType> collections = cfDef.hasCollections
                                                                 ? new HashMap<ByteBuffer, CollectionType>(cfDef.getCollectionType().defined)
                                                                 : new HashMap<ByteBuffer, CollectionType>();
+                    collections.put(columnName.key, (CollectionType)type);
                     ColumnToCollectionType newColType = ColumnToCollectionType.getInstance(collections);
                     List<AbstractType<?>> ctypes = new ArrayList<AbstractType<?>>(((CompositeType)cfm.comparator).types);
                     if (cfDef.hasCollections)
@@ -95,11 +99,11 @@ public class AlterTableStatement extends SchemaAlteringStatement
                     cfm.comparator = CompositeType.getInstance(ctypes);
                 }
                 cfm.addColumnDefinition(new ColumnDefinition(columnName.key,
-                                                             validator.getType(),
+                                                             type,
                                                              null,
                                                              null,
                                                              null,
-                                                             cfDef.isComposite ? ((CompositeType)meta.comparator).types.size() - 1 : null));
+                                                             componentIndex));
                 break;
 
             case ALTER:

http://git-wip-us.apache.org/repos/asf/cassandra/blob/ceca1997/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/ColumnFamilyStore.java b/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
index caa8dbc..44dc23a 100644
--- a/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
+++ b/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
@@ -152,6 +152,23 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean
         maybeReloadCompactionStrategy();
 
         indexManager.reload();
+
+        // If the CF comparator has changed, we need to change the memtable,
+        // because the old one still aliases the previous comparator. We don't
+        // call forceFlush() because it can skip the switch if the memtable is
+        // clean, which we don't want here.
+        try
+        {
+            maybeSwitchMemtable(getMemtableThreadSafe(), true).get();
+        }
+        catch (ExecutionException e)
+        {
+            throw new RuntimeException(e);
+        }
+        catch (InterruptedException e)
+        {
+            throw new AssertionError(e);
+        }
     }
 
     private void maybeReloadCompactionStrategy()