cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slebre...@apache.org
Subject [1/3] git commit: Unify migration code
Date Sun, 18 Mar 2012 10:10:52 GMT
Updated Branches:
  refs/heads/cassandra-1.1.0 09ad083ab -> 438acfc8c


Unify migration code

patch by slebresne; reviewed by xedin for CASSANDRA-4017


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

Branch: refs/heads/cassandra-1.1.0
Commit: 438acfc8c4b58e05791ebc232e4517c71a4631e7
Parents: 09ad083
Author: Sylvain Lebresne <sylvain@datastax.com>
Authored: Wed Mar 14 16:59:12 2012 +0100
Committer: Sylvain Lebresne <sylvain@datastax.com>
Committed: Sun Mar 18 11:08:56 2012 +0100

----------------------------------------------------------------------
 CHANGES.txt                                        |    1 +
 .../org/apache/cassandra/config/CFMetaData.java    |   25 +-
 .../apache/cassandra/config/ColumnDefinition.java  |    6 +-
 .../cassandra/config/DatabaseDescriptor.java       |    4 +-
 .../org/apache/cassandra/config/KSMetaData.java    |   10 +-
 src/java/org/apache/cassandra/config/Schema.java   |   22 +--
 .../apache/cassandra/cql/DropIndexStatement.java   |    5 +-
 .../org/apache/cassandra/cql/QueryProcessor.java   |   62 +---
 .../cql3/statements/AlterTableStatement.java       |  163 +++++-----
 .../statements/CreateColumnFamilyStatement.java    |    7 +-
 .../cql3/statements/CreateIndexStatement.java      |   82 ++---
 .../cql3/statements/CreateKeyspaceStatement.java   |    7 +-
 .../cql3/statements/DropColumnFamilyStatement.java |    7 +-
 .../cql3/statements/DropIndexStatement.java        |    7 +-
 .../cql3/statements/DropKeyspaceStatement.java     |    7 +-
 .../cql3/statements/SchemaAlteringStatement.java   |   50 +---
 src/java/org/apache/cassandra/db/DefsTable.java    |  209 +++++++++++--
 src/java/org/apache/cassandra/db/Directories.java  |    2 +-
 src/java/org/apache/cassandra/db/SystemTable.java  |    5 +-
 .../cassandra/db/migration/AddColumnFamily.java    |   59 ----
 .../apache/cassandra/db/migration/AddKeyspace.java |   59 ----
 .../cassandra/db/migration/DropColumnFamily.java   |   57 ----
 .../cassandra/db/migration/DropKeyspace.java       |   54 ----
 .../apache/cassandra/db/migration/Migration.java   |  128 --------
 .../cassandra/db/migration/MigrationHelper.java    |  247 ---------------
 .../cassandra/db/migration/UpdateColumnFamily.java |   52 ---
 .../cassandra/db/migration/UpdateKeyspace.java     |   58 ----
 .../apache/cassandra/service/MigrationManager.java |  119 +++++++-
 .../org/apache/cassandra/service/StorageProxy.java |    3 +-
 .../apache/cassandra/thrift/CassandraServer.java   |   47 +--
 .../apache/cassandra/thrift/ThriftValidation.java  |    7 +-
 .../org/apache/cassandra/db/LongTableTest.java     |    4 +-
 .../apache/cassandra/db/MeteredFlusherTest.java    |    8 +-
 .../db/compaction/LongCompactionSpeedTest.java     |    4 +-
 .../cassandra/AbstractSerializationsTester.java    |    2 +-
 test/unit/org/apache/cassandra/CleanupHelper.java  |  126 --------
 test/unit/org/apache/cassandra/EmbeddedServer.java |    2 +-
 test/unit/org/apache/cassandra/SchemaLoader.java   |  115 +++++++-
 test/unit/org/apache/cassandra/cli/CliTest.java    |    6 +-
 .../apache/cassandra/config/CFMetaDataTest.java    |    4 +-
 .../cassandra/config/DatabaseDescriptorTest.java   |   12 +-
 .../unit/org/apache/cassandra/config/DefsTest.java |   94 ++----
 test/unit/org/apache/cassandra/db/CleanupTest.java |    4 +-
 .../apache/cassandra/db/ColumnFamilyStoreTest.java |    4 +-
 .../org/apache/cassandra/db/CommitLogTest.java     |    4 +-
 .../apache/cassandra/db/CounterMutationTest.java   |    4 +-
 .../unit/org/apache/cassandra/db/KeyCacheTest.java |    4 +-
 .../org/apache/cassandra/db/KeyCollisionTest.java  |    4 +-
 .../org/apache/cassandra/db/MultitableTest.java    |    4 +-
 .../unit/org/apache/cassandra/db/NameSortTest.java |    4 +-
 .../apache/cassandra/db/RecoveryManager2Test.java  |    4 +-
 .../apache/cassandra/db/RecoveryManager3Test.java  |    4 +-
 .../apache/cassandra/db/RecoveryManagerTest.java   |    4 +-
 .../cassandra/db/RecoveryManagerTruncateTest.java  |    4 +-
 .../cassandra/db/RemoveColumnFamilyTest.java       |    4 +-
 .../db/RemoveColumnFamilyWithFlush1Test.java       |    4 +-
 .../db/RemoveColumnFamilyWithFlush2Test.java       |    4 +-
 .../org/apache/cassandra/db/RemoveColumnTest.java  |    4 +-
 .../apache/cassandra/db/RemoveSubColumnTest.java   |    4 +-
 .../apache/cassandra/db/RemoveSuperColumnTest.java |    4 +-
 .../unit/org/apache/cassandra/db/RowCacheTest.java |    4 +-
 .../org/apache/cassandra/db/RowIterationTest.java  |    4 +-
 test/unit/org/apache/cassandra/db/ScrubTest.java   |    5 +-
 test/unit/org/apache/cassandra/db/TableTest.java   |    4 +-
 .../unit/org/apache/cassandra/db/TimeSortTest.java |    4 +-
 .../db/compaction/CompactionsPurgeTest.java        |    4 +-
 .../cassandra/db/compaction/CompactionsTest.java   |    4 +-
 .../cassandra/db/compaction/OneCompactionTest.java |    4 +-
 .../cassandra/db/marshal/CompositeTypeTest.java    |    4 +-
 .../db/marshal/DynamicCompositeTypeTest.java       |    4 +-
 .../org/apache/cassandra/dht/BootStrapperTest.java |    4 +-
 .../cassandra/io/BloomFilterTrackerTest.java       |    4 +-
 .../apache/cassandra/io/CompactSerializerTest.java |    4 +-
 .../cassandra/io/LazilyCompactedRowTest.java       |    4 +-
 .../cassandra/io/sstable/LegacySSTableTest.java    |    4 +-
 .../cassandra/io/sstable/SSTableReaderTest.java    |    4 +-
 .../io/sstable/SSTableSimpleWriterTest.java        |    4 +-
 .../apache/cassandra/io/sstable/SSTableTest.java   |    4 +-
 .../cassandra/locator/SimpleStrategyTest.java      |    4 +-
 .../service/AntiEntropyServiceTestAbstract.java    |    4 +-
 .../cassandra/service/CassandraServerTest.java     |    4 +-
 .../service/EmbeddedCassandraServiceTest.java      |    6 +-
 .../cassandra/service/LeaveAndBootstrapTest.java   |   48 ++--
 .../org/apache/cassandra/service/MoveTest.java     |   52 ++--
 .../org/apache/cassandra/service/RemoveTest.java   |   27 ++-
 .../apache/cassandra/service/StorageProxyTest.java |    4 +-
 .../service/StorageServiceClientTest.java          |    6 +-
 .../service/StorageServiceServerTest.java          |    6 +-
 .../cassandra/streaming/StreamingTransferTest.java |    4 +-
 .../cassandra/thrift/ThriftValidationTest.java     |    4 +-
 90 files changed, 818 insertions(+), 1444 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/438acfc8/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index d97fc5a..70db8e5 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -25,6 +25,7 @@
    serialization for schema (CASSANDRA-3792)
  * add missing column validator options to the CLI help (CASSANDRA-3926)
  * skip reading saved key cache if CF's caching strategy is NONE or ROWS_ONLY (CASSANDRA-3954)
+ * Unify migration code (CASSANDRA-4017)
 Merged from 1.0:
  * always compact away deleted hints immediately after handoff (CASSANDRA-3955)
  * delete hints from dropped ColumnFamilies on handoff instead of

http://git-wip-us.apache.org/repos/asf/cassandra/blob/438acfc8/src/java/org/apache/cassandra/config/CFMetaData.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/config/CFMetaData.java b/src/java/org/apache/cassandra/config/CFMetaData.java
index 157bb9e..2c1df75 100644
--- a/src/java/org/apache/cassandra/config/CFMetaData.java
+++ b/src/java/org/apache/cassandra/config/CFMetaData.java
@@ -39,7 +39,6 @@ import org.apache.cassandra.cql3.UntypedResultSet;
 import org.apache.cassandra.db.*;
 import org.apache.cassandra.db.compaction.AbstractCompactionStrategy;
 import org.apache.cassandra.db.marshal.*;
-import org.apache.cassandra.db.migration.Migration;
 import org.apache.cassandra.io.IColumnSerializer;
 import org.apache.cassandra.io.compress.CompressionParameters;
 import org.apache.cassandra.io.compress.SnappyCompressor;
@@ -72,9 +71,9 @@ public final class CFMetaData
     public static final CFMetaData StatusCf = newSystemMetadata(SystemTable.STATUS_CF, 0, "persistent metadata for the local node", BytesType.instance, null);
     public static final CFMetaData HintsCf = newSystemMetadata(HintedHandOffManager.HINTS_CF, 1, "hinted handoff data", BytesType.instance, BytesType.instance);
     @Deprecated
-    public static final CFMetaData MigrationsCf = newSystemMetadata(Migration.MIGRATIONS_CF, 2, "individual schema mutations", TimeUUIDType.instance, null);
+    public static final CFMetaData MigrationsCf = newSystemMetadata(DefsTable.OLD_MIGRATIONS_CF, 2, "individual schema mutations", TimeUUIDType.instance, null);
     @Deprecated
