cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adelap...@apache.org
Subject [3/7] cassandra git commit: Fix ALTER TABLE statement to atomically propagate changes to the table and its MVs
Date Fri, 28 Jul 2017 10:29:27 GMT
Fix ALTER TABLE statement to atomically propagate changes to the table and its MVs

patch by Andres de la Peña; reviewed by Zhao Yang for CASSANDRA-12952


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

Branch: refs/heads/trunk
Commit: f85b024fb31567e0139b1ad5d019d6410908caa9
Parents: f919cf4
Author: Andrés de la Peña <a.penya.garcia@gmail.com>
Authored: Thu Jul 27 10:58:35 2017 +0100
Committer: Andrés de la Peña <a.penya.garcia@gmail.com>
Committed: Thu Jul 27 10:58:35 2017 +0100

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../cql3/statements/AlterTableStatement.java    |  8 +-----
 .../apache/cassandra/schema/SchemaKeyspace.java |  4 +--
 .../cassandra/service/MigrationManager.java     | 26 +++++++++++++++++---
 4 files changed, 26 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/f85b024f/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 5e6d189..5e95b75 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 3.0.15
+ * Fix ALTER TABLE statement to atomically propagate changes to the table and its MVs (CASSANDRA-12952)
  * Fixed ambiguous output of nodetool tablestats command (CASSANDRA-13722)
  * JMXEnabledThreadPoolExecutor with corePoolSize equal to maxPoolSize (Backport CASSANDRA-13329)
  * Fix Digest mismatch Exception if hints file has UnknownColumnFamily (CASSANDRA-13696)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f85b024f/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 756bb96..5db4b9f 100644
--- a/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
@@ -297,13 +297,7 @@ public class AlterTableStatement extends SchemaAlteringStatement
                 break;
         }
 
-        MigrationManager.announceColumnFamilyUpdate(cfm, isLocalOnly);
-
-        if (viewUpdates != null)
-        {
-            for (ViewDefinition viewUpdate : viewUpdates)
-                MigrationManager.announceViewUpdate(viewUpdate, isLocalOnly);
-        }
+        MigrationManager.announceColumnFamilyUpdate(cfm, viewUpdates, isLocalOnly);
         return new Event.SchemaChange(Event.SchemaChange.Change.UPDATED, Event.SchemaChange.Target.TABLE,
keyspace(), columnFamily());
     }
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f85b024f/src/java/org/apache/cassandra/schema/SchemaKeyspace.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/schema/SchemaKeyspace.java b/src/java/org/apache/cassandra/schema/SchemaKeyspace.java
index 8719b2f..63017ec 100644
--- a/src/java/org/apache/cassandra/schema/SchemaKeyspace.java
+++ b/src/java/org/apache/cassandra/schema/SchemaKeyspace.java
@@ -731,13 +731,11 @@ public final class SchemaKeyspace
         return mutation;
     }
 
-    public static Mutation makeUpdateViewMutation(KeyspaceMetadata keyspace,
+    public static Mutation makeUpdateViewMutation(Mutation mutation,
                                                   ViewDefinition oldView,
                                                   ViewDefinition newView,
                                                   long timestamp)
     {
-        Mutation mutation = makeCreateKeyspaceMutation(keyspace.name, keyspace.params, timestamp);
-
         addViewToSchemaMutation(newView, timestamp, false, mutation);
 
         MapDifference<ByteBuffer, ColumnDefinition> columnDiff = Maps.difference(oldView.metadata.getColumnMetadata(),

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f85b024f/src/java/org/apache/cassandra/service/MigrationManager.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/service/MigrationManager.java b/src/java/org/apache/cassandra/service/MigrationManager.java
index 7b7cd8f..b4893a9 100644
--- a/src/java/org/apache/cassandra/service/MigrationManager.java
+++ b/src/java/org/apache/cassandra/service/MigrationManager.java
@@ -413,6 +413,11 @@ public class MigrationManager
 
     public static void announceColumnFamilyUpdate(CFMetaData cfm, boolean announceLocally)
throws ConfigurationException
     {
+        announceColumnFamilyUpdate(cfm, null, announceLocally);
+    }
+
+    public static void announceColumnFamilyUpdate(CFMetaData cfm, Collection<ViewDefinition>
views, boolean announceLocally) throws ConfigurationException
+    {
         cfm.validate();
 
         CFMetaData oldCfm = Schema.instance.getCFMetaData(cfm.ksName, cfm.cfName);
@@ -422,23 +427,38 @@ public class MigrationManager
 
         oldCfm.validateCompatibility(cfm);
 
+        long timestamp = FBUtilities.timestampMicros();
+
         logger.info(String.format("Update table '%s/%s' From %s To %s", cfm.ksName, cfm.cfName,
oldCfm, cfm));
-        announce(SchemaKeyspace.makeUpdateTableMutation(ksm, oldCfm, cfm, FBUtilities.timestampMicros()),
announceLocally);
+        Mutation mutation = SchemaKeyspace.makeUpdateTableMutation(ksm, oldCfm, cfm, timestamp);
+
+        if (views != null)
+            views.forEach(view -> addViewUpdateToMutation(view, mutation, timestamp));
+
+        announce(mutation, announceLocally);
     }
 
     public static void announceViewUpdate(ViewDefinition view, boolean announceLocally) throws
ConfigurationException
     {
+        KeyspaceMetadata ksm = Schema.instance.getKSMetaData(view.ksName);
+        long timestamp = FBUtilities.timestampMicros();
+        Mutation mutation = SchemaKeyspace.makeCreateKeyspaceMutation(ksm.name, ksm.params,
timestamp);
+        addViewUpdateToMutation(view, mutation, timestamp);
+        announce(mutation, announceLocally);
+    }
+
+    private static void addViewUpdateToMutation(ViewDefinition view, Mutation mutation, long
timestamp)
+    {
         view.metadata.validate();
 
         ViewDefinition oldView = Schema.instance.getView(view.ksName, view.viewName);
         if (oldView == null)
             throw new ConfigurationException(String.format("Cannot update non existing materialized
view '%s' in keyspace '%s'.", view.viewName, view.ksName));
-        KeyspaceMetadata ksm = Schema.instance.getKSMetaData(view.ksName);
 
         oldView.metadata.validateCompatibility(view.metadata);
 
         logger.info(String.format("Update view '%s/%s' From %s To %s", view.ksName, view.viewName,
oldView, view));
-        announce(SchemaKeyspace.makeUpdateViewMutation(ksm, oldView, view, FBUtilities.timestampMicros()),
announceLocally);
+        SchemaKeyspace.makeUpdateViewMutation(mutation, oldView, view, timestamp);
     }
 
     public static void announceTypeUpdate(UserType updatedType, boolean announceLocally)


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org


Mime
View raw message