You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by sa...@apache.org on 2016/01/27 12:55:45 UTC

[2/6] cassandra git commit: Migrate build status for indexes along with legacy schema

Migrate build status for indexes along with legacy schema

Patch by Sam Tunnicliffe; reviewed by Jake Luciani for CASSANDRA-11046


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

Branch: refs/heads/cassandra-3.3
Commit: eb12770076fd7bfcc5c00900854d2c1258b51022
Parents: 5ec40a3
Author: Sam Tunnicliffe <sa...@beobal.com>
Authored: Wed Jan 20 12:14:08 2016 +0000
Committer: Sam Tunnicliffe <sa...@beobal.com>
Committed: Wed Jan 27 11:49:11 2016 +0000

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../cassandra/schema/LegacySchemaMigrator.java  | 22 +++++++++++
 .../schema/LegacySchemaMigratorTest.java        | 39 ++++++++++++++++++++
 3 files changed, 62 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/eb127700/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 024aaa0..c99438f 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 3.0.3
+ * Migrate build status for indexes along with legacy schema (CASSANDRA-11046)
  * Ensure SSTables for legacy KEYS indexes can be read (CASSANDRA-11045)
  * Added support for IBM zSystems architecture (CASSANDRA-11054)
  * Update CQL documentation (CASSANDRA-10899)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/eb127700/src/java/org/apache/cassandra/schema/LegacySchemaMigrator.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/schema/LegacySchemaMigrator.java b/src/java/org/apache/cassandra/schema/LegacySchemaMigrator.java
index 9008cc8..3588a92 100644
--- a/src/java/org/apache/cassandra/schema/LegacySchemaMigrator.java
+++ b/src/java/org/apache/cassandra/schema/LegacySchemaMigrator.java
@@ -88,6 +88,7 @@ public final class LegacySchemaMigrator
                     keyspaces.size(),
                     SchemaKeyspace.NAME);
         keyspaces.forEach(LegacySchemaMigrator::storeKeyspaceInNewSchemaTables);
+        keyspaces.forEach(LegacySchemaMigrator::migrateBuiltIndexesForKeyspace);
 
         // flush the new tables before truncating the old ones
         SchemaKeyspace.flush();
@@ -102,6 +103,27 @@ public final class LegacySchemaMigrator
         logger.info("Completed migration of legacy schema tables");
     }
 
+    private static void migrateBuiltIndexesForKeyspace(Keyspace keyspace)
+    {
+        keyspace.tables.forEach(LegacySchemaMigrator::migrateBuiltIndexesForTable);
+    }
+
+    private static void migrateBuiltIndexesForTable(Table table)
+    {
+        table.metadata.getIndexes().forEach((index) -> migrateIndexBuildStatus(table.metadata.ksName,
+                                                                               table.metadata.cfName,
+                                                                               index));
+    }
+
+    private static void migrateIndexBuildStatus(String keyspace, String table, IndexMetadata index)
+    {
+        if (SystemKeyspace.isIndexBuilt(keyspace, table + '.' + index.name))
+        {
+            SystemKeyspace.setIndexBuilt(keyspace, index.name);
+            SystemKeyspace.setIndexRemoved(keyspace, table + '.' + index.name);
+        }
+    }
+
     static void unloadLegacySchemaTables()
     {
         KeyspaceMetadata systemKeyspace = Schema.instance.getKSMetaData(SystemKeyspace.NAME);

http://git-wip-us.apache.org/repos/asf/cassandra/blob/eb127700/test/unit/org/apache/cassandra/schema/LegacySchemaMigratorTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/schema/LegacySchemaMigratorTest.java b/test/unit/org/apache/cassandra/schema/LegacySchemaMigratorTest.java
index 1ef3005..feb2778 100644
--- a/test/unit/org/apache/cassandra/schema/LegacySchemaMigratorTest.java
+++ b/test/unit/org/apache/cassandra/schema/LegacySchemaMigratorTest.java
@@ -39,6 +39,7 @@ import org.apache.cassandra.thrift.ThriftConversion;
 
 import static java.lang.String.format;
 import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertFalse;
 import static junit.framework.Assert.assertTrue;
 import static org.apache.cassandra.cql3.QueryProcessor.executeOnceInternal;
 import static org.apache.cassandra.utils.ByteBufferUtil.bytes;
@@ -87,6 +88,11 @@ public class LegacySchemaMigratorTest
 
         // make sure that we've read *exactly* the same set of keyspaces/tables/types/functions
         assertEquals(expected, actual);
+
+        // check that the build status of all indexes has been updated to use the new
+        // format of index name: the index_name column of system.IndexInfo used to
+        // contain table_name.index_name. Now it should contain just the index_name.
+        expected.forEach(LegacySchemaMigratorTest::verifyIndexBuildStatus);
     }
 
     private static void loadLegacySchemaTables()
@@ -542,6 +548,7 @@ public class LegacySchemaMigratorTest
     private static void legacySerializeKeyspace(KeyspaceMetadata keyspace)
     {
         makeLegacyCreateKeyspaceMutation(keyspace, TIMESTAMP).apply();
+        setLegacyIndexStatus(keyspace);
     }
 
     private static Mutation makeLegacyCreateKeyspaceMutation(KeyspaceMetadata keyspace, long timestamp)
@@ -787,4 +794,36 @@ public class LegacySchemaMigratorTest
 
         return ListType.getInstance(UTF8Type.instance, false).decompose(arguments);
     }
+
+    private static void setLegacyIndexStatus(KeyspaceMetadata keyspace)
+    {
+        keyspace.tables.forEach(LegacySchemaMigratorTest::setLegacyIndexStatus);
+    }
+
+    private static void setLegacyIndexStatus(CFMetaData table)
+    {
+        table.getIndexes().forEach((index) -> setLegacyIndexStatus(table.ksName, table.cfName, index));
+    }
+
+    private static void setLegacyIndexStatus(String keyspace, String table, IndexMetadata index)
+    {
+        SystemKeyspace.setIndexBuilt(keyspace, table + '.' + index.name);
+    }
+
+    private static void verifyIndexBuildStatus(KeyspaceMetadata keyspace)
+    {
+        keyspace.tables.forEach(LegacySchemaMigratorTest::verifyIndexBuildStatus);
+    }
+
+    private static void verifyIndexBuildStatus(CFMetaData table)
+    {
+        table.getIndexes().forEach(index -> verifyIndexBuildStatus(table.ksName, table.cfName, index));
+    }
+
+    private static void verifyIndexBuildStatus(String keyspace, String table, IndexMetadata index)
+    {
+        assertFalse(SystemKeyspace.isIndexBuilt(keyspace, table + '.' + index.name));
+        assertTrue(SystemKeyspace.isIndexBuilt(keyspace, index.name));
+    }
+
 }