-    public static final CFMetaData SchemaCf = newSystemMetadata(Migration.SCHEMA_CF, 3, "current state of the schema", UTF8Type.instance, null);
+    public static final CFMetaData SchemaCf = newSystemMetadata(DefsTable.OLD_SCHEMA_CF, 3, "current state of the schema", UTF8Type.instance, null);
     public static final CFMetaData IndexCf = newSystemMetadata(SystemTable.INDEX_CF, 5, "indexes that have been completed", UTF8Type.instance, null);
     public static final CFMetaData NodeIdCf = newSystemMetadata(SystemTable.NODE_ID_CF, 6, "nodeId and their metadata", TimeUUIDType.instance, null);
     public static final CFMetaData VersionCf =
@@ -884,16 +883,14 @@ public final class CFMetaData
     }
 
     /**
-     * Calculate the difference between current metadata and given and serialize it as schema RowMutation
+     * Create schema mutations to update this metadata to provided new state.
      *
      * @param newState The new metadata (for the same CF)
      * @param modificationTimestamp Timestamp to use for mutation
      *
      * @return Difference between attributes in form of schema mutation
-     *
-     * @throws ConfigurationException if any of the attributes didn't pass validation
      */
-    public RowMutation diff(CFMetaData newState, long modificationTimestamp) throws ConfigurationException
+    public RowMutation toSchemaUpdate(CFMetaData newState, long modificationTimestamp)
     {
         RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, SystemTable.getSchemaKSKey(ksName));
 
@@ -1056,7 +1053,7 @@ public final class CFMetaData
         CFMetaData cfDef = fromSchemaNoColumns(result);
 
         Row serializedColumnDefinitions = ColumnDefinition.readSchema(cfDef.ksName, cfDef.cfName);
-        return addColumnDefinitionSchema(cfDef, serializedColumnDefinitions);
+        return addColumnDefinitionSchema(cfDef, serializedColumnDefinitions).updateCfDef();
     }
 
     private static CFMetaData fromSchema(Row row)
@@ -1131,7 +1128,7 @@ public final class CFMetaData
     // Package protected for use by tests
     static CFMetaData addColumnDefinitionSchema(CFMetaData cfDef, Row serializedColumnDefinitions)
     {
-        for (ColumnDefinition cd : ColumnDefinition.fromSchema(serializedColumnDefinitions, cfDef.comparator))
+        for (ColumnDefinition cd : ColumnDefinition.fromSchema(serializedColumnDefinitions, cfDef.getColumnDefinitionComparator()))
             cfDef.column_metadata.put(cd.name, cd);
         return cfDef;
     }
@@ -1146,9 +1143,10 @@ public final class CFMetaData
         return column_metadata.remove(def.name) != null;
     }
 
-    private void updateCfDef()
+    private CFMetaData updateCfDef()
     {
         cqlCfDef = new CFDefinition(this);
+        return this;
     }
 
     public CFDefinition getCfDef()
@@ -1157,6 +1155,11 @@ public final class CFMetaData
         return cqlCfDef;
     }
 
+    public static boolean isNameValid(String name)
+    {
+        return name.matches("\\w+");
+    }
+
     @Override
     public String toString()
     {
@@ -1178,7 +1181,7 @@ public final class CFMetaData
             .append("maxCompactionThreshold", maxCompactionThreshold)
             .append("keyAlias", keyAlias)
             .append("columnAliases", columnAliases)
-            .append("valueAlias", keyAlias)
+            .append("valueAlias", valueAlias)
             .append("column_metadata", column_metadata)
             .append("compactionStrategyClass", compactionStrategyClass)
             .append("compactionStrategyOptions", compactionStrategyOptions)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/438acfc8/src/java/org/apache/cassandra/config/ColumnDefinition.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/config/ColumnDefinition.java b/src/java/org/apache/cassandra/config/ColumnDefinition.java
index e47ac07..d8ac960 100644
--- a/src/java/org/apache/cassandra/config/ColumnDefinition.java
+++ b/src/java/org/apache/cassandra/config/ColumnDefinition.java
@@ -32,14 +32,12 @@ import org.apache.cassandra.cql3.UntypedResultSet;
 import org.apache.cassandra.db.*;
 import org.apache.cassandra.db.filter.QueryPath;
 import org.apache.cassandra.db.marshal.*;
-import org.apache.cassandra.db.migration.MigrationHelper;
 import org.apache.cassandra.service.StorageService;
 import org.apache.cassandra.thrift.ColumnDef;
 import org.apache.cassandra.thrift.IndexType;
 import org.apache.cassandra.utils.ByteBufferUtil;
 import org.apache.cassandra.utils.FBUtilities;
 
-import static org.apache.cassandra.db.migration.MigrationHelper.*;
 import static org.apache.cassandra.utils.FBUtilities.json;
 
 public class ColumnDefinition
@@ -244,8 +242,8 @@ public class ColumnDefinition
         ColumnFamilyStore columnsStore = SystemTable.schemaCFS(SystemTable.SCHEMA_COLUMNS_CF);
         ColumnFamily cf = columnsStore.getColumnFamily(key,
                                                        new QueryPath(SystemTable.SCHEMA_COLUMNS_CF),
-                                                       MigrationHelper.searchComposite(cfName, true),
-                                                       MigrationHelper.searchComposite(cfName, false),
+                                                       DefsTable.searchComposite(cfName, true),
+                                                       DefsTable.searchComposite(cfName, false),
                                                        false,
                                                        Integer.MAX_VALUE);
         return new Row(key, cf);

http://git-wip-us.apache.org/repos/asf/cassandra/blob/438acfc8/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/config/DatabaseDescriptor.java b/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
index db2669c..34a3ac0 100644
--- a/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
+++ b/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
@@ -39,7 +39,6 @@ import org.apache.cassandra.config.Config.RequestSchedulerId;
 import org.apache.cassandra.db.ColumnFamilyStore;
 import org.apache.cassandra.db.DefsTable;
 import org.apache.cassandra.db.SystemTable;
-import org.apache.cassandra.db.migration.Migration;
 import org.apache.cassandra.dht.IPartitioner;
 import org.apache.cassandra.io.util.FileUtils;
 import org.apache.cassandra.io.util.MmappedSegmentedFile;
@@ -50,6 +49,7 @@ import org.apache.cassandra.locator.SeedProvider;
 import org.apache.cassandra.scheduler.IRequestScheduler;
 import org.apache.cassandra.scheduler.NoScheduler;
 import org.apache.cassandra.service.CacheService;
+import org.apache.cassandra.service.MigrationManager;
 import org.apache.cassandra.thrift.CassandraDaemon;
 import org.apache.cassandra.utils.FBUtilities;
 import org.yaml.snakeyaml.Loader;
@@ -482,7 +482,7 @@ public class DatabaseDescriptor
             // we can load tables from local storage if a version is set in the system table and that actually maps to
             // real data in the definitions table.  If we do end up loading from xml, store the definitions so that we
             // don't load from xml anymore.
-            UUID uuid = Migration.getLastMigrationId();
+            UUID uuid = MigrationManager.getLastMigrationId();
 
             if (uuid == null)
             {

http://git-wip-us.apache.org/repos/asf/cassandra/blob/438acfc8/src/java/org/apache/cassandra/config/KSMetaData.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/config/KSMetaData.java b/src/java/org/apache/cassandra/config/KSMetaData.java
index 5b9d5ba..c10a94f 100644
--- a/src/java/org/apache/cassandra/config/KSMetaData.java
+++ b/src/java/org/apache/cassandra/config/KSMetaData.java
@@ -38,7 +38,6 @@ import org.apache.cassandra.thrift.CfDef;
 import org.apache.cassandra.thrift.KsDef;
 import org.apache.cassandra.thrift.ColumnDef;
 
-import static org.apache.cassandra.db.migration.MigrationHelper.*;
 import static org.apache.cassandra.utils.FBUtilities.*;
 
 public final class KSMetaData
@@ -161,7 +160,7 @@ public final class KSMetaData
         return ksdef;
     }
 
-    public RowMutation diff(KSMetaData newState, long modificationTimestamp)
+    public RowMutation toSchemaUpdate(KSMetaData newState, long modificationTimestamp)
     {
         return newState.toSchema(modificationTimestamp);
     }
@@ -266,10 +265,15 @@ public final class KSMetaData
         for (CFMetaData cfm : cfms.values())
         {
             Row columnRow = ColumnDefinition.readSchema(cfm.ksName, cfm.cfName);
-            for (ColumnDefinition cd : ColumnDefinition.fromSchema(columnRow, cfm.comparator))
+            for (ColumnDefinition cd : ColumnDefinition.fromSchema(columnRow, cfm.getColumnDefinitionComparator()))
                 cfm.column_metadata.put(cd.name, cd);
         }
 
         return cfms;
     }
+
+    public KSMetaData validate() throws ConfigurationException
+    {
+        return this;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/438acfc8/src/java/org/apache/cassandra/config/Schema.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/config/Schema.java b/src/java/org/apache/cassandra/config/Schema.java
index 2ae507b..6aa43e0 100644
--- a/src/java/org/apache/cassandra/config/Schema.java
+++ b/src/java/org/apache/cassandra/config/Schema.java
@@ -37,7 +37,6 @@ import org.apache.cassandra.db.Row;
 import org.apache.cassandra.db.SystemTable;
 import org.apache.cassandra.db.Table;
 import org.apache.cassandra.db.marshal.AbstractType;
-import org.apache.cassandra.db.migration.Migration;
 import org.apache.cassandra.io.sstable.Descriptor;
 import org.apache.cassandra.utils.Pair;
 
@@ -95,23 +94,8 @@ public class Schema
      */
     public Schema load(KSMetaData keyspaceDef)
     {
-        if (!Migration.isLegalName(keyspaceDef.name))
-            throw new RuntimeException("invalid keyspace name: " + keyspaceDef.name);
-
         for (CFMetaData cfm : keyspaceDef.cfMetaData().values())
-        {
-            if (!Migration.isLegalName(cfm.cfName))
-                throw new RuntimeException("invalid column family name: " + cfm.cfName);
-
-            try
-            {
-                load(cfm);
-            }
-            catch (ConfigurationException ex)
-            {
-                throw new IOError(ex);
-            }
-        }
+            load(cfm);
 
         setTableDefinition(keyspaceDef);
 
@@ -382,12 +366,12 @@ public class Schema
      *
      * @throws ConfigurationException if ColumnFamily was already loaded
      */
-    public void load(CFMetaData cfm) throws ConfigurationException
+    public void load(CFMetaData cfm)
     {
         Pair<String, String> key = new Pair<String, String>(cfm.ksName, cfm.cfName);
 
         if (cfIdMap.containsKey(key))
-            throw new ConfigurationException("Attempt to assign id to existing column family.");
+            throw new RuntimeException(String.format("Attempting to load already loaded column family %s.%s", cfm.ksName, cfm.cfName));
 
         logger.debug("Adding {} to cfIdMap", cfm);
         cfIdMap.put(key, cfm.cfId);

http://git-wip-us.apache.org/repos/asf/cassandra/blob/438acfc8/src/java/org/apache/cassandra/cql/DropIndexStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql/DropIndexStatement.java b/src/java/org/apache/cassandra/cql/DropIndexStatement.java
index 6d1bb18..9c7a744 100644
--- a/src/java/org/apache/cassandra/cql/DropIndexStatement.java
+++ b/src/java/org/apache/cassandra/cql/DropIndexStatement.java
@@ -23,7 +23,6 @@ package org.apache.cassandra.cql;
 import java.io.IOException;
 
 import org.apache.cassandra.config.*;
-import org.apache.cassandra.db.migration.UpdateColumnFamily;
 import org.apache.cassandra.thrift.CfDef;
 import org.apache.cassandra.thrift.ColumnDef;
 import org.apache.cassandra.thrift.InvalidRequestException;
@@ -37,7 +36,7 @@ public class DropIndexStatement
         index = indexName;
     }
 
-    public UpdateColumnFamily generateMutation(String keyspace)
+    public CFMetaData generateCFMetadataUpdate(String keyspace)
     throws InvalidRequestException, ConfigurationException, IOException
     {
         CfDef cfDef = null;
@@ -54,7 +53,7 @@ public class DropIndexStatement
         if (cfDef == null)
             throw new InvalidRequestException("Index '" + index + "' could not be found in any of the ColumnFamilies of keyspace '" + keyspace + "'");
 
-        return new UpdateColumnFamily(CFMetaData.fromThrift(cfDef));
+        return CFMetaData.fromThrift(cfDef);
     }
 
     private CfDef getUpdatedCFDef(CfDef cfDef) throws InvalidRequestException

http://git-wip-us.apache.org/repos/asf/cassandra/blob/438acfc8/src/java/org/apache/cassandra/cql/QueryProcessor.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql/QueryProcessor.java b/src/java/org/apache/cassandra/cql/QueryProcessor.java
index c824561..912315c 100644
--- a/src/java/org/apache/cassandra/cql/QueryProcessor.java
+++ b/src/java/org/apache/cassandra/cql/QueryProcessor.java
@@ -43,11 +43,11 @@ import org.apache.cassandra.db.marshal.AbstractType;
 import org.apache.cassandra.db.marshal.AsciiType;
 import org.apache.cassandra.db.marshal.MarshalException;
 import org.apache.cassandra.db.marshal.TypeParser;
-import org.apache.cassandra.db.migration.*;
 import org.apache.cassandra.dht.*;
 import org.apache.cassandra.service.ClientState;
 import org.apache.cassandra.service.StorageProxy;
 import org.apache.cassandra.service.StorageService;
+import org.apache.cassandra.service.MigrationManager;
 import org.apache.cassandra.thrift.*;
 import org.apache.cassandra.thrift.Column;
 import org.apache.cassandra.utils.ByteBufferUtil;
@@ -324,45 +324,6 @@ public class QueryProcessor
         }
     }
 
