cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject [3/6] git commit: migrate 1.1 schema_columnfamilies.key_alias column to key_aliases patch by Alex Liu; reviewed by Tyler Hobbs for CASSANDRA-5800
Date Fri, 09 Aug 2013 20:56:57 GMT
migrate 1.1 schema_columnfamilies.key_alias column to key_aliases
patch by Alex Liu; reviewed by Tyler Hobbs for CASSANDRA-5800


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

Branch: refs/heads/cassandra-2.0
Commit: fd14512fd2a4e5031ba3d511ba27c113b3087d07
Parents: f5d632f
Author: Jonathan Ellis <jbellis@apache.org>
Authored: Fri Aug 9 15:56:07 2013 -0500
Committer: Jonathan Ellis <jbellis@apache.org>
Committed: Fri Aug 9 15:56:14 2013 -0500

----------------------------------------------------------------------
 CHANGES.txt                                     |  2 ++
 .../org/apache/cassandra/db/SystemTable.java    | 38 ++++++++++++++++++++
 2 files changed, 40 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/fd14512f/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index f8c472c..7630084 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,6 @@
 1.2.9
+ * migrate 1.1 schema_columnfamilies.key_alias column to key_aliases
+   (CASSANDRA-5800)
  * add --migrate option to sstableupgrade and sstablescrub (CASSANDRA-5831)
  * fix bulk-loading compressed sstables (CASSANDRA-5820)
  * (Hadoop) fix quoting in CqlPagingRecordReader and CqlRecordWriter 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/fd14512f/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 318b34d..32f5fe0 100644
--- a/src/java/org/apache/cassandra/db/SystemTable.java
+++ b/src/java/org/apache/cassandra/db/SystemTable.java
@@ -180,6 +180,44 @@ public class SystemTable
             logger.info("Possible old-format hints found. Truncating");
             oldHintsCfs.truncate();
         }
+
+        migrateKeyAliases();
+    }
+
+
+    /**
+     * 1.1 used a key_alias column; 1.2 changed that to key_aliases as part of CQL3
+     */
+    private static void migrateKeyAliases()
+    {
+        for (UntypedResultSet.Row row : processInternal("SELECT keyspace_name, columnfamily_name,
key_aliases, key_alias FROM system.schema_columnfamilies"))
+        {
+            String key_alias = null;
+            String key_aliases = null;
+            try
+            {
+                key_alias = row.getString("key_alias");
+            }
+            catch (NullPointerException e)
+            {
+                // column value is null
+            }
+            try
+            {
+                key_aliases =  row.getString("key_aliases");
+            }
+            catch (NullPointerException e)
+            {
+                // column value is null
+            }
+            if (key_alias != null && key_aliases == null)
+            {
+                String keyspace = row.getString("keyspace_name");
+                String columnfamily = row.getString("columnfamily_name");
+                processInternal(String.format("UPDATE system.schema_columnfamilies set key_aliases='[\"%s\"]'
, key_alias = null where keyspace_name='%s' and columnfamily_name='%s'",
+                                              key_alias, keyspace, columnfamily));
+            }
+        }
     }
 
     public static void saveTruncationRecord(ColumnFamilyStore cfs, long truncatedAt, ReplayPosition
position)


Mime
View raw message