You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by al...@apache.org on 2013/08/12 19:19:31 UTC

[1/3] git commit: CASSANDRA-5800 follow-up

Updated Branches:
  refs/heads/cassandra-2.0 839cc3307 -> 9806b7761


CASSANDRA-5800 follow-up

patch by Aleksey Yeschenko; 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/44925ac7
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/44925ac7
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/44925ac7

Branch: refs/heads/cassandra-2.0
Commit: 44925ac7ea3520bd414d06273cce0edf650d589f
Parents: cb0a0cd
Author: Aleksey Yeschenko <al...@apache.org>
Authored: Mon Aug 12 19:16:01 2013 +0200
Committer: Aleksey Yeschenko <al...@apache.org>
Committed: Mon Aug 12 19:16:01 2013 +0200

----------------------------------------------------------------------
 .../org/apache/cassandra/db/SystemTable.java    | 66 +++++++++++++-------
 1 file changed, 42 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/44925ac7/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 32f5fe0..81e675e 100644
--- a/src/java/org/apache/cassandra/db/SystemTable.java
+++ b/src/java/org/apache/cassandra/db/SystemTable.java
@@ -181,41 +181,59 @@ public class SystemTable
             oldHintsCfs.truncate();
         }
 
-        migrateKeyAliases();
+        migrateKeyAlias();
     }
 
 
     /**
      * 1.1 used a key_alias column; 1.2 changed that to key_aliases as part of CQL3
      */
-    private static void migrateKeyAliases()
+    private static void migrateKeyAlias()
     {
-        for (UntypedResultSet.Row row : processInternal("SELECT keyspace_name, columnfamily_name, key_aliases, key_alias FROM system.schema_columnfamilies"))
+        String selectQuery = String.format("SELECT keyspace_name, columnfamily_name, writetime(type), key_aliases, key_alias FROM %s.%s",
+                                           Table.SYSTEM_KS,
+                                           SCHEMA_COLUMNFAMILIES_CF);
+        for (UntypedResultSet.Row row : processInternal(selectQuery))
         {
-            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)
+            String ks = row.getString("keyspace_name");
+            String cf = row.getString("columnfamily_name");
+            Long timestamp = row.getLong("writetime(type)"); // guaranteed to be present
+
+            String keyAlias = row.has("key_alias") ? row.getString("key_alias") : null;
+            String keyAliases = row.has("key_aliases") ? row.getString("key_aliases") : null;
+
+            if (keyAliases != null)
             {
-                // column value is null
+                if (keyAlias == null)
+                    continue; // key_alias has never existed or has already been migrated - moving on.
+
+                // delete key_alias if it's still there - it's not being used anymore.
+                processInternal(String.format("DELETE key_alias "
+                                              + "FROM %s.%s "
+                                              + "USING TIMESTAMP %d "
+                                              + "WHERE keyspace_name = '%s' AND columnfamily_name = '%s'",
+                                              Table.SYSTEM_KS,
+                                              SCHEMA_COLUMNFAMILIES_CF,
+                                              timestamp,
+                                              ks,
+                                              cf));
             }
-            if (key_alias != null && key_aliases == null)
+            else
             {
-                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));
+                // key_aliases is null. Set to either '[]' or '["<keyAlias>"]', depending on the key_alias (lack of) value.
+                List<String> aliases = keyAlias == null
+                                     ? Collections.<String>emptyList()
+                                     : Collections.singletonList(keyAlias);
+                processInternal(String.format("UPDATE %s.%s "
+                                              + "USING TIMESTAMP %d "
+                                              + "SET key_alias = null, key_aliases = '%s' "
+                                              + "WHERE keyspace_name = '%s' AND columnfamily_name = '%s'",
+                                              Table.SYSTEM_KS,
+                                              SCHEMA_COLUMNFAMILIES_CF,
+                                              timestamp,
+                                              FBUtilities.json(aliases),
+                                              ks,
+                                              cf));
             }
         }
     }


[2/3] git commit: Merge branch 'cassandra-1.2' into cassandra-2.0.0

Posted by al...@apache.org.
Merge branch 'cassandra-1.2' into cassandra-2.0.0

Conflicts:
	src/java/org/apache/cassandra/db/SystemKeyspace.java


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

Branch: refs/heads/cassandra-2.0
Commit: 1716054231398f3804f6d08ab877cc09df190532
Parents: a347900 44925ac
Author: Aleksey Yeschenko <al...@apache.org>
Authored: Mon Aug 12 19:18:28 2013 +0200
Committer: Aleksey Yeschenko <al...@apache.org>
Committed: Mon Aug 12 19:18:28 2013 +0200

----------------------------------------------------------------------
 src/java/org/apache/cassandra/config/CFMetaData.java | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/17160542/src/java/org/apache/cassandra/config/CFMetaData.java
----------------------------------------------------------------------
diff --cc src/java/org/apache/cassandra/config/CFMetaData.java
index 9d116f9,33e3f00..430d26d
--- a/src/java/org/apache/cassandra/config/CFMetaData.java
+++ b/src/java/org/apache/cassandra/config/CFMetaData.java
@@@ -88,82 -79,79 +88,81 @@@ public final class CFMetaDat
      public final static boolean DEFAULT_POPULATE_IO_CACHE_ON_FLUSH = false;
  
      // Note that this is the default only for user created tables
 -    public final static String DEFAULT_COMPRESSOR = SnappyCompressor.isAvailable() ? SnappyCompressor.class.getCanonicalName() : null;
 -
 -    @Deprecated
 -    public static final CFMetaData OldStatusCf = newSystemMetadata(Table.SYSTEM_KS, SystemTable.OLD_STATUS_CF, 0, "unused", BytesType.instance, null);
 -    @Deprecated
 -    public static final CFMetaData OldHintsCf = newSystemMetadata(Table.SYSTEM_KS, SystemTable.OLD_HINTS_CF, 1, "unused", BytesType.instance, BytesType.instance);
 -    @Deprecated
 -    public static final CFMetaData OldMigrationsCf = newSystemMetadata(Table.SYSTEM_KS, DefsTable.OLD_MIGRATIONS_CF, 2, "unused", TimeUUIDType.instance, null);
 -    @Deprecated
 -    public static final CFMetaData OldSchemaCf = newSystemMetadata(Table.SYSTEM_KS, DefsTable.OLD_SCHEMA_CF, 3, "unused", UTF8Type.instance, null);
 -
 -    public static final CFMetaData IndexCf = compile(5, "CREATE TABLE \"" + SystemTable.INDEX_CF + "\" ("
 -                                                        + "table_name text,"
 -                                                        + "index_name text,"
 -                                                        + "PRIMARY KEY (table_name, index_name)"
 -                                                        + ") WITH COMPACT STORAGE AND COMMENT='indexes that have been completed'");
 -
 -    public static final CFMetaData CounterIdCf = compile(6, "CREATE TABLE \"" + SystemTable.COUNTER_ID_CF + "\" ("
 -                                                            + "key text,"
 -                                                            + "id timeuuid,"
 -                                                            + "PRIMARY KEY (key, id)"
 -                                                            + ") WITH COMPACT STORAGE AND COMMENT='counter node IDs'");
 -
 -    // new-style schema
 -    public static final CFMetaData SchemaKeyspacesCf = compile(8, "CREATE TABLE " + SystemTable.SCHEMA_KEYSPACES_CF + "("
 -                                                                  + "keyspace_name text PRIMARY KEY,"
 -                                                                  + "durable_writes boolean,"
 -                                                                  + "strategy_class text,"
 -                                                                  + "strategy_options text"
 -                                                                  + ") WITH COMPACT STORAGE AND COMMENT='keyspace definitions' AND gc_grace_seconds=8640");
 -
 -    public static final CFMetaData SchemaColumnFamiliesCf = compile(9, "CREATE TABLE " + SystemTable.SCHEMA_COLUMNFAMILIES_CF + "("
 -                                                                       + "keyspace_name text,"
 -                                                                       + "columnfamily_name text,"
 -                                                                       + "id int,"
 -                                                                       + "type text,"
 -                                                                       + "comparator text,"
 -                                                                       + "subcomparator text,"
 -                                                                       + "comment text,"
 -                                                                       + "read_repair_chance double,"
 -                                                                       + "local_read_repair_chance double,"
 -                                                                       + "replicate_on_write boolean,"
 -                                                                       + "gc_grace_seconds int,"
 -                                                                       + "default_validator text,"
 -                                                                       + "key_validator text,"
 -                                                                       + "min_compaction_threshold int,"
 -                                                                       + "max_compaction_threshold int,"
 -                                                                       + "key_alias text," // that one is kept for compatibility sake
 -                                                                       + "key_aliases text,"
 -                                                                       + "bloom_filter_fp_chance double,"
 -                                                                       + "caching text,"
 -                                                                       + "populate_io_cache_on_flush boolean,"
 -                                                                       + "compaction_strategy_class text,"
 -                                                                       + "compression_parameters text,"
 -                                                                       + "value_alias text,"
 -                                                                       + "column_aliases text,"
 -                                                                       + "compaction_strategy_options text,"
 -                                                                       + "PRIMARY KEY (keyspace_name, columnfamily_name)"
 -                                                                       + ") WITH COMMENT='ColumnFamily definitions' AND gc_grace_seconds=8640");
 -
 -    public static final CFMetaData SchemaColumnsCf = compile(10, "CREATE TABLE " + SystemTable.SCHEMA_COLUMNS_CF + "("
 -                                                                 + "keyspace_name text,"
 -                                                                 + "columnfamily_name text,"
 -                                                                 + "column_name text,"
 -                                                                 + "validator text,"
 -                                                                 + "index_type text,"
 -                                                                 + "index_options text,"
 -                                                                 + "index_name text,"
 -                                                                 + "component_index int,"
 -                                                                 + "PRIMARY KEY(keyspace_name, columnfamily_name, column_name)"
 -                                                                 + ") WITH COMMENT='ColumnFamily column attributes' AND gc_grace_seconds=8640");
 -
 -    public static final CFMetaData HintsCf = compile("CREATE TABLE " + SystemTable.HINTS_CF + " ("
 +    public final static String DEFAULT_COMPRESSOR = LZ4Compressor.class.getCanonicalName();
 +
 +    public static final CFMetaData IndexCf = compile("CREATE TABLE \"" + SystemKeyspace.INDEX_CF + "\" ("
 +                                                     + "table_name text,"
 +                                                     + "index_name text,"
 +                                                     + "PRIMARY KEY (table_name, index_name)"
 +                                                     + ") WITH COMPACT STORAGE AND COMMENT='indexes that have been completed'");
 +
 +    public static final CFMetaData CounterIdCf = compile("CREATE TABLE \"" + SystemKeyspace.COUNTER_ID_CF + "\" ("
 +                                                         + "key text,"
 +                                                         + "id timeuuid,"
 +                                                         + "PRIMARY KEY (key, id)"
 +                                                         + ") WITH COMPACT STORAGE AND COMMENT='counter node IDs'");
 +
 +    public static final CFMetaData SchemaKeyspacesCf = compile("CREATE TABLE " + SystemKeyspace.SCHEMA_KEYSPACES_CF + " ("
 +                                                               + "keyspace_name text PRIMARY KEY,"
 +                                                               + "durable_writes boolean,"
 +                                                               + "strategy_class text,"
 +                                                               + "strategy_options text"
 +                                                               + ") WITH COMPACT STORAGE AND COMMENT='keyspace definitions' AND gc_grace_seconds=8640");
 +
 +    public static final CFMetaData SchemaColumnFamiliesCf = compile("CREATE TABLE " + SystemKeyspace.SCHEMA_COLUMNFAMILIES_CF + " ("
 +                                                                    + "keyspace_name text,"
 +                                                                    + "columnfamily_name text,"
 +                                                                    + "type text,"
 +                                                                    + "comparator text,"
 +                                                                    + "subcomparator text,"
 +                                                                    + "comment text,"
 +                                                                    + "read_repair_chance double,"
 +                                                                    + "local_read_repair_chance double,"
 +                                                                    + "replicate_on_write boolean,"
 +                                                                    + "gc_grace_seconds int,"
 +                                                                    + "default_validator text,"
 +                                                                    + "key_validator text,"
 +                                                                    + "min_compaction_threshold int,"
 +                                                                    + "max_compaction_threshold int,"
 +                                                                    + "memtable_flush_period_in_ms int,"
-                                                                     + "key_alias text," // that one is kept for compatibility sake
 +                                                                    + "key_aliases text,"
 +                                                                    + "bloom_filter_fp_chance double,"
 +                                                                    + "caching text,"
 +                                                                    + "default_time_to_live int,"
 +                                                                    + "compaction_strategy_class text,"
 +                                                                    + "compression_parameters text,"
 +                                                                    + "value_alias text,"
 +                                                                    + "column_aliases text,"
 +                                                                    + "compaction_strategy_options text,"
 +                                                                    + "speculative_retry text,"
 +                                                                    + "populate_io_cache_on_flush boolean,"
 +                                                                    + "index_interval int,"
 +                                                                    + "dropped_columns map<text, bigint>,"
 +                                                                    + "PRIMARY KEY (keyspace_name, columnfamily_name)"
 +                                                                    + ") WITH COMMENT='ColumnFamily definitions' AND gc_grace_seconds=8640");
 +
 +    public static final CFMetaData SchemaColumnsCf = compile("CREATE TABLE " + SystemKeyspace.SCHEMA_COLUMNS_CF + " ("
 +                                                             + "keyspace_name text,"
 +                                                             + "columnfamily_name text,"
 +                                                             + "column_name text,"
 +                                                             + "validator text,"
 +                                                             + "index_type text,"
 +                                                             + "index_options text,"
 +                                                             + "index_name text,"
 +                                                             + "component_index int,"
 +                                                             + "type text,"
 +                                                             + "PRIMARY KEY(keyspace_name, columnfamily_name, column_name)"
 +                                                             + ") WITH COMMENT='ColumnFamily column attributes' AND gc_grace_seconds=8640");
 +
 +    public static final CFMetaData SchemaTriggersCf = compile("CREATE TABLE " + SystemKeyspace.SCHEMA_TRIGGERS_CF + " ("
 +                                                              + "keyspace_name text,"
 +                                                              + "columnfamily_name text,"
 +                                                              + "trigger_name text,"
 +                                                              + "trigger_options map<text, text>,"
 +                                                              + "PRIMARY KEY (keyspace_name, columnfamily_name, trigger_name)"
 +                                                              + ") WITH COMMENT='triggers metadata table'");
 +
 +    public static final CFMetaData HintsCf = compile("CREATE TABLE " + SystemKeyspace.HINTS_CF + " ("
                                                       + "target_id uuid,"
                                                       + "hint_id timeuuid,"
                                                       + "message_version int,"
@@@ -1561,59 -1395,30 +1560,54 @@@
              cfm.maxCompactionThreshold(result.getInt("max_compaction_threshold"));
              if (result.has("comment"))
                  cfm.comment(result.getString("comment"));
--            // We need support the old key_alias for compatibility sake
 -            if (result.has("key_aliases"))
 -            {
 -                cfm.keyAliases(aliasesFromStrings(fromJsonList(result.getString("key_aliases"))));
 -            }
 -            else if (result.has("key_alias"))
 -            {
 -                cfm.keyAliases(Collections.<ByteBuffer>singletonList(result.getBytes("key_alias")));
 -            }
              if (result.has("bloom_filter_fp_chance"))
                  cfm.bloomFilterFpChance(result.getDouble("bloom_filter_fp_chance"));
 +            if (result.has("memtable_flush_period_in_ms"))
 +                cfm.memtableFlushPeriod(result.getInt("memtable_flush_period_in_ms"));
              cfm.caching(Caching.valueOf(result.getString("caching")));
 +            if (result.has("default_time_to_live"))
 +                cfm.defaultTimeToLive(result.getInt("default_time_to_live"));
 +            if (result.has("speculative_retry"))
 +                cfm.speculativeRetry(SpeculativeRetry.fromString(result.getString("speculative_retry")));
              cfm.compactionStrategyClass(createCompactionStrategy(result.getString("compaction_strategy_class")));
              cfm.compressionParameters(CompressionParameters.create(fromJsonMap(result.getString("compression_parameters"))));
 -            cfm.columnAliases(aliasesFromStrings(fromJsonList(result.getString("column_aliases"))));
 -            if (result.has("value_alias"))
 -                cfm.valueAlias(result.getBytes("value_alias"));
              cfm.compactionStrategyOptions(fromJsonMap(result.getString("compaction_strategy_options")));
 +            if (result.has("index_interval"))
 +            {
 +                cfm.indexInterval(result.getInt("index_interval"));
 +            }
 +            else
 +            {
 +                if (DatabaseDescriptor.getIndexInterval() != null)
 +                {
 +                    // use index_interval set in cassandra.yaml as default value (in memory only)
 +                    cfm.indexInterval(DatabaseDescriptor.getIndexInterval());
 +                }
 +            }
              if (result.has("populate_io_cache_on_flush"))
                  cfm.populateIoCacheOnFlush(result.getBoolean("populate_io_cache_on_flush"));
  
 +            /*
-              * The info previously hold by key_alias(es), column_alias and value_alias is now stored in column_metadata (because 1) this
++             * The info previously hold by key_aliases, column_aliases and value_alias is now stored in column_metadata (because 1) this
 +             * make more sense and 2) this allow to store indexing information).
 +             * However, for upgrade sake we need to still be able to read those old values. Moreover, we cannot easily
 +             * remove those old columns once "converted" to column_metadata because that would screw up nodes that may
 +             * not have upgraded. So for now we keep the both info and in sync, even though its redundant.
 +             * In other words, the ColumnDefinition the following lines add may be replaced later when ColumnDefinition.fromSchema
 +             * is called but that's ok.
 +             */
-             if (result.has("key_aliases"))
-                 cfm.addColumnMetadataFromAliases(aliasesFromStrings(fromJsonList(result.getString("key_aliases"))), cfm.keyValidator, ColumnDefinition.Type.PARTITION_KEY);
-             else if (result.has("key_alias"))
-                 cfm.addColumnMetadataFromAliases(Collections.<ByteBuffer>singletonList(result.getBytes("key_alias")), cfm.keyValidator, ColumnDefinition.Type.PARTITION_KEY);
- 
++            cfm.addColumnMetadataFromAliases(aliasesFromStrings(fromJsonList(result.getString("key_aliases"))), cfm.keyValidator, ColumnDefinition.Type.PARTITION_KEY);
 +            cfm.addColumnMetadataFromAliases(aliasesFromStrings(fromJsonList(result.getString("column_aliases"))), cfm.comparator, ColumnDefinition.Type.CLUSTERING_KEY);
 +
 +            if (result.has("value_alias"))
 +                cfm.addColumnMetadataFromAliases(Collections.<ByteBuffer>singletonList(result.getBytes("value_alias")), cfm.defaultValidator, ColumnDefinition.Type.COMPACT_VALUE);
 +
 +            if (result.has("dropped_columns"))
 +                cfm.droppedColumns(convertDroppedColumns(result.getMap("dropped_columns", UTF8Type.instance, LongType.instance)));
 +
              return cfm;
          }
 -        catch (SyntaxException e)
 +        catch (SyntaxException | ConfigurationException e)
          {
              throw new RuntimeException(e);
          }


[3/3] git commit: Merge branch 'cassandra-2.0.0' into cassandra-2.0

Posted by al...@apache.org.
Merge branch 'cassandra-2.0.0' into cassandra-2.0


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

Branch: refs/heads/cassandra-2.0
Commit: 9806b7761fa035665959bc3a7434d535021c7d7d
Parents: 839cc33 1716054
Author: Aleksey Yeschenko <al...@apache.org>
Authored: Mon Aug 12 19:19:24 2013 +0200
Committer: Aleksey Yeschenko <al...@apache.org>
Committed: Mon Aug 12 19:19:24 2013 +0200

----------------------------------------------------------------------
 src/java/org/apache/cassandra/config/CFMetaData.java | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
----------------------------------------------------------------------