-    // Copypasta from o.a.c.thrift.CassandraDaemon
-    private static void applyMigrationOnStage(final Migration m) throws SchemaDisagreementException, InvalidRequestException
-    {
-        Future<?> f = StageManager.getStage(Stage.MIGRATION).submit(new Callable<Object>()
-        {
-            public Object call() throws Exception
-            {
-                m.apply();
-                return null;
-            }
-        });
-        try
-        {
-            f.get();
-        }
-        catch (InterruptedException e)
-        {
-            throw new RuntimeException(e);
-        }
-        catch (ExecutionException e)
-        {
-            // this means call() threw an exception. deal with it directly.
-            if (e.getCause() != null)
-            {
-                InvalidRequestException ex = new InvalidRequestException(e.getCause().getMessage());
-                ex.initCause(e.getCause());
-                throw ex;
-            }
-            else
-            {
-                InvalidRequestException ex = new InvalidRequestException(e.getMessage());
-                ex.initCause(e);
-                throw ex;
-            }
-        }
-
-        validateSchemaIsSettled();
-    }
-
     public static void validateKey(ByteBuffer key) throws InvalidRequestException
     {
         if (key == null || key.remaining() == 0)
@@ -723,7 +684,8 @@ public class QueryProcessor
                                 .setStrategy_options(create.getStrategyOptions());
                     ThriftValidation.validateKsDef(ksd);
                     ThriftValidation.validateKeyspaceNotYetExisting(create.getName());
-                    applyMigrationOnStage(new AddKeyspace(KSMetaData.fromThrift(ksd)));
+                    MigrationManager.announceNewKeyspace(KSMetaData.fromThrift(ksd));
+                    validateSchemaIsSettled();
                 }
                 catch (ConfigurationException e)
                 {
@@ -744,7 +706,8 @@ public class QueryProcessor
 
                 try
                 {
-                    applyMigrationOnStage(new AddColumnFamily(cfmd));
+                    MigrationManager.announceNewColumnFamily(cfmd);
+                    validateSchemaIsSettled();
                 }
                 catch (ConfigurationException e)
                 {
@@ -790,7 +753,8 @@ public class QueryProcessor
                 ThriftValidation.validateCfDef(cf_def, oldCfm);
                 try
                 {
-                    applyMigrationOnStage(new UpdateColumnFamily(CFMetaData.fromThrift(cf_def)));
+                    MigrationManager.announceColumnFamilyUpdate(CFMetaData.fromThrift(cf_def));
+                    validateSchemaIsSettled();
                 }
                 catch (ConfigurationException e)
                 {
@@ -809,7 +773,8 @@ public class QueryProcessor
 
                 try
                 {
-                    applyMigrationOnStage(dropIdx.generateMutation(clientState.getKeyspace()));
+                    MigrationManager.announceColumnFamilyUpdate(dropIdx.generateCFMetadataUpdate(clientState.getKeyspace()));
+                    validateSchemaIsSettled();
                 }
                 catch (ConfigurationException e)
                 {
@@ -835,7 +800,8 @@ public class QueryProcessor
 
                 try
                 {
-                    applyMigrationOnStage(new DropKeyspace(deleteKeyspace));
+                    MigrationManager.announceKeyspaceDrop(deleteKeyspace);
+                    validateSchemaIsSettled();
                 }
                 catch (ConfigurationException e)
                 {
@@ -854,7 +820,8 @@ public class QueryProcessor
 
                 try
                 {
-                    applyMigrationOnStage(new DropColumnFamily(keyspace, deleteColumnFamily));
+                    MigrationManager.announceColumnFamilyDrop(keyspace, deleteColumnFamily);
+                    validateSchemaIsSettled();
                 }
                 catch (ConfigurationException e)
                 {
@@ -875,7 +842,8 @@ public class QueryProcessor
 
                 try
                 {
-                    applyMigrationOnStage(new UpdateColumnFamily(CFMetaData.fromThrift(alterTable.getCfDef(keyspace))));
+                    MigrationManager.announceColumnFamilyUpdate(CFMetaData.fromThrift(alterTable.getCfDef(keyspace)));
+                    validateSchemaIsSettled();
                 }
                 catch (ConfigurationException e)
                 {

http://git-wip-us.apache.org/repos/asf/cassandra/blob/438acfc8/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 8935df7..9e08fbb 100644
--- a/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
@@ -23,8 +23,7 @@ import java.util.*;
 
 import org.apache.cassandra.cql3.*;
 import org.apache.cassandra.config.*;
-import org.apache.cassandra.db.migration.Migration;
-import org.apache.cassandra.db.migration.UpdateColumnFamily;
+import org.apache.cassandra.service.MigrationManager;
 import org.apache.cassandra.thrift.CfDef;
 import org.apache.cassandra.thrift.ColumnDef;
 import org.apache.cassandra.thrift.InvalidRequestException;
@@ -51,99 +50,91 @@ public class AlterTableStatement extends SchemaAlteringStatement
         this.cfProps.addAll(propertyMap);
     }
 
-    public Migration getMigration() throws InvalidRequestException, IOException
+    public void announceMigration() throws InvalidRequestException, ConfigurationException
     {
-        try
-        {
-            CFMetaData meta = validateColumnFamily(keyspace(), columnFamily());
-            CfDef thriftDef = meta.toThrift();
-
-            CFDefinition cfDef = meta.getCfDef();
-            CFDefinition.Name name = this.oType == Type.OPTS ? null : cfDef.get(columnName);
-            switch (oType)
-            {
-                case ADD:
-                    if (cfDef.isCompact)
-                        throw new InvalidRequestException("Cannot add new column to a compact CF");
-                    if (name != null)
-                    {
-                        switch (name.kind)
-                        {
-                            case KEY_ALIAS:
-                            case COLUMN_ALIAS:
-                                throw new InvalidRequestException(String.format("Invalid column name %s because it conflicts with a PRIMARY KEY part", columnName));
-                            case COLUMN_METADATA:
-                                throw new InvalidRequestException(String.format("Invalid column name %s because it conflicts with an existing column", columnName));
-                        }
-                    }
-                    thriftDef.column_metadata.add(new ColumnDefinition(columnName.key,
-                                CFPropDefs.parseType(validator),
-                                null,
-                                null,
-                                null).toThrift());
-                    break;
-
-                case ALTER:
-                    if (name == null)
-                        throw new InvalidRequestException(String.format("Column %s was not found in CF %s", columnName, columnFamily()));
-
-                    switch (name.kind)
-                    {
-                        case KEY_ALIAS:
-                            thriftDef.key_validation_class = CFPropDefs.parseType(validator).toString();
-                            break;
-                        case COLUMN_ALIAS:
-                            throw new InvalidRequestException(String.format("Cannot alter PRIMARY KEY part %s", columnName));
-                        case VALUE_ALIAS:
-                            thriftDef.default_validation_class = CFPropDefs.parseType(validator).toString();
-                            break;
-                        case COLUMN_METADATA:
-                            ColumnDefinition column = meta.getColumnDefinition(columnName.key);
-                            column.setValidator(CFPropDefs.parseType(validator));
-                            thriftDef.column_metadata.add(column.toThrift());
-                            break;
-                    }
-                    break;
-
-                case DROP:
-                    if (cfDef.isCompact)
-                        throw new InvalidRequestException("Cannot drop columns from a compact CF");
-                    if (name == null)
-                        throw new InvalidRequestException(String.format("Column %s was not found in CF %s", columnName, columnFamily()));
+        CFMetaData meta = validateColumnFamily(keyspace(), columnFamily());
+        CfDef thriftDef = meta.toThrift();
 
+        CFDefinition cfDef = meta.getCfDef();
+        CFDefinition.Name name = this.oType == Type.OPTS ? null : cfDef.get(columnName);
+        switch (oType)
+        {
+            case ADD:
+                if (cfDef.isCompact)
+                    throw new InvalidRequestException("Cannot add new column to a compact CF");
+                if (name != null)
+                {
                     switch (name.kind)
                     {
                         case KEY_ALIAS:
                         case COLUMN_ALIAS:
-                            throw new InvalidRequestException(String.format("Cannot drop PRIMARY KEY part %s", columnName));
+                            throw new InvalidRequestException(String.format("Invalid column name %s because it conflicts with a PRIMARY KEY part", columnName));
                         case COLUMN_METADATA:
-                            ColumnDef toDelete = null;
-                            for (ColumnDef columnDef : thriftDef.column_metadata)
-                            {
-                                if (columnDef.name.equals(columnName.key))
-                                    toDelete = columnDef;
-                            }
-                            assert toDelete != null;
-                            thriftDef.column_metadata.remove(toDelete);
-                            break;
+                            throw new InvalidRequestException(String.format("Invalid column name %s because it conflicts with an existing column", columnName));
                     }
-                    break;
-                case OPTS:
-                    if (cfProps == null)
-                        throw new InvalidRequestException(String.format("ALTER COLUMNFAMILY WITH invoked, but no parameters found"));
-
-                    cfProps.validate();
-                    applyPropertiesToCfDef(thriftDef, cfProps);
-                    break;
-            }
-            return new UpdateColumnFamily(CFMetaData.fromThrift(thriftDef));
-        }
-        catch (ConfigurationException e)
-        {
-            InvalidRequestException ex = new InvalidRequestException(e.toString());
-            ex.initCause(e);
-            throw ex;
+                }
+                thriftDef.column_metadata.add(new ColumnDefinition(columnName.key,
+                            CFPropDefs.parseType(validator),
+                            null,
+                            null,
+                            null).toThrift());
+                break;
+
+            case ALTER:
+                if (name == null)
+                    throw new InvalidRequestException(String.format("Column %s was not found in CF %s", columnName, columnFamily()));
+
+                switch (name.kind)
+                {
+                    case KEY_ALIAS:
+                        thriftDef.key_validation_class = CFPropDefs.parseType(validator).toString();
+                        break;
+                    case COLUMN_ALIAS:
+                        throw new InvalidRequestException(String.format("Cannot alter PRIMARY KEY part %s", columnName));
+                    case VALUE_ALIAS:
+                        thriftDef.default_validation_class = CFPropDefs.parseType(validator).toString();
+                        break;
+                    case COLUMN_METADATA:
+                        ColumnDefinition column = meta.getColumnDefinition(columnName.key);
+                        column.setValidator(CFPropDefs.parseType(validator));
+                        thriftDef.column_metadata.add(column.toThrift());
+                        break;
+                }
+                break;
+
+            case DROP:
+                if (cfDef.isCompact)
+                    throw new InvalidRequestException("Cannot drop columns from a compact CF");
+                if (name == null)
+                    throw new InvalidRequestException(String.format("Column %s was not found in CF %s", columnName, columnFamily()));
+
+                switch (name.kind)
+                {
+                    case KEY_ALIAS:
+                    case COLUMN_ALIAS:
+                        throw new InvalidRequestException(String.format("Cannot drop PRIMARY KEY part %s", columnName));
+                    case COLUMN_METADATA:
+                        ColumnDef toDelete = null;
+                        for (ColumnDef columnDef : thriftDef.column_metadata)
+                        {
+                            if (columnDef.name.equals(columnName.key))
+                                toDelete = columnDef;
+                        }
+                        assert toDelete != null;
+                        thriftDef.column_metadata.remove(toDelete);
+                        break;
+                }
+                break;
+            case OPTS:
+                if (cfProps == null)
+                    throw new InvalidRequestException(String.format("ALTER COLUMNFAMILY WITH invoked, but no parameters found"));
+
+                cfProps.validate();
+                applyPropertiesToCfDef(thriftDef, cfProps);
+                break;
         }
+
+        MigrationManager.announceColumnFamilyUpdate(CFMetaData.fromThrift(thriftDef));
     }
 
     public static void applyPropertiesToCfDef(CfDef cfDef, CFPropDefs cfProps) throws InvalidRequestException

http://git-wip-us.apache.org/repos/asf/cassandra/blob/438acfc8/src/java/org/apache/cassandra/cql3/statements/CreateColumnFamilyStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/CreateColumnFamilyStatement.java b/src/java/org/apache/cassandra/cql3/statements/CreateColumnFamilyStatement.java
index e175fed..1689895 100644
--- a/src/java/org/apache/cassandra/cql3/statements/CreateColumnFamilyStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/CreateColumnFamilyStatement.java
@@ -35,9 +35,8 @@ import org.apache.cassandra.config.ConfigurationException;
 import org.apache.cassandra.db.ColumnFamilyType;
 import org.apache.cassandra.db.marshal.AbstractType;
 import org.apache.cassandra.db.marshal.CompositeType;
-import org.apache.cassandra.db.migration.AddColumnFamily;
-import org.apache.cassandra.db.migration.Migration;
 import org.apache.cassandra.service.ClientState;
+import org.apache.cassandra.service.MigrationManager;
 import org.apache.cassandra.thrift.CqlResult;
 import org.apache.cassandra.thrift.InvalidRequestException;
 import org.apache.cassandra.thrift.ThriftValidation;
@@ -78,11 +77,11 @@ public class CreateColumnFamilyStatement extends SchemaAlteringStatement
         return columnDefs;
     }
 
-    public Migration getMigration() throws InvalidRequestException, ConfigurationException, IOException
+    public void announceMigration() throws InvalidRequestException, ConfigurationException
     {
         CFMetaData cfmd = getCFMetaData();
         ThriftValidation.validateCfDef(cfmd.toThrift(), null);
-        return new AddColumnFamily(cfmd);
+        MigrationManager.announceNewColumnFamily(cfmd);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/cassandra/blob/438acfc8/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 cc738c4..c42a854 100644
--- a/src/java/org/apache/cassandra/cql3/statements/CreateIndexStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/CreateIndexStatement.java
@@ -24,8 +24,7 @@ import org.slf4j.LoggerFactory;
 import org.apache.cassandra.config.CFMetaData;
 import org.apache.cassandra.config.ConfigurationException;
 import org.apache.cassandra.cql3.*;
-import org.apache.cassandra.db.migration.Migration;
-import org.apache.cassandra.db.migration.UpdateColumnFamily;
+import org.apache.cassandra.service.MigrationManager;
 import org.apache.cassandra.thrift.CfDef;
 import org.apache.cassandra.thrift.ColumnDef;
 import org.apache.cassandra.thrift.IndexType;
@@ -47,60 +46,47 @@ public class CreateIndexStatement extends SchemaAlteringStatement
         this.columnName = columnName;
     }
 
-    public Migration getMigration() throws InvalidRequestException, ConfigurationException
+    public void announceMigration() throws InvalidRequestException, ConfigurationException
     {
-        try
+        CFMetaData oldCfm = ThriftValidation.validateColumnFamily(keyspace(), columnFamily());
+        boolean columnExists = false;
+        // mutating oldCfm directly would be bad, but mutating a Thrift copy is fine.  This also
+        // sets us up to use validateCfDef to check for index name collisions.
+        CfDef cf_def = oldCfm.toThrift();
+        for (ColumnDef cd : cf_def.column_metadata)
         {
-            CFMetaData oldCfm = ThriftValidation.validateColumnFamily(keyspace(), columnFamily());
-            boolean columnExists = false;
-            // mutating oldCfm directly would be bad, but mutating a Thrift copy is fine.  This also
-            // sets us up to use validateCfDef to check for index name collisions.
-            CfDef cf_def = oldCfm.toThrift();
-            for (ColumnDef cd : cf_def.column_metadata)
+            if (cd.name.equals(columnName.key))
             {
-                if (cd.name.equals(columnName.key))
-                {
-                    if (cd.index_type != null)
-                        throw new InvalidRequestException("Index already exists");
-                    if (logger.isDebugEnabled())
-                        logger.debug("Updating column {} definition for index {}", columnName, indexName);
-                    cd.setIndex_type(IndexType.KEYS);
-                    cd.setIndex_name(indexName);
-                    columnExists = true;
-                    break;
-                }
+                if (cd.index_type != null)
+                    throw new InvalidRequestException("Index already exists");
+                if (logger.isDebugEnabled())
+                    logger.debug("Updating column {} definition for index {}", columnName, indexName);
+                cd.setIndex_type(IndexType.KEYS);
+                cd.setIndex_name(indexName);
+                columnExists = true;
+                break;
             }
-            if (!columnExists)
+        }
+        if (!columnExists)
+        {
+            CFDefinition cfDef = oldCfm.getCfDef();
+            CFDefinition.Name name = cfDef.get(columnName);
+            if (name != null)
             {
-                CFDefinition cfDef = oldCfm.getCfDef();
-                CFDefinition.Name name = cfDef.get(columnName);
-                if (name != null)
+                switch (name.kind)
                 {
-                    switch (name.kind)
-                    {
-                        case KEY_ALIAS:
-                        case COLUMN_ALIAS:
-                            throw new InvalidRequestException(String.format("Cannot create index on PRIMARY KEY part %s", columnName));
-                        case VALUE_ALIAS:
-                            throw new InvalidRequestException(String.format("Cannot create index on column %s of compact CF", columnName));
-                    }
+                    case KEY_ALIAS:
+                    case COLUMN_ALIAS:
+                        throw new InvalidRequestException(String.format("Cannot create index on PRIMARY KEY part %s", columnName));
+                    case VALUE_ALIAS:
+                        throw new InvalidRequestException(String.format("Cannot create index on column %s of compact CF", columnName));
                 }
-                throw new InvalidRequestException("No column definition found for column " + columnName);
             }
-
-            CFMetaData.addDefaultIndexNames(cf_def);
-            ThriftValidation.validateCfDef(cf_def, oldCfm);
-            return new UpdateColumnFamily(CFMetaData.fromThrift(cf_def));
-        }
-        catch (InvalidRequestException e)
-        {
-            logger.error("oups", e);
-            throw e;
-        }
-        catch (ConfigurationException e)
-        {
-            logger.error("oups", e);
-            throw e;
+            throw new InvalidRequestException("No column definition found for column " + columnName);
         }
+
+        CFMetaData.addDefaultIndexNames(cf_def);
+        ThriftValidation.validateCfDef(cf_def, oldCfm);
+        MigrationManager.announceColumnFamilyUpdate(CFMetaData.fromThrift(cf_def));
     }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/438acfc8/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 1e9349c..c5de9d6 100644
--- a/src/java/org/apache/cassandra/cql3/statements/CreateKeyspaceStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/CreateKeyspaceStatement.java
@@ -26,10 +26,9 @@ import java.util.Map;
 import org.apache.cassandra.config.ConfigurationException;
 import org.apache.cassandra.config.DatabaseDescriptor;
 import org.apache.cassandra.config.KSMetaData;
-import org.apache.cassandra.db.migration.AddKeyspace;
-import org.apache.cassandra.db.migration.Migration;
 import org.apache.cassandra.locator.AbstractReplicationStrategy;
 import org.apache.cassandra.service.ClientState;
+import org.apache.cassandra.service.MigrationManager;
 import org.apache.cassandra.service.StorageService;
 import org.apache.cassandra.thrift.CfDef;
 import org.apache.cassandra.thrift.InvalidRequestException;
@@ -103,12 +102,12 @@ public class CreateKeyspaceStatement extends SchemaAlteringStatement
         }
     }
 
-    public Migration getMigration() throws InvalidRequestException, ConfigurationException, IOException
+    public void announceMigration() throws InvalidRequestException, ConfigurationException
     {
         KsDef ksd = new KsDef(name, strategyClass, Collections.<CfDef>emptyList());
         ksd.setStrategy_options(strategyOptions);
         ThriftValidation.validateKsDef(ksd);
         ThriftValidation.validateKeyspaceNotYetExisting(name);
-        return new AddKeyspace(KSMetaData.fromThrift(ksd));
+        MigrationManager.announceNewKeyspace(KSMetaData.fromThrift(ksd));
     }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/438acfc8/src/java/org/apache/cassandra/cql3/statements/DropColumnFamilyStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/DropColumnFamilyStatement.java b/src/java/org/apache/cassandra/cql3/statements/DropColumnFamilyStatement.java
index 58e10b8..e0bd75d 100644
--- a/src/java/org/apache/cassandra/cql3/statements/DropColumnFamilyStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/DropColumnFamilyStatement.java
@@ -22,8 +22,7 @@ import java.io.IOException;
 
 import org.apache.cassandra.config.ConfigurationException;
 import org.apache.cassandra.cql3.CFName;
-import org.apache.cassandra.db.migration.DropColumnFamily;
-import org.apache.cassandra.db.migration.Migration;
+import org.apache.cassandra.service.MigrationManager;
 
 public class DropColumnFamilyStatement extends SchemaAlteringStatement
 {
@@ -32,8 +31,8 @@ public class DropColumnFamilyStatement extends SchemaAlteringStatement
         super(name);
     }
 
-    public Migration getMigration() throws ConfigurationException, IOException
+    public void announceMigration() throws ConfigurationException
     {
-        return new DropColumnFamily(keyspace(), columnFamily());
+        MigrationManager.announceColumnFamilyDrop(keyspace(), columnFamily());
     }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/438acfc8/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 5d3721a..4959e81 100644
--- a/src/java/org/apache/cassandra/cql3/statements/DropIndexStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/DropIndexStatement.java
@@ -22,8 +22,7 @@ import java.io.IOException;
 
 import org.apache.cassandra.cql3.*;
 import org.apache.cassandra.config.*;
-import org.apache.cassandra.db.migration.Migration;
-import org.apache.cassandra.db.migration.UpdateColumnFamily;
+import org.apache.cassandra.service.MigrationManager;
 import org.apache.cassandra.thrift.CfDef;
 import org.apache.cassandra.thrift.ColumnDef;
 import org.apache.cassandra.thrift.InvalidRequestException;
@@ -38,7 +37,7 @@ public class DropIndexStatement extends SchemaAlteringStatement
         index = indexName;
     }
 
-    public Migration getMigration() throws InvalidRequestException, ConfigurationException, IOException
+    public void announceMigration() throws InvalidRequestException, ConfigurationException
     {
         CfDef cfDef = null;
 
@@ -54,7 +53,7 @@ public class DropIndexStatement extends SchemaAlteringStatement
         if (cfDef == null)
             throw new InvalidRequestException("Index '" + index + "' could not be found in any of the column families of keyspace '" + keyspace() + "'");
 
-        return new UpdateColumnFamily(CFMetaData.fromThrift(cfDef));
+        MigrationManager.announceColumnFamilyUpdate(CFMetaData.fromThrift(cfDef));
     }
 
     private CfDef getUpdatedCFDef(CfDef cfDef) throws InvalidRequestException

http://git-wip-us.apache.org/repos/asf/cassandra/blob/438acfc8/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 1ed057d..82dea1b 100644
--- a/src/java/org/apache/cassandra/cql3/statements/DropKeyspaceStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/DropKeyspaceStatement.java
@@ -21,9 +21,8 @@ package org.apache.cassandra.cql3.statements;
 import java.io.IOException;
 
 import org.apache.cassandra.config.ConfigurationException;
-import org.apache.cassandra.db.migration.DropKeyspace;
-import org.apache.cassandra.db.migration.Migration;
 import org.apache.cassandra.service.ClientState;
+import org.apache.cassandra.service.MigrationManager;
 import org.apache.cassandra.thrift.InvalidRequestException;
 import org.apache.cassandra.thrift.SchemaDisagreementException;
 import org.apache.cassandra.thrift.ThriftValidation;
@@ -45,8 +44,8 @@ public class DropKeyspaceStatement extends SchemaAlteringStatement
         ThriftValidation.validateKeyspaceNotSystem(keyspace);
     }
 
-    public Migration getMigration() throws ConfigurationException, IOException
+    public void announceMigration() throws ConfigurationException
     {
-        return new DropKeyspace(keyspace);
+        MigrationManager.announceKeyspaceDrop(keyspace);
     }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/438acfc8/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 4fab436..c2d7180 100644
--- a/src/java/org/apache/cassandra/cql3/statements/SchemaAlteringStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/SchemaAlteringStatement.java
@@ -76,7 +76,7 @@ public abstract class SchemaAlteringStatement extends CFStatement implements CQL
         return new Prepared(this);
     }
 
-    public abstract Migration getMigration() throws InvalidRequestException, IOException, ConfigurationException;
+    public abstract void announceMigration() throws InvalidRequestException, ConfigurationException;
 
     public void checkAccess(ClientState state) throws InvalidRequestException
     {
@@ -96,7 +96,7 @@ public abstract class SchemaAlteringStatement extends CFStatement implements CQL
     {
         try
         {
-            applyMigrationOnStage(getMigration());
+            announceMigration();
         }
         catch (ConfigurationException e)
         {
@@ -104,12 +104,7 @@ public abstract class SchemaAlteringStatement extends CFStatement implements CQL
             ex.initCause(e);
             throw ex;
         }
-        catch (IOException e)
-        {
-            InvalidRequestException ex = new InvalidRequestException(e.toString());
-            ex.initCause(e);
-            throw ex;
-        }
+        validateSchemaIsSettled();
         return null;
     }
 
@@ -120,45 +115,6 @@ public abstract class SchemaAlteringStatement extends CFStatement implements CQL
             throw new SchemaDisagreementException();
     }
 
-    // Copypasta from o.a.c.thrift.CassandraDaemon
-    private static void applyMigrationOnStage(final Migration m) throws SchemaDisagreementException, InvalidRequestException
-    {
-        Future<?> f = StageManager.getStage(Stage.MIGRATION).submit(new Callable<Object>()
-        {
-            public Object call() throws Exception
-            {
-                m.apply();
-                return null;
-            }
-        });
-        try
-        {
-            f.get();
-        }
-        catch (InterruptedException e)
-        {
-            throw new RuntimeException(e);
-        }
-        catch (ExecutionException e)
-        {
-            // this means call() threw an exception. deal with it directly.
-            if (e.getCause() != null)
-            {
-                InvalidRequestException ex = new InvalidRequestException(e.getCause().getMessage());
-                ex.initCause(e.getCause());
-                throw ex;
-            }
-            else
-            {
-                InvalidRequestException ex = new InvalidRequestException(e.getMessage());
-                ex.initCause(e);
-                throw ex;
-            }
-        }
-
-        validateSchemaIsSettled();
-    }
-
     private static Map<String, List<String>> describeSchemaVersions()
     {
         // unreachable hosts don't count towards disagreement

http://git-wip-us.apache.org/repos/asf/cassandra/blob/438acfc8/src/java/org/apache/cassandra/db/DefsTable.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/DefsTable.java b/src/java/org/apache/cassandra/db/DefsTable.java
index 05e4519..ddab690 100644
--- a/src/java/org/apache/cassandra/db/DefsTable.java
+++ b/src/java/org/apache/cassandra/db/DefsTable.java
@@ -21,10 +21,12 @@ package org.apache.cassandra.db;
 import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.util.*;
+import java.util.concurrent.Future;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.collect.Iterables;
 import com.google.common.collect.MapDifference;
 import com.google.common.collect.Maps;
 
@@ -36,14 +38,14 @@ import org.apache.cassandra.config.*;
 import org.apache.cassandra.db.filter.QueryFilter;
 import org.apache.cassandra.db.filter.QueryPath;
 import org.apache.cassandra.db.marshal.AsciiType;
-import org.apache.cassandra.db.migration.Migration;
-import org.apache.cassandra.db.migration.MigrationHelper;
+import org.apache.cassandra.db.marshal.UTF8Type;
 import org.apache.cassandra.db.migration.avro.KsDef;
 import org.apache.cassandra.net.MessagingService;
 import org.apache.cassandra.service.MigrationManager;
 import org.apache.cassandra.service.StorageService;
 import org.apache.cassandra.thrift.CfDef;
 import org.apache.cassandra.utils.ByteBufferUtil;
+import org.apache.cassandra.utils.FBUtilities;
 
 /**
  * SCHEMA_{KEYSPACES, COLUMNFAMILIES, COLUMNS}_CF are used to store Keyspace/ColumnFamily attributes to make schema
@@ -123,6 +125,9 @@ public class DefsTable
     // NB: must be an invalid keyspace name
     public static final ByteBuffer DEFINITION_SCHEMA_COLUMN_NAME = ByteBufferUtil.bytes("Avro/Schema");
 
+    public static final String OLD_MIGRATIONS_CF = "Migrations";
+    public static final String OLD_SCHEMA_CF = "Schema";
+
     /* dumps current keyspace definitions to storage */
     public static synchronized void dumpToStorage(Collection<KSMetaData> keyspaces) throws IOException
     {
@@ -156,6 +161,19 @@ public class DefsTable
         return keyspaces;
     }
 
+    public static ByteBuffer searchComposite(String name, boolean start)
+    {
+        assert name != null;
+        ByteBuffer nameBytes = UTF8Type.instance.decompose(name);
+        int length = nameBytes.remaining();
+        byte[] bytes = new byte[2 + length + 1];
+        bytes[0] = (byte)((length >> 8) & 0xFF);
+        bytes[1] = (byte)(length & 0xFF);
+        ByteBufferUtil.arrayCopy(nameBytes, 0, bytes, 2, length);
+        bytes[bytes.length - 1] = (byte)(start ? 0 : 1);
+        return ByteBuffer.wrap(bytes);
+    }
+
     private static Row serializedColumnFamilies(DecoratedKey ksNameKey)
     {
         ColumnFamilyStore cfsStore = SystemTable.schemaCFS(SystemTable.SCHEMA_COLUMNFAMILIES_CF);
@@ -176,8 +194,8 @@ public class DefsTable
     {
         DecoratedKey vkey = StorageService.getPartitioner().decorateKey(toUTF8Bytes(version));
         Table defs = Table.open(Table.SYSTEM_TABLE);
-        ColumnFamilyStore cfStore = defs.getColumnFamilyStore(Migration.SCHEMA_CF);
-        ColumnFamily cf = cfStore.getColumnFamily(QueryFilter.getIdentityFilter(vkey, new QueryPath(Migration.SCHEMA_CF)));
+        ColumnFamilyStore cfStore = defs.getColumnFamilyStore(OLD_SCHEMA_CF);
+        ColumnFamily cf = cfStore.getColumnFamily(QueryFilter.getIdentityFilter(vkey, new QueryPath(OLD_SCHEMA_CF)));
         IColumn avroschema = cf.getColumn(DEFINITION_SCHEMA_COLUMN_NAME);
 
         Collection<KSMetaData> keyspaces = Collections.emptyList();
@@ -202,8 +220,8 @@ public class DefsTable
             dumpToStorage(keyspaces);
 
             logger.info("Truncating deprecated system column families (migrations, schema)...");
-            MigrationHelper.dropColumnFamily(Table.SYSTEM_TABLE, Migration.MIGRATIONS_CF, -1, false);
-            MigrationHelper.dropColumnFamily(Table.SYSTEM_TABLE, Migration.SCHEMA_CF, -1, false);
+            dropColumnFamily(Table.SYSTEM_TABLE, OLD_MIGRATIONS_CF);
+            dropColumnFamily(Table.SYSTEM_TABLE, OLD_SCHEMA_CF);
         }
 
         return keyspaces;
@@ -227,25 +245,34 @@ public class DefsTable
             return;
         }
 
-        // save current state of the schema
+        mergeSchema(MigrationManager.deserializeMigrationMessage(data, version));
+    }
+
+    public static synchronized void mergeSchema(Collection<RowMutation> mutations) throws ConfigurationException, IOException
+    {
+        // current state of the schema
         Map<DecoratedKey, ColumnFamily> oldKeyspaces = SystemTable.getSchema(SystemTable.SCHEMA_KEYSPACES_CF);
         Map<DecoratedKey, ColumnFamily> oldColumnFamilies = SystemTable.getSchema(SystemTable.SCHEMA_COLUMNFAMILIES_CF);
 
-        // apply remote mutations
-        for (RowMutation mutation : MigrationManager.deserializeMigrationMessage(data, version))
+        for (RowMutation mutation : mutations)
             mutation.apply();
 
         if (!StorageService.instance.isClientMode())
-            MigrationHelper.flushSchemaCFs();
+            flushSchemaCFs();
 
         Schema.instance.updateVersionAndAnnounce();
 
-        Set<String> keyspacesToDrop = mergeKeyspaces(oldKeyspaces, SystemTable.getSchema(SystemTable.SCHEMA_KEYSPACES_CF));
-        mergeColumnFamilies(oldColumnFamilies, SystemTable.getSchema(SystemTable.SCHEMA_COLUMNFAMILIES_CF));
+        // with new data applied
+        Map<DecoratedKey, ColumnFamily> newKeyspaces = SystemTable.getSchema(SystemTable.SCHEMA_KEYSPACES_CF);
+        Map<DecoratedKey, ColumnFamily> newColumnFamilies = SystemTable.getSchema(SystemTable.SCHEMA_COLUMNFAMILIES_CF);
+
+        Set<String> keyspacesToDrop = mergeKeyspaces(oldKeyspaces, newKeyspaces);
+        mergeColumnFamilies(oldColumnFamilies, newColumnFamilies);
 
         // it is safe to drop a keyspace only when all nested ColumnFamilies where deleted
         for (String keyspaceToDrop : keyspacesToDrop)
-            MigrationHelper.dropKeyspace(keyspaceToDrop, -1, false);
+            dropKeyspace(keyspaceToDrop);
+
     }
 
     private static Set<String> mergeKeyspaces(Map<DecoratedKey, ColumnFamily> old, Map<DecoratedKey, ColumnFamily> updated)
@@ -263,10 +290,7 @@ public class DefsTable
 
             // we don't care about nested ColumnFamilies here because those are going to be processed separately
             if (!ksAttrs.isEmpty())
-            {
-                KSMetaData ksm = KSMetaData.fromSchema(new Row(entry.getKey(), entry.getValue()), Collections.<CFMetaData>emptyList());
-                MigrationHelper.addKeyspace(ksm, -1, false);
-            }
+                addKeyspace(KSMetaData.fromSchema(new Row(entry.getKey(), entry.getValue()), Collections.<CFMetaData>emptyList()));
         }
 
         /**
@@ -287,8 +311,7 @@ public class DefsTable
 
             if (prevValue.isEmpty())
             {
-                KSMetaData ksm = KSMetaData.fromSchema(new Row(entry.getKey(), newValue), Collections.<CFMetaData>emptyList());
-                MigrationHelper.addKeyspace(ksm, -1, false);
+                addKeyspace(KSMetaData.fromSchema(new Row(entry.getKey(), newValue), Collections.<CFMetaData>emptyList()));
                 continue;
             }
 
@@ -311,14 +334,9 @@ public class DefsTable
             ColumnFamily newState = valueDiff.rightValue();
 
             if (newState.isEmpty())
-            {
                 keyspacesToDrop.add(AsciiType.instance.getString(key.key));
-            }
             else
-            {
-                KSMetaData ksm = KSMetaData.fromSchema(new Row(key, newState), Collections.<CFMetaData>emptyList());
-                MigrationHelper.updateKeyspace(ksm, -1, false);
-            }
+                updateKeyspace(KSMetaData.fromSchema(new Row(key, newState), Collections.<CFMetaData>emptyList()));
         }
 
         return keyspacesToDrop;
@@ -340,7 +358,7 @@ public class DefsTable
                Map<String, CFMetaData> cfDefs = KSMetaData.deserializeColumnFamilies(new Row(entry.getKey(), cfAttrs));
 
                 for (CFMetaData cfDef : cfDefs.values())
-                    MigrationHelper.addColumnFamily(cfDef, -1, false);
+                    addColumnFamily(cfDef);
             }
         }
 
@@ -353,17 +371,18 @@ public class DefsTable
 
             ColumnFamily prevValue = valueDiff.leftValue(); // state before external modification
             ColumnFamily newValue = valueDiff.rightValue(); // updated state
+
             Row newRow = new Row(keyspace, newValue);
 
             if (prevValue.isEmpty()) // whole keyspace was deleted and now it's re-created
             {
                 for (CFMetaData cfm : KSMetaData.deserializeColumnFamilies(newRow).values())
-                    MigrationHelper.addColumnFamily(cfm, -1, false);
+                    addColumnFamily(cfm);
             }
             else if (newValue.isEmpty()) // whole keyspace is deleted
             {
                 for (CFMetaData cfm : KSMetaData.deserializeColumnFamilies(new Row(keyspace, prevValue)).values())
-                    MigrationHelper.dropColumnFamily(cfm.ksName, cfm.cfName, -1, false);
+                    dropColumnFamily(cfm.ksName, cfm.cfName);
             }
             else // has modifications in the nested ColumnFamilies, need to perform nested diff to determine what was really changed
             {
@@ -378,17 +397,145 @@ public class DefsTable
                 MapDifference<String, CFMetaData> cfDefDiff = Maps.difference(oldCfDefs, newCfDefs);
 
                 for (CFMetaData cfDef : cfDefDiff.entriesOnlyOnRight().values())
-                    MigrationHelper.addColumnFamily(cfDef, -1, false);
+                    addColumnFamily(cfDef);
 
                 for (CFMetaData cfDef : cfDefDiff.entriesOnlyOnLeft().values())
-                    MigrationHelper.dropColumnFamily(cfDef.ksName, cfDef.cfName, -1, false);
+                    dropColumnFamily(cfDef.ksName, cfDef.cfName);
 
                 for (MapDifference.ValueDifference<CFMetaData> cfDef : cfDefDiff.entriesDiffering().values())
-                    MigrationHelper.updateColumnFamily(cfDef.rightValue(), -1, false);
+                    updateColumnFamily(cfDef.rightValue());
             }
         }
     }
 
+    private static void addKeyspace(KSMetaData ksm)
+    {
+        assert Schema.instance.getKSMetaData(ksm.name) == null;
+        Schema.instance.load(ksm);
+
+        if (!StorageService.instance.isClientMode())
+            Table.open(ksm.name);
+    }
+
+    private static void addColumnFamily(CFMetaData cfm) throws IOException
+    {
+        assert Schema.instance.getCFMetaData(cfm.ksName, cfm.cfName) == null;
+        KSMetaData ksm = Schema.instance.getTableDefinition(cfm.ksName);
+        ksm = KSMetaData.cloneWith(ksm, Iterables.concat(ksm.cfMetaData().values(), Collections.singleton(cfm)));
+
+        Schema.instance.load(cfm);
+
+        // make sure it's init-ed w/ the old definitions first,
+        // since we're going to call initCf on the new one manually
+        Table.open(cfm.ksName);
+
+        Schema.instance.setTableDefinition(ksm);
+
+        if (!StorageService.instance.isClientMode())
+            Table.open(ksm.name).initCf(cfm.cfId, cfm.cfName);
+    }
+
+    private static void updateKeyspace(KSMetaData newState) throws IOException
+    {
+        KSMetaData oldKsm = Schema.instance.getKSMetaData(newState.name);
+        assert oldKsm != null;
+        KSMetaData newKsm = KSMetaData.cloneWith(oldKsm.reloadAttributes(), oldKsm.cfMetaData().values());
+
+        Schema.instance.setTableDefinition(newKsm);
+
+        try
+        {
+            if (!StorageService.instance.isClientMode())
+                Table.open(newState.name).createReplicationStrategy(newKsm);
+        }
+        catch (ConfigurationException e)
+        {
+            // It's too late to throw a configuration exception, we should have catch those previously
+            throw new RuntimeException(e);
+        }
+    }
+
+    private static void updateColumnFamily(CFMetaData newState) throws IOException
+    {
+        CFMetaData cfm = Schema.instance.getCFMetaData(newState.ksName, newState.cfName);
+        assert cfm != null;
+        cfm.reload();
+
+        if (!StorageService.instance.isClientMode())
+        {
+            Table table = Table.open(cfm.ksName);
+            table.getColumnFamilyStore(cfm.cfName).reload();
+        }
+    }
+
+    private static void dropKeyspace(String ksName) throws IOException
+    {
+        KSMetaData ksm = Schema.instance.getTableDefinition(ksName);
+        String snapshotName = Table.getTimestampedSnapshotName(ksName);
+
+        // remove all cfs from the table instance.
+        for (CFMetaData cfm : ksm.cfMetaData().values())
+        {
+            ColumnFamilyStore cfs = Table.open(ksm.name).getColumnFamilyStore(cfm.cfName);
+
+            Schema.instance.purge(cfm);
+
+            if (!StorageService.instance.isClientMode())
+            {
+                cfs.snapshot(snapshotName);
+                Table.open(ksm.name).dropCf(cfm.cfId);
+            }
+        }
+
+        // remove the table from the static instances.
+        Table.clear(ksm.name);
+        Schema.instance.clearTableDefinition(ksm);
+    }
+
+    private static void dropColumnFamily(String ksName, String cfName) throws IOException
+    {
+        KSMetaData ksm = Schema.instance.getTableDefinition(ksName);
+        assert ksm != null;
+        ColumnFamilyStore cfs = Table.open(ksName).getColumnFamilyStore(cfName);
+        assert cfs != null;
+
+        // reinitialize the table.
+        CFMetaData cfm = ksm.cfMetaData().get(cfName);
+
+        Schema.instance.purge(cfm);
+        Schema.instance.setTableDefinition(makeNewKeyspaceDefinition(ksm, cfm));
+
+        if (!StorageService.instance.isClientMode())
+        {
+            cfs.snapshot(Table.getTimestampedSnapshotName(cfs.columnFamily));
+            Table.open(ksm.name).dropCf(cfm.cfId);
+        }
+    }
+
+    private static KSMetaData makeNewKeyspaceDefinition(KSMetaData ksm, CFMetaData toExclude)
+    {
+        // clone ksm but do not include the new def
+        List<CFMetaData> newCfs = new ArrayList<CFMetaData>(ksm.cfMetaData().values());
+        newCfs.remove(toExclude);
+        assert newCfs.size() == ksm.cfMetaData().size() - 1;
+        return KSMetaData.cloneWith(ksm, newCfs);
+    }
+
+    private static void flushSchemaCFs()
+    {
+        flushSchemaCF(SystemTable.SCHEMA_KEYSPACES_CF);
+        flushSchemaCF(SystemTable.SCHEMA_COLUMNFAMILIES_CF);
+        flushSchemaCF(SystemTable.SCHEMA_COLUMNS_CF);
+    }
+
+    private static void flushSchemaCF(String cfName)
+    {
+        Future<?> flush = SystemTable.schemaCFS(cfName).forceFlush();
+
+        if (flush != null)
+            FBUtilities.waitOnFuture(flush);
+    }
+
     private static ByteBuffer toUTF8Bytes(UUID version)
     {
         return ByteBufferUtil.bytes(version.toString());

http://git-wip-us.apache.org/repos/asf/cassandra/blob/438acfc8/src/java/org/apache/cassandra/db/Directories.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/Directories.java b/src/java/org/apache/cassandra/db/Directories.java
index 2afefd2..7f383ff 100644
--- a/src/java/org/apache/cassandra/db/Directories.java
+++ b/src/java/org/apache/cassandra/db/Directories.java
@@ -154,7 +154,7 @@ public class Directories
                 maxLocation = dir;
             }
         }
-        logger.debug("expected data files size is {}; largest free partition has {} bytes free", estimatedSize, maxFreeDisk);
+        logger.debug(String.format("expected data files size is %d; largest free partition (%s) has %d bytes free", estimatedSize, maxLocation, maxFreeDisk));
 
         // Load factor of 0.9 we do not want to use the entire disk that is too risky.
         maxFreeDisk = (long)(0.9 * maxFreeDisk);

http://git-wip-us.apache.org/repos/asf/cassandra/blob/438acfc8/src/java/org/apache/cassandra/db/SystemTable.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/SystemTable.java b/src/java/org/apache/cassandra/db/SystemTable.java
index 6f2b9c8..277e087 100644
--- a/src/java/org/apache/cassandra/db/SystemTable.java
+++ b/src/java/org/apache/cassandra/db/SystemTable.java
@@ -37,7 +37,6 @@ import org.apache.cassandra.db.filter.QueryFilter;
 import org.apache.cassandra.db.filter.QueryPath;
 import org.apache.cassandra.db.marshal.AsciiType;
 import org.apache.cassandra.db.marshal.BytesType;
-import org.apache.cassandra.db.migration.MigrationHelper;
 import org.apache.cassandra.dht.IPartitioner;
 import org.apache.cassandra.dht.Range;
 import org.apache.cassandra.dht.Token;
@@ -610,8 +609,8 @@ public class SystemTable
         ColumnFamilyStore schemaCFS = SystemTable.schemaCFS(SCHEMA_COLUMNFAMILIES_CF);
         ColumnFamily result = schemaCFS.getColumnFamily(key,
                                                         new QueryPath(SCHEMA_COLUMNFAMILIES_CF),
-                                                        MigrationHelper.searchComposite(cfName, true),
-                                                        MigrationHelper.searchComposite(cfName, false),
+                                                        DefsTable.searchComposite(cfName, true),
+                                                        DefsTable.searchComposite(cfName, false),
                                                         false,
                                                         Integer.MAX_VALUE);
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/438acfc8/src/java/org/apache/cassandra/db/migration/AddColumnFamily.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/migration/AddColumnFamily.java b/src/java/org/apache/cassandra/db/migration/AddColumnFamily.java
deleted file mode 100644
index c54e4ab..0000000
--- a/src/java/org/apache/cassandra/db/migration/AddColumnFamily.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.cassandra.db.migration;
-
-import java.io.IOException;
-import java.util.Collection;
-
-import org.apache.cassandra.config.CFMetaData;
-import org.apache.cassandra.config.ConfigurationException;
-import org.apache.cassandra.config.KSMetaData;
-import org.apache.cassandra.config.Schema;
-import org.apache.cassandra.db.RowMutation;
-
-public class  AddColumnFamily extends Migration
-{
-    private final CFMetaData cfm;
-
-    public AddColumnFamily(CFMetaData cfm) throws ConfigurationException
-    {
-        super(System.nanoTime());
-
-        KSMetaData ksm = Schema.instance.getTableDefinition(cfm.ksName);
-
-        if (ksm == null)
-            throw new ConfigurationException(String.format("Can't add ColumnFamily '%s' to Keyspace '%s': Keyspace does not exist.", cfm.cfName, cfm.ksName));
-        else if (ksm.cfMetaData().containsKey(cfm.cfName))
-            throw new ConfigurationException(String.format("Can't add ColumnFamily '%s' to Keyspace '%s': Already exists.", cfm.cfName, cfm.ksName));
-        else if (!Migration.isLegalName(cfm.cfName))
-            throw new ConfigurationException("Can't add ColumnFamily '%s' to Keyspace '%s': Invalid ColumnFamily name.");
-
-        this.cfm = cfm;
-    }
-
-    protected RowMutation applyImpl() throws ConfigurationException, IOException
-    {
-        return MigrationHelper.addColumnFamily(cfm, timestamp, true);
-    }
-
-    @Override
-    public String toString()
-    {
-        return "Add column family: " + cfm.toString();
-    }
-}

http://git-wip-us.apache.org/repos/asf/cassandra/blob/438acfc8/src/java/org/apache/cassandra/db/migration/AddKeyspace.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/migration/AddKeyspace.java b/src/java/org/apache/cassandra/db/migration/AddKeyspace.java
deleted file mode 100644
index 36c4de9..0000000
--- a/src/java/org/apache/cassandra/db/migration/AddKeyspace.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.cassandra.db.migration;
-
-import java.io.IOException;
-import java.util.Collection;
-
-import org.apache.cassandra.config.CFMetaData;
-import org.apache.cassandra.config.ConfigurationException;
-import org.apache.cassandra.config.KSMetaData;
-import org.apache.cassandra.config.Schema;
-import org.apache.cassandra.db.RowMutation;
-
-public class AddKeyspace extends Migration
-{
-    private final KSMetaData ksm;
-
-    public AddKeyspace(KSMetaData ksm) throws ConfigurationException
-    {
-        super(System.nanoTime());
-
-        if (Schema.instance.getTableDefinition(ksm.name) != null)
-            throw new ConfigurationException(String.format("Can't add Keyspace '%s': Already exists.", ksm.name));
-        else if (!Migration.isLegalName(ksm.name))
-            throw new ConfigurationException(String.format("Can't add Keyspace '%s': Invalid name.", ksm.name));
-        for (CFMetaData cfm : ksm.cfMetaData().values())
-            if (!Migration.isLegalName(cfm.cfName))
-                throw new ConfigurationException(String.format("Can't add Keyspace '%s': Invalid ColumnFamily name '%s'.", ksm.name, cfm.cfName));
-
-        this.ksm = ksm;
-    }
-
-    protected RowMutation applyImpl() throws ConfigurationException, IOException
-    {
-        return MigrationHelper.addKeyspace(ksm, timestamp, true);
-    }
-
-    @Override
-    public String toString()
-    {
-        return "Add keyspace: " + ksm.toString();
-    }
-}

http://git-wip-us.apache.org/repos/asf/cassandra/blob/438acfc8/src/java/org/apache/cassandra/db/migration/DropColumnFamily.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/migration/DropColumnFamily.java b/src/java/org/apache/cassandra/db/migration/DropColumnFamily.java
deleted file mode 100644
index 0628824..0000000
--- a/src/java/org/apache/cassandra/db/migration/DropColumnFamily.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.cassandra.db.migration;
-
-import java.io.IOException;
-import java.util.Collection;
-
-import org.apache.cassandra.config.ConfigurationException;
-import org.apache.cassandra.config.KSMetaData;
-import org.apache.cassandra.config.Schema;
-import org.apache.cassandra.db.RowMutation;
-
-public class DropColumnFamily extends Migration
-{
-    private final String ksName;
-    private final String cfName;
-
-    public DropColumnFamily(String ksName, String cfName) throws ConfigurationException
-    {
-        super(System.nanoTime());
-
-        KSMetaData ksm = Schema.instance.getTableDefinition(ksName);
-        if (ksm == null)
-            throw new ConfigurationException("Can't drop ColumnFamily: No such keyspace '" + ksName + "'.");
-        else if (!ksm.cfMetaData().containsKey(cfName))
-            throw new ConfigurationException(String.format("Can't drop ColumnFamily (ks=%s, cf=%s) : Not defined in that keyspace.", ksName, cfName));
-
-        this.ksName = ksName;
-        this.cfName = cfName;
-    }
-
-    protected RowMutation applyImpl() throws ConfigurationException, IOException
-    {
-        return MigrationHelper.dropColumnFamily(ksName, cfName, timestamp, true);
-    }
-
-    @Override
-    public String toString()
-    {
-        return String.format("Drop column family: %s.%s", ksName, cfName);
-    }
-}

http://git-wip-us.apache.org/repos/asf/cassandra/blob/438acfc8/src/java/org/apache/cassandra/db/migration/DropKeyspace.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/migration/DropKeyspace.java b/src/java/org/apache/cassandra/db/migration/DropKeyspace.java
deleted file mode 100644
index d6e46a4..0000000
--- a/src/java/org/apache/cassandra/db/migration/DropKeyspace.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.cassandra.db.migration;
-
-import java.io.IOException;
-import java.util.Collection;
-
-import org.apache.cassandra.config.ConfigurationException;
-import org.apache.cassandra.config.KSMetaData;
-import org.apache.cassandra.config.Schema;
-import org.apache.cassandra.db.RowMutation;
-
-public class DropKeyspace extends Migration
-{
-    private final String name;
-
-    public DropKeyspace(String name) throws ConfigurationException
-    {
-        super(System.nanoTime());
-
-        KSMetaData ksm = Schema.instance.getTableDefinition(name);
-        if (ksm == null)
-            throw new ConfigurationException("Can't drop keyspace '" + name + "' because it does not exist.");
-
-        this.name = name;
-    }
-
-    protected RowMutation applyImpl() throws ConfigurationException, IOException
-    {
-        return MigrationHelper.dropKeyspace(name, timestamp, true);
-    }
-
-    @Override
-    public String toString()
-    {
-        return "Drop keyspace: " + name;
-    }
-}

http://git-wip-us.apache.org/repos/asf/cassandra/blob/438acfc8/src/java/org/apache/cassandra/db/migration/Migration.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/migration/Migration.java b/src/java/org/apache/cassandra/db/migration/Migration.java
deleted file mode 100644
index 9b239bb..0000000
--- a/src/java/org/apache/cassandra/db/migration/Migration.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.cassandra.db.migration;
-
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.UUID;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.cassandra.config.ConfigurationException;
-import org.apache.cassandra.config.Schema;
-import org.apache.cassandra.db.*;
-import org.apache.cassandra.db.filter.QueryFilter;
-import org.apache.cassandra.db.filter.QueryPath;
-import org.apache.cassandra.service.MigrationManager;
-import org.apache.cassandra.service.StorageService;
-import org.apache.cassandra.utils.ByteBufferUtil;
-import org.apache.cassandra.utils.UUIDGen;
-
-/**
- * A migration represents a single metadata mutation (cf dropped, added, etc.).
- *
- * There are two parts to a migration (think of it as a schema update):
- * 1. data is written to the schema cf (SCHEMA_KEYSPACES_CF).
- * 2. updated models are applied to the cassandra instance.
- *
- * Since all steps are not committed atomically, care should be taken to ensure that a node/cluster is reasonably
- * quiescent with regard to the Keyspace or ColumnFamily whose schema is being modified.
- */
-public abstract class Migration
-{
-    protected static final Logger logger = LoggerFactory.getLogger(Migration.class);
-
-    public static final String NAME_VALIDATOR_REGEX = "\\w+";
-    public static final String MIGRATIONS_CF = "Migrations";
-    public static final String SCHEMA_CF = "Schema";
-    public static final ByteBuffer LAST_MIGRATION_KEY = ByteBufferUtil.bytes("Last Migration");
-
-    protected final long timestamp;
-
-    Migration(long modificationTimestamp)
-    {
-        timestamp = modificationTimestamp;
-    }
-
-    public final void apply() throws ConfigurationException, IOException
-    {
-        RowMutation mutation = applyImpl();
-        assert mutation != null;
-
-        if (!StorageService.instance.isClientMode())
-            MigrationHelper.flushSchemaCFs();
-
-        Schema.instance.updateVersion();
-        announce(Collections.singletonList(mutation));
-    }
-
-    /**
-     * Class specific apply implementation where schema migration logic should be put
-     *
-     * @return mutation to update native schema
-     *
-     * @throws IOException on any I/O related error.
-     * @throws ConfigurationException if there is object misconfiguration.
-     */
-    protected abstract RowMutation applyImpl() throws ConfigurationException, IOException;
-
-    /**
-     * Send schema update (in form of row mutations) to alive nodes in the cluster.
-     *
-     * @param mutations to distribute in the cluster
-     */
-    private void announce(Collection<RowMutation> mutations)
-    {
-        assert !StorageService.instance.isClientMode();
-        MigrationManager.announce(mutations);
-        passiveAnnounce(); // keeps gossip in sync w/ what we just told everyone
-    }
-
-    /** Announce new schema version over Gossip */
-    public final void passiveAnnounce()
-    {
-        MigrationManager.passiveAnnounce(Schema.instance.getVersion());
-    }
-
-    /**
-     * Used only in case node has old style migration schema (newly updated)
-     * @return the UUID identifying version of the last applied migration
-     */
-    @Deprecated
-    public static UUID getLastMigrationId()
-    {
-        DecoratedKey<?> dkey = StorageService.getPartitioner().decorateKey(LAST_MIGRATION_KEY);
-        Table defs = Table.open(Table.SYSTEM_TABLE);
-        ColumnFamilyStore cfStore = defs.getColumnFamilyStore(SCHEMA_CF);
-        QueryFilter filter = QueryFilter.getNamesFilter(dkey, new QueryPath(SCHEMA_CF), LAST_MIGRATION_KEY);
-        ColumnFamily cf = cfStore.getColumnFamily(filter);
-        if (cf == null || cf.getColumnNames().size() == 0)
-            return null;
-        else
-            return UUIDGen.getUUID(cf.getColumn(LAST_MIGRATION_KEY).value());
-    }
-
-    public static boolean isLegalName(String s)
-    {
-        return s.matches(Migration.NAME_VALIDATOR_REGEX);
-    }
-}


Mime
View raw message