mirror of https://github.com/apache/cassandra
Remove post-2.1 dead schema migrations and columns
This commit is contained in:
parent
58fdc6b5c0
commit
cbbc1191ce
|
|
@ -130,11 +130,7 @@ public class CachingOptions
|
|||
return result;
|
||||
}
|
||||
|
||||
public static boolean isLegacy(String CachingOptions)
|
||||
{
|
||||
return legacyOptions.contains(CachingOptions.toUpperCase());
|
||||
}
|
||||
|
||||
// FIXME: move to ThriftConversion
|
||||
public static CachingOptions fromThrift(String caching, String cellsPerRow) throws ConfigurationException
|
||||
{
|
||||
|
||||
|
|
@ -153,6 +149,7 @@ public class CachingOptions
|
|||
return new CachingOptions(kc, rc);
|
||||
}
|
||||
|
||||
// FIXME: move to ThriftConversion
|
||||
public String toThriftCaching()
|
||||
{
|
||||
if (rowCache.isEnabled() && keyCache.isEnabled())
|
||||
|
|
@ -164,6 +161,7 @@ public class CachingOptions
|
|||
return "NONE";
|
||||
}
|
||||
|
||||
// FIXME: move to ThriftConversion
|
||||
public String toThriftCellsPerRow()
|
||||
{
|
||||
if (rowCache.cacheFullPartitions())
|
||||
|
|
@ -171,7 +169,6 @@ public class CachingOptions
|
|||
return String.valueOf(rowCache.rowsToCache);
|
||||
}
|
||||
|
||||
|
||||
public static class KeyCache
|
||||
{
|
||||
public final Type type;
|
||||
|
|
|
|||
|
|
@ -54,7 +54,6 @@ import org.apache.cassandra.utils.ByteBufferUtil;
|
|||
import org.apache.cassandra.utils.FBUtilities;
|
||||
import org.apache.cassandra.utils.UUIDGen;
|
||||
|
||||
import static org.apache.cassandra.utils.FBUtilities.fromJsonList;
|
||||
import static org.apache.cassandra.utils.FBUtilities.fromJsonMap;
|
||||
import static org.apache.cassandra.utils.FBUtilities.json;
|
||||
|
||||
|
|
@ -1251,7 +1250,6 @@ public final class CFMetaData
|
|||
adder.add("min_compaction_threshold", minCompactionThreshold);
|
||||
adder.add("max_compaction_threshold", maxCompactionThreshold);
|
||||
adder.add("bloom_filter_fp_chance", getBloomFilterFpChance());
|
||||
|
||||
adder.add("memtable_flush_period_in_ms", memtableFlushPeriod);
|
||||
adder.add("caching", caching.toString());
|
||||
adder.add("default_time_to_live", defaultTimeToLive);
|
||||
|
|
@ -1260,18 +1258,12 @@ public final class CFMetaData
|
|||
adder.add("compaction_strategy_options", json(compactionStrategyOptions));
|
||||
adder.add("min_index_interval", minIndexInterval);
|
||||
adder.add("max_index_interval", maxIndexInterval);
|
||||
adder.add("index_interval", null);
|
||||
adder.add("speculative_retry", speculativeRetry.toString());
|
||||
|
||||
for (Map.Entry<ColumnIdentifier, Long> entry : droppedColumns.entrySet())
|
||||
adder.addMapEntry("dropped_columns", entry.getKey().toString(), entry.getValue());
|
||||
|
||||
adder.add("is_dense", isDense);
|
||||
|
||||
// Save the CQL3 metadata "the old way" for compatibility sake
|
||||
adder.add("key_aliases", aliasesToJson(partitionKeyColumns));
|
||||
adder.add("column_aliases", aliasesToJson(clusteringColumns));
|
||||
adder.add("value_alias", compactValueColumn == null ? null : compactValueColumn.name.toString());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
|
@ -1328,11 +1320,9 @@ public final class CFMetaData
|
|||
cfm.compressionParameters(CompressionParameters.create(fromJsonMap(result.getString("compression_parameters"))));
|
||||
cfm.compactionStrategyOptions(fromJsonMap(result.getString("compaction_strategy_options")));
|
||||
|
||||
// migrate old index_interval values to min_index_interval, if present
|
||||
if (result.has("min_index_interval"))
|
||||
cfm.minIndexInterval(result.getInt("min_index_interval"));
|
||||
else if (result.has("index_interval"))
|
||||
cfm.minIndexInterval(result.getInt("index_interval"));
|
||||
|
||||
if (result.has("max_index_interval"))
|
||||
cfm.maxIndexInterval(result.getInt("max_index_interval"));
|
||||
|
||||
|
|
@ -1341,20 +1331,6 @@ public final class CFMetaData
|
|||
else
|
||||
cfm.bloomFilterFpChance(cfm.getBloomFilterFpChance());
|
||||
|
||||
/*
|
||||
* The info previously hold by key_aliases, column_aliases and value_alias is now stored in columnMetadata (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 columnMetadata 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.
|
||||
*/
|
||||
if (result.has("key_aliases"))
|
||||
cfm.addColumnMetadataFromAliases(aliasesFromStrings(fromJsonList(result.getString("key_aliases"))), cfm.keyValidator, ColumnDefinition.Kind.PARTITION_KEY);
|
||||
if (result.has("column_aliases"))
|
||||
cfm.addColumnMetadataFromAliases(aliasesFromStrings(fromJsonList(result.getString("column_aliases"))), cfm.comparator.asAbstractType(), ColumnDefinition.Kind.CLUSTERING_COLUMN);
|
||||
if (result.has("value_alias"))
|
||||
cfm.addColumnMetadataFromAliases(Collections.singletonList(result.getBytes("value_alias")), cfm.defaultValidator, ColumnDefinition.Kind.COMPACT_VALUE);
|
||||
|
||||
if (result.has("dropped_columns"))
|
||||
cfm.droppedColumns(convertDroppedColumns(result.getMap("dropped_columns", UTF8Type.instance, LongType.instance)));
|
||||
|
||||
|
|
@ -1415,25 +1391,6 @@ public final class CFMetaData
|
|||
return fromSchema(result);
|
||||
}
|
||||
|
||||
private String aliasesToJson(List<ColumnDefinition> rawAliases)
|
||||
{
|
||||
if (rawAliases == null)
|
||||
return null;
|
||||
|
||||
List<String> aliases = new ArrayList<>(rawAliases.size());
|
||||
for (ColumnDefinition rawAlias : rawAliases)
|
||||
aliases.add(rawAlias.name.toString());
|
||||
return json(aliases);
|
||||
}
|
||||
|
||||
private static List<ByteBuffer> aliasesFromStrings(List<String> aliases)
|
||||
{
|
||||
List<ByteBuffer> rawAliases = new ArrayList<>(aliases.size());
|
||||
for (String alias : aliases)
|
||||
rawAliases.add(UTF8Type.instance.decompose(alias));
|
||||
return rawAliases;
|
||||
}
|
||||
|
||||
private static Map<ColumnIdentifier, Long> convertDroppedColumns(Map<String, Long> raw)
|
||||
{
|
||||
Map<ColumnIdentifier, Long> converted = Maps.newHashMap();
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@ import com.google.common.collect.Sets;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.apache.cassandra.cache.CachingOptions;
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.config.KSMetaData;
|
||||
|
|
@ -119,7 +118,6 @@ public final class SystemKeyspace
|
|||
+ "bloom_filter_fp_chance double,"
|
||||
+ "caching text,"
|
||||
+ "cf_id uuid," // post-2.1 UUID cfid
|
||||
+ "column_aliases text,"
|
||||
+ "comment text,"
|
||||
+ "compaction_strategy_class text,"
|
||||
+ "compaction_strategy_options text,"
|
||||
|
|
@ -129,9 +127,7 @@ public final class SystemKeyspace
|
|||
+ "default_validator text,"
|
||||
+ "dropped_columns map<text, bigint>,"
|
||||
+ "gc_grace_seconds int,"
|
||||
+ "index_interval int,"
|
||||
+ "is_dense boolean,"
|
||||
+ "key_aliases text,"
|
||||
+ "key_validator text,"
|
||||
+ "local_read_repair_chance double,"
|
||||
+ "max_compaction_threshold int,"
|
||||
|
|
@ -143,7 +139,6 @@ public final class SystemKeyspace
|
|||
+ "speculative_retry text,"
|
||||
+ "subcomparator text,"
|
||||
+ "type text,"
|
||||
+ "value_alias text,"
|
||||
+ "PRIMARY KEY ((keyspace_name), columnfamily_name))")
|
||||
.gcGraceSeconds(WEEK);
|
||||
|
||||
|
|
@ -370,16 +365,11 @@ public final class SystemKeyspace
|
|||
{
|
||||
setupVersion();
|
||||
|
||||
migrateIndexInterval();
|
||||
migrateCachingOption();
|
||||
// add entries to system schema columnfamilies for the hardcoded system definitions
|
||||
KSMetaData ksmd = Schema.instance.getKSMetaData(NAME);
|
||||
|
||||
// delete old, possibly obsolete entries in schema tables
|
||||
// FIXME: once schema_functions moves from 'namespace' to 'keyspace_name', fix this
|
||||
List<String> schemaTables = new ArrayList<>(ALL_SCHEMA_TABLES);
|
||||
schemaTables.remove(SCHEMA_FUNCTIONS_TABLE);
|
||||
for (String table : schemaTables)
|
||||
for (String table : ALL_SCHEMA_TABLES)
|
||||
executeOnceInternal(String.format("DELETE FROM system.%s WHERE keyspace_name = ?", table), ksmd.name);
|
||||
|
||||
// (+1 to timestamp to make sure we don't get shadowed by the tombstones we just added)
|
||||
|
|
@ -401,56 +391,6 @@ public final class SystemKeyspace
|
|||
DatabaseDescriptor.getPartitioner().getClass().getName());
|
||||
}
|
||||
|
||||
// TODO: In 3.0, remove this and the index_interval column from system.schema_columnfamilies
|
||||
/** Migrates index_interval values to min_index_interval and sets index_interval to null */
|
||||
private static void migrateIndexInterval()
|
||||
{
|
||||
for (UntypedResultSet.Row row : executeOnceInternal(String.format("SELECT * FROM system.%s", SCHEMA_COLUMNFAMILIES_TABLE)))
|
||||
{
|
||||
if (!row.has("index_interval"))
|
||||
continue;
|
||||
|
||||
logger.debug("Migrating index_interval to min_index_interval");
|
||||
|
||||
CFMetaData table = CFMetaData.fromSchema(row);
|
||||
String query = String.format("SELECT writetime(type) FROM system.%s WHERE keyspace_name = ? AND columnfamily_name = ?", SCHEMA_COLUMNFAMILIES_TABLE);
|
||||
long timestamp = executeOnceInternal(query, table.ksName, table.cfName).one().getLong("writetime(type)");
|
||||
try
|
||||
{
|
||||
table.toSchema(timestamp).apply();
|
||||
}
|
||||
catch (ConfigurationException e)
|
||||
{
|
||||
// shouldn't happen
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void migrateCachingOption()
|
||||
{
|
||||
for (UntypedResultSet.Row row : executeOnceInternal(String.format("SELECT * FROM system.%s", SCHEMA_COLUMNFAMILIES_TABLE)))
|
||||
{
|
||||
if (!row.has("caching"))
|
||||
continue;
|
||||
|
||||
if (!CachingOptions.isLegacy(row.getString("caching")))
|
||||
continue;
|
||||
try
|
||||
{
|
||||
CachingOptions caching = CachingOptions.fromString(row.getString("caching"));
|
||||
CFMetaData table = CFMetaData.fromSchema(row);
|
||||
logger.info("Migrating caching option {} to {} for {}.{}", row.getString("caching"), caching.toString(), table.ksName, table.cfName);
|
||||
String query = String.format("SELECT writetime(type) FROM system.%s WHERE keyspace_name = ? AND columnfamily_name = ?", SCHEMA_COLUMNFAMILIES_TABLE);
|
||||
long timestamp = executeOnceInternal(query, table.ksName, table.cfName).one().getLong("writetime(type)");
|
||||
table.toSchema(timestamp).apply();
|
||||
}
|
||||
catch (ConfigurationException e)
|
||||
{
|
||||
// shouldn't happen
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write compaction log, except columfamilies under system keyspace.
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue