mirror of https://github.com/apache/cassandra
Refactoring of the DatabaseDescriptor/CFMetadata/Table to support o.a.c.config.Schema which will be handling all schema quering/mutations
patch by Pavel Yaskevich; reviewed by Jonathan Ellis for CASSANDRA-1391 git-svn-id: https://svn.apache.org/repos/asf/cassandra/trunk@1160494 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
11b1a2b03f
commit
7b532bcada
|
|
@ -27,6 +27,7 @@ import java.util.concurrent.Future;
|
|||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.cassandra.config.Schema;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
@ -68,7 +69,7 @@ public abstract class AutoSavingCache<K, V> extends InstrumentingCache<K, V>
|
|||
|
||||
public int getAdjustedCacheSize(long expectedKeys)
|
||||
{
|
||||
CFMetaData cfm = DatabaseDescriptor.getCFMetaData(tableName, cfName);
|
||||
CFMetaData cfm = Schema.instance.getCFMetaData(tableName, cfName);
|
||||
return (int)Math.min(FBUtilities.absoluteFromFraction(getConfiguredCacheSize(cfm), expectedKeys), Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,10 +20,7 @@ package org.apache.cassandra.config;
|
|||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
|
|
@ -50,7 +47,6 @@ import org.apache.cassandra.io.SerDeUtils;
|
|||
import org.apache.cassandra.thrift.InvalidRequestException;
|
||||
import org.apache.cassandra.utils.ByteBufferUtil;
|
||||
import org.apache.cassandra.utils.FBUtilities;
|
||||
import org.apache.cassandra.utils.Pair;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
|
@ -82,11 +78,6 @@ public final class CFMetaData
|
|||
public final static ByteBuffer DEFAULT_KEY_NAME = ByteBufferUtil.bytes("KEY");
|
||||
public final static boolean DEFAULT_COMPRESSION = false;
|
||||
|
||||
private static final int MIN_CF_ID = 1000;
|
||||
private static final AtomicInteger idGen = new AtomicInteger(MIN_CF_ID);
|
||||
|
||||
private static final BiMap<Pair<String, String>, Integer> cfIdMap = HashBiMap.create();
|
||||
|
||||
public static final CFMetaData StatusCf = newSystemMetadata(SystemTable.STATUS_CF, 0, "persistent metadata for the local node", BytesType.instance, null, DEFAULT_SYSTEM_MEMTABLE_THROUGHPUT_IN_MB);
|
||||
public static final CFMetaData HintsCf = newSystemMetadata(HintedHandOffManager.HINTS_CF, 1, "hinted handoff data", BytesType.instance, BytesType.instance, Math.min(256, Math.max(32, DEFAULT_MEMTABLE_THROUGHPUT_IN_MB / 2)));
|
||||
public static final CFMetaData MigrationsCf = newSystemMetadata(Migration.MIGRATIONS_CF, 2, "individual schema mutations", TimeUUIDType.instance, null, DEFAULT_SYSTEM_MEMTABLE_THROUGHPUT_IN_MB);
|
||||
|
|
@ -110,41 +101,6 @@ public final class CFMetaData
|
|||
return 0.3 * mem_throughput / 64.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The (ksname,cfname) pair for the given id, or null if it has been dropped.
|
||||
*/
|
||||
public static Pair<String,String> getCF(Integer cfId)
|
||||
{
|
||||
return cfIdMap.inverse().get(cfId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The id for the given (ksname,cfname) pair, or null if it has been dropped.
|
||||
*/
|
||||
public static Integer getId(String ksName, String cfName)
|
||||
{
|
||||
return cfIdMap.get(new Pair<String, String>(ksName, cfName));
|
||||
}
|
||||
|
||||
// this gets called after initialization to make sure that id generation happens properly.
|
||||
public static void fixMaxId()
|
||||
{
|
||||
// never set it to less than 1000. this ensures that we have enough system CFids for future use.
|
||||
idGen.set(cfIdMap.size() == 0 ? MIN_CF_ID : Math.max(Collections.max(cfIdMap.values()) + 1, MIN_CF_ID));
|
||||
}
|
||||
|
||||
/** adds this cfm to the map. */
|
||||
public static void map(CFMetaData cfm) throws ConfigurationException
|
||||
{
|
||||
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.");
|
||||
else
|
||||
{
|
||||
cfIdMap.put(key, cfm.cfId);
|
||||
}
|
||||
}
|
||||
|
||||
//REQUIRED
|
||||
public final Integer cfId; // internal id, never exposed to user
|
||||
public final String ksName; // name of keyspace
|
||||
|
|
@ -203,7 +159,7 @@ public final class CFMetaData
|
|||
|
||||
public CFMetaData(String keyspace, String name, ColumnFamilyType type, AbstractType comp, AbstractType subcc)
|
||||
{
|
||||
this(keyspace, name, type, comp, subcc, nextId());
|
||||
this(keyspace, name, type, comp, subcc, Schema.instance.nextCFId());
|
||||
}
|
||||
|
||||
private CFMetaData(String keyspace, String name, ColumnFamilyType type, AbstractType comp, AbstractType subcc, int id)
|
||||
|
|
@ -335,12 +291,6 @@ public final class CFMetaData
|
|||
.compactionStrategyOptions(oldCFMD.compactionStrategyOptions)
|
||||
.compression(oldCFMD.compression);
|
||||
}
|
||||
|
||||
/** used for evicting cf data out of static tracking collections. */
|
||||
public static void purge(CFMetaData cfm)
|
||||
{
|
||||
cfIdMap.remove(new Pair<String, String>(cfm.ksName, cfm.cfName));
|
||||
}
|
||||
|
||||
/**
|
||||
* generate a column family name for an index corresponding to the given column.
|
||||
|
|
@ -673,11 +623,6 @@ public final class CFMetaData
|
|||
.toHashCode();
|
||||
}
|
||||
|
||||
private static int nextId()
|
||||
{
|
||||
return idGen.getAndIncrement();
|
||||
}
|
||||
|
||||
public AbstractType getValueValidator(ByteBuffer column)
|
||||
{
|
||||
return getValueValidator(column_metadata.get(column));
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ import java.io.*;
|
|||
import java.net.InetAddress;
|
||||
import java.net.URL;
|
||||
import java.net.UnknownHostException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.*;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
|
@ -34,15 +33,10 @@ import org.apache.cassandra.auth.IAuthenticator;
|
|||
import org.apache.cassandra.auth.IAuthority;
|
||||
import org.apache.cassandra.config.Config.RequestSchedulerId;
|
||||
import org.apache.cassandra.db.ColumnFamilyStore;
|
||||
import org.apache.cassandra.db.ColumnFamilyType;
|
||||
import org.apache.cassandra.db.DefsTable;
|
||||
import org.apache.cassandra.db.Table;
|
||||
import org.apache.cassandra.db.marshal.AbstractType;
|
||||
import org.apache.cassandra.db.migration.Migration;
|
||||
import org.apache.cassandra.dht.IPartitioner;
|
||||
import org.apache.cassandra.gms.Gossiper;
|
||||
import org.apache.cassandra.gms.VersionedValue;
|
||||
import org.apache.cassandra.io.sstable.Descriptor;
|
||||
import org.apache.cassandra.io.util.FileUtils;
|
||||
import org.apache.cassandra.io.util.MmappedSegmentedFile;
|
||||
import org.apache.cassandra.locator.*;
|
||||
|
|
@ -50,7 +44,7 @@ import org.apache.cassandra.scheduler.IRequestScheduler;
|
|||
import org.apache.cassandra.scheduler.NoScheduler;
|
||||
import org.apache.cassandra.thrift.CassandraDaemon;
|
||||
import org.apache.cassandra.utils.FBUtilities;
|
||||
import org.apache.cassandra.utils.Pair;
|
||||
|
||||
import org.yaml.snakeyaml.Loader;
|
||||
import org.yaml.snakeyaml.TypeDescription;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
|
@ -68,8 +62,6 @@ public class DatabaseDescriptor
|
|||
/* Current index into the above list of directories */
|
||||
private static int currentIndex = 0;
|
||||
|
||||
static Map<String, KSMetaData> tables = new HashMap<String, KSMetaData>();
|
||||
|
||||
/* Hashing strategy Random or OPHF */
|
||||
private static IPartitioner partitioner;
|
||||
|
||||
|
|
@ -86,9 +78,6 @@ public class DatabaseDescriptor
|
|||
private static RequestSchedulerId requestSchedulerId;
|
||||
private static RequestSchedulerOptions requestSchedulerOptions;
|
||||
|
||||
public static final UUID INITIAL_VERSION = new UUID(4096, 0); // has type nibble set to 1, everything else to zero.
|
||||
private static volatile UUID defsVersion = INITIAL_VERSION;
|
||||
|
||||
/**
|
||||
* Inspect the classpath to find storage configuration file
|
||||
*/
|
||||
|
|
@ -414,13 +403,14 @@ public class DatabaseDescriptor
|
|||
CFMetaData.SchemaCf,
|
||||
CFMetaData.IndexCf,
|
||||
CFMetaData.NodeIdCf);
|
||||
CFMetaData.map(CFMetaData.StatusCf);
|
||||
CFMetaData.map(CFMetaData.HintsCf);
|
||||
CFMetaData.map(CFMetaData.MigrationsCf);
|
||||
CFMetaData.map(CFMetaData.SchemaCf);
|
||||
CFMetaData.map(CFMetaData.IndexCf);
|
||||
CFMetaData.map(CFMetaData.NodeIdCf);
|
||||
tables.put(Table.SYSTEM_TABLE, systemMeta);
|
||||
Schema.instance.load(CFMetaData.StatusCf);
|
||||
Schema.instance.load(CFMetaData.HintsCf);
|
||||
Schema.instance.load(CFMetaData.MigrationsCf);
|
||||
Schema.instance.load(CFMetaData.SchemaCf);
|
||||
Schema.instance.load(CFMetaData.IndexCf);
|
||||
Schema.instance.load(CFMetaData.NodeIdCf);
|
||||
|
||||
Schema.instance.addSystemTable(systemMeta);
|
||||
|
||||
/* Load the seeds for node contact points */
|
||||
if (conf.seed_provider == null)
|
||||
|
|
@ -474,7 +464,7 @@ public class DatabaseDescriptor
|
|||
logger.info("Couldn't detect any schema definitions in local storage.");
|
||||
// peek around the data directories to see if anything is there.
|
||||
boolean hasExistingTables = false;
|
||||
for (String dataDir : DatabaseDescriptor.getAllDataFileLocations())
|
||||
for (String dataDir : getAllDataFileLocations())
|
||||
{
|
||||
File dataPath = new File(dataDir);
|
||||
if (dataPath.exists() && dataPath.isDirectory())
|
||||
|
|
@ -505,35 +495,21 @@ public class DatabaseDescriptor
|
|||
{
|
||||
logger.info("Loading schema version " + uuid.toString());
|
||||
Collection<KSMetaData> tableDefs = DefsTable.loadFromStorage(uuid);
|
||||
for (KSMetaData def : tableDefs)
|
||||
{
|
||||
if (!def.name.matches(Migration.NAME_VALIDATOR_REGEX))
|
||||
throw new RuntimeException("invalid keyspace name: " + def.name);
|
||||
for (CFMetaData cfm : def.cfMetaData().values())
|
||||
{
|
||||
if (!cfm.cfName.matches(Migration.NAME_VALIDATOR_REGEX))
|
||||
throw new RuntimeException("invalid column family name: " + cfm.cfName);
|
||||
try
|
||||
{
|
||||
CFMetaData.map(cfm);
|
||||
}
|
||||
catch (ConfigurationException ex)
|
||||
{
|
||||
throw new IOError(ex);
|
||||
}
|
||||
}
|
||||
DatabaseDescriptor.setTableDefinition(def, uuid);
|
||||
}
|
||||
|
||||
|
||||
// happens when someone manually deletes all tables and restarts.
|
||||
if (tableDefs.size() == 0)
|
||||
{
|
||||
logger.warn("No schema definitions were found in local storage.");
|
||||
// set defsVersion so that migrations leading up to emptiness aren't replayed.
|
||||
defsVersion = uuid;
|
||||
// set version so that migrations leading up to emptiness aren't replayed.
|
||||
Schema.instance.setVersion(uuid);
|
||||
}
|
||||
else // if non-system tables where found, trying to load them
|
||||
{
|
||||
Schema.instance.load(tableDefs, uuid);
|
||||
}
|
||||
}
|
||||
CFMetaData.fixMaxId();
|
||||
|
||||
Schema.instance.fixCFMaxId();
|
||||
}
|
||||
|
||||
public static IAuthenticator getAuthenticator()
|
||||
|
|
@ -616,12 +592,6 @@ public class DatabaseDescriptor
|
|||
return requestSchedulerId;
|
||||
}
|
||||
|
||||
public static KSMetaData getKSMetaData(String table)
|
||||
{
|
||||
assert table != null;
|
||||
return tables.get(table);
|
||||
}
|
||||
|
||||
public static String getJobTrackerAddress()
|
||||
{
|
||||
return conf.job_tracker_host;
|
||||
|
|
@ -646,58 +616,6 @@ public class DatabaseDescriptor
|
|||
{
|
||||
return conf.job_jar_file_location;
|
||||
}
|
||||
|
||||
public static Map<String, CFMetaData> getTableMetaData(String tableName)
|
||||
{
|
||||
assert tableName != null;
|
||||
KSMetaData ksm = tables.get(tableName);
|
||||
assert ksm != null;
|
||||
return ksm.cfMetaData();
|
||||
}
|
||||
|
||||
/*
|
||||
* Given a table name & column family name, get the column family
|
||||
* meta data. If the table name or column family name is not valid
|
||||
* this function returns null.
|
||||
*/
|
||||
public static CFMetaData getCFMetaData(String tableName, String cfName)
|
||||
{
|
||||
assert tableName != null;
|
||||
KSMetaData ksm = tables.get(tableName);
|
||||
if (ksm == null)
|
||||
return null;
|
||||
return ksm.cfMetaData().get(cfName);
|
||||
}
|
||||
|
||||
public static CFMetaData getCFMetaData(Integer cfId)
|
||||
{
|
||||
Pair<String,String> cf = CFMetaData.getCF(cfId);
|
||||
if (cf == null)
|
||||
return null;
|
||||
return getCFMetaData(cf.left, cf.right);
|
||||
}
|
||||
|
||||
public static ColumnFamilyType getColumnFamilyType(String tableName, String cfName)
|
||||
{
|
||||
assert tableName != null && cfName != null;
|
||||
CFMetaData cfMetaData = getCFMetaData(tableName, cfName);
|
||||
|
||||
if (cfMetaData == null)
|
||||
return null;
|
||||
return cfMetaData.cfType;
|
||||
}
|
||||
|
||||
public static Set<String> getTables()
|
||||
{
|
||||
return tables.keySet();
|
||||
}
|
||||
|
||||
public static List<String> getNonSystemTables()
|
||||
{
|
||||
List<String> tableslist = new ArrayList<String>(tables.keySet());
|
||||
tableslist.remove(Table.SYSTEM_TABLE);
|
||||
return Collections.unmodifiableList(tableslist);
|
||||
}
|
||||
|
||||
public static int getStoragePort()
|
||||
{
|
||||
|
|
@ -847,46 +765,6 @@ public class DatabaseDescriptor
|
|||
}
|
||||
return dataFileDirectory;
|
||||
}
|
||||
|
||||
public static AbstractType getComparator(String ksName, String cfName)
|
||||
{
|
||||
assert ksName != null;
|
||||
CFMetaData cfmd = getCFMetaData(ksName, cfName);
|
||||
if (cfmd == null)
|
||||
throw new IllegalArgumentException("Unknown ColumnFamily " + cfName + " in keyspace " + ksName);
|
||||
return cfmd.comparator;
|
||||
}
|
||||
|
||||
public static AbstractType getSubComparator(String tableName, String cfName)
|
||||
{
|
||||
assert tableName != null;
|
||||
return getCFMetaData(tableName, cfName).subcolumnComparator;
|
||||
}
|
||||
|
||||
public static KSMetaData getTableDefinition(String table)
|
||||
{
|
||||
return tables.get(table);
|
||||
}
|
||||
|
||||
// todo: this is wrong. the definitions need to be moved into their own class that can only be updated by the
|
||||
// process of mutating an individual keyspace, rather than setting manually here.
|
||||
public static void setTableDefinition(KSMetaData ksm, UUID newVersion)
|
||||
{
|
||||
if (ksm != null)
|
||||
tables.put(ksm.name, ksm);
|
||||
DatabaseDescriptor.defsVersion = newVersion;
|
||||
}
|
||||
|
||||
public static void clearTableDefinition(KSMetaData ksm, UUID newVersion)
|
||||
{
|
||||
tables.remove(ksm.name);
|
||||
DatabaseDescriptor.defsVersion = newVersion;
|
||||
}
|
||||
|
||||
public static UUID getDefsVersion()
|
||||
{
|
||||
return defsVersion;
|
||||
}
|
||||
|
||||
public static InetAddress getListenAddress()
|
||||
{
|
||||
|
|
@ -997,16 +875,6 @@ public class DatabaseDescriptor
|
|||
return conf.max_hint_window_in_ms;
|
||||
}
|
||||
|
||||
public static AbstractType getValueValidator(String keyspace, String cf, ByteBuffer column)
|
||||
{
|
||||
return getCFMetaData(keyspace, cf).getValueValidator(column);
|
||||
}
|
||||
|
||||
public static CFMetaData getCFMetaData(Descriptor desc)
|
||||
{
|
||||
return getCFMetaData(desc.ksname, desc.cfname);
|
||||
}
|
||||
|
||||
public static Integer getIndexInterval()
|
||||
{
|
||||
return conf.index_interval;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,428 @@
|
|||
/**
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* 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.config;
|
||||
|
||||
import java.io.IOError;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.apache.cassandra.db.ColumnFamilyType;
|
||||
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;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import org.cliffc.high_scale_lib.NonBlockingHashMap;
|
||||
|
||||
public class Schema
|
||||
{
|
||||
public static final UUID INITIAL_VERSION = new UUID(4096, 0); // has type nibble set to 1, everything else to zero.
|
||||
|
||||
public static final Schema instance = new Schema(INITIAL_VERSION);
|
||||
|
||||
private static final int MIN_CF_ID = 1000;
|
||||
private final AtomicInteger cfIdGen = new AtomicInteger(MIN_CF_ID);
|
||||
|
||||
/* metadata map for faster table lookup */
|
||||
private final Map<String, KSMetaData> tables;
|
||||
|
||||
/* Table objects, one per keyspace. Only one instance should ever exist for any given keyspace. */
|
||||
private final Map<String, Table> tableInstances;
|
||||
|
||||
/* metadata map for faster ColumnFamily lookup */
|
||||
private final BiMap<Pair<String, String>, Integer> cfIdMap;
|
||||
|
||||
private volatile UUID version;
|
||||
|
||||
/**
|
||||
* Initialize empty schema object with given version
|
||||
* @param initialVersion The initial version of the schema
|
||||
*/
|
||||
public Schema(UUID initialVersion)
|
||||
{
|
||||
tables = new HashMap<String, KSMetaData>();
|
||||
tableInstances = new NonBlockingHashMap<String, Table>();
|
||||
cfIdMap = HashBiMap.create();
|
||||
version = initialVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load up non-system tables and set schema version to the given value
|
||||
*
|
||||
* @param tableDefs The non-system table definitions
|
||||
* @param version The version of the schema
|
||||
*
|
||||
* @return self to support chaining calls
|
||||
*/
|
||||
public Schema load(Collection<KSMetaData> tableDefs, UUID version)
|
||||
{
|
||||
for (KSMetaData def : tableDefs)
|
||||
{
|
||||
if (!Migration.isLegalName(def.name))
|
||||
throw new RuntimeException("invalid keyspace name: " + def.name);
|
||||
|
||||
for (CFMetaData cfm : def.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);
|
||||
}
|
||||
}
|
||||
|
||||
setTableDefinition(def, version);
|
||||
}
|
||||
|
||||
setVersion(version);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get table instance by name
|
||||
*
|
||||
* @param tableName The name of the table
|
||||
*
|
||||
* @return Table object or null if table was not found
|
||||
*/
|
||||
public Table getTableInstance(String tableName)
|
||||
{
|
||||
return tableInstances.get(tableName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store given Table instance to the schema
|
||||
*
|
||||
* @param table The Table instance to store
|
||||
*
|
||||
* @throws IllegalArgumentException if Table is already stored
|
||||
*/
|
||||
public void storeTableInstance(Table table)
|
||||
{
|
||||
if (tableInstances.containsKey(table.name))
|
||||
throw new IllegalArgumentException(String.format("Table %s was already initialized.", table.name));
|
||||
|
||||
tableInstances.put(table.name, table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove table from schema
|
||||
*
|
||||
* @param tableName The name of the table to remove
|
||||
*
|
||||
* @return removed table instance or null if it wasn't found
|
||||
*/
|
||||
public Table removeTableInstance(String tableName)
|
||||
{
|
||||
return tableInstances.remove(tableName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove table definition from system and update schema version
|
||||
*
|
||||
* @param ksm The table definition to remove
|
||||
* @param newVersion New version of the system
|
||||
*/
|
||||
public void clearTableDefinition(KSMetaData ksm, UUID newVersion)
|
||||
{
|
||||
tables.remove(ksm.name);
|
||||
version = newVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a table name & column family name, get the column family
|
||||
* meta data. If the table name or column family name is not valid
|
||||
* this function returns null.
|
||||
*
|
||||
* @param tableName The table name
|
||||
* @param cfName The ColumnFamily name
|
||||
*
|
||||
* @return ColumnFamily Metadata object or null if it wasn't found
|
||||
*/
|
||||
public CFMetaData getCFMetaData(String tableName, String cfName)
|
||||
{
|
||||
assert tableName != null;
|
||||
KSMetaData ksm = tables.get(tableName);
|
||||
return (ksm == null) ? null : ksm.cfMetaData().get(cfName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ColumnFamily metadata by its identifier
|
||||
*
|
||||
* @param cfId The ColumnFamily identifier
|
||||
*
|
||||
* @return metadata about ColumnFamily
|
||||
*/
|
||||
public CFMetaData getCFMetaData(Integer cfId)
|
||||
{
|
||||
Pair<String,String> cf = getCF(cfId);
|
||||
return (cf == null) ? null : getCFMetaData(cf.left, cf.right);
|
||||
}
|
||||
|
||||
public CFMetaData getCFMetaData(Descriptor descriptor)
|
||||
{
|
||||
return getCFMetaData(descriptor.ksname, descriptor.cfname);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type of the ColumnFamily but it's keyspace/name
|
||||
*
|
||||
* @param ksName The keyspace name
|
||||
* @param cfName The ColumnFamily name
|
||||
*
|
||||
* @return The type of the ColumnFamily
|
||||
*/
|
||||
public ColumnFamilyType getColumnFamilyType(String ksName, String cfName)
|
||||
{
|
||||
assert ksName != null && cfName != null;
|
||||
CFMetaData cfMetaData = getCFMetaData(ksName, cfName);
|
||||
return (cfMetaData == null) ? null : cfMetaData.cfType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get column comparator for ColumnFamily but it's keyspace/name
|
||||
*
|
||||
* @param ksName The keyspace name
|
||||
* @param cfName The ColumnFamily name
|
||||
*
|
||||
* @return The comparator of the ColumnFamily
|
||||
*/
|
||||
public AbstractType getComparator(String ksName, String cfName)
|
||||
{
|
||||
assert ksName != null;
|
||||
CFMetaData cfmd = getCFMetaData(ksName, cfName);
|
||||
if (cfmd == null)
|
||||
throw new IllegalArgumentException("Unknown ColumnFamily " + cfName + " in keyspace " + ksName);
|
||||
return cfmd.comparator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get subComparator of the ColumnFamily
|
||||
*
|
||||
* @param ksName The keyspace name
|
||||
* @param cfName The ColumnFamily name
|
||||
*
|
||||
* @return The subComparator of the ColumnFamily
|
||||
*/
|
||||
public AbstractType getSubComparator(String ksName, String cfName)
|
||||
{
|
||||
assert ksName != null;
|
||||
return getCFMetaData(ksName, cfName).subcolumnComparator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get value validator for specific column
|
||||
*
|
||||
* @param ksName The keyspace name
|
||||
* @param cfName The ColumnFamily name
|
||||
* @param column The name of the column
|
||||
*
|
||||
* @return value validator specific to the column or default (per-cf) one
|
||||
*/
|
||||
public AbstractType getValueValidator(String ksName, String cfName, ByteBuffer column)
|
||||
{
|
||||
return getCFMetaData(ksName, cfName).getValueValidator(column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get metadata about table by its name
|
||||
*
|
||||
* @param table The name of the table
|
||||
*
|
||||
* @return The table metadata or null if it wasn't found
|
||||
*/
|
||||
public KSMetaData getKSMetaData(String table)
|
||||
{
|
||||
assert table != null;
|
||||
return tables.get(table);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return collection of the non-system tables
|
||||
*/
|
||||
public List<String> getNonSystemTables()
|
||||
{
|
||||
List<String> tablesList = new ArrayList<String>(tables.keySet());
|
||||
tablesList.remove(Table.SYSTEM_TABLE);
|
||||
return Collections.unmodifiableList(tablesList);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get metadata about table by its name
|
||||
*
|
||||
* @param table The name of the table
|
||||
*
|
||||
* @return The table metadata or null if it wasn't found
|
||||
*/
|
||||
public KSMetaData getTableDefinition(String table)
|
||||
{
|
||||
return getKSMetaData(table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get metadata about table inner ColumnFamilies
|
||||
*
|
||||
* @param tableName The name of the table
|
||||
*
|
||||
* @return metadata about ColumnFamilies the belong to the given table
|
||||
*/
|
||||
public Map<String, CFMetaData> getTableMetaData(String tableName)
|
||||
{
|
||||
assert tableName != null;
|
||||
KSMetaData ksm = tables.get(tableName);
|
||||
assert ksm != null;
|
||||
return ksm.cfMetaData();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return collection of the all table names registered in the system (system and non-system)
|
||||
*/
|
||||
public Set<String> getTables()
|
||||
{
|
||||
return tables.keySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return collection of the metadata about all tables registered in the system (system and non-system)
|
||||
*/
|
||||
public Collection<KSMetaData> getTableDefinitions()
|
||||
{
|
||||
return tables.values();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update (or insert) new table definition and change schema version
|
||||
*
|
||||
* @param ksm The metadata about table
|
||||
* @param newVersion New schema version
|
||||
*/
|
||||
public void setTableDefinition(KSMetaData ksm, UUID newVersion)
|
||||
{
|
||||
if (ksm != null)
|
||||
tables.put(ksm.name, ksm);
|
||||
version = newVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new system table
|
||||
* @param systemTable The metadata describing new system table
|
||||
*/
|
||||
public void addSystemTable(KSMetaData systemTable)
|
||||
{
|
||||
tables.put(systemTable.name, systemTable);
|
||||
}
|
||||
|
||||
/* ColumnFamily query/control methods */
|
||||
|
||||
/**
|
||||
* @param cfId The identifier of the ColumnFamily to lookup
|
||||
* @return The (ksname,cfname) pair for the given id, or null if it has been dropped.
|
||||
*/
|
||||
public Pair<String,String> getCF(Integer cfId)
|
||||
{
|
||||
return cfIdMap.inverse().get(cfId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup keyspace/ColumnFamily identifier
|
||||
*
|
||||
* @param ksName The keyspace name
|
||||
* @param cfName The ColumnFamily name
|
||||
*
|
||||
* @return The id for the given (ksname,cfname) pair, or null if it has been dropped.
|
||||
*/
|
||||
public Integer getId(String ksName, String cfName)
|
||||
{
|
||||
return cfIdMap.get(new Pair<String, String>(ksName, cfName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Load individual ColumnFamily Definition to the schema
|
||||
* (to make ColumnFamily lookup faster)
|
||||
*
|
||||
* @param cfm The ColumnFamily definition to load
|
||||
*
|
||||
* @throws ConfigurationException if ColumnFamily was already loaded
|
||||
*/
|
||||
public void load(CFMetaData cfm) throws ConfigurationException
|
||||
{
|
||||
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.");
|
||||
|
||||
cfIdMap.put(key, cfm.cfId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used for ColumnFamily data eviction out from the schema
|
||||
*
|
||||
* @param cfm The ColumnFamily Definition to evict
|
||||
*/
|
||||
public void purge(CFMetaData cfm)
|
||||
{
|
||||
cfIdMap.remove(new Pair<String, String>(cfm.ksName, cfm.cfName));
|
||||
}
|
||||
|
||||
/**
|
||||
* This gets called after initialization to make sure that id generation happens properly.
|
||||
*/
|
||||
public void fixCFMaxId()
|
||||
{
|
||||
// never set it to less than 1000. this ensures that we have enough system CFids for future use.
|
||||
cfIdGen.set(cfIdMap.size() == 0 ? MIN_CF_ID : Math.max(Collections.max(cfIdMap.values()) + 1, MIN_CF_ID));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return identifier for the new ColumnFamily (called primarily by CFMetaData constructor)
|
||||
*/
|
||||
public int nextCFId()
|
||||
{
|
||||
return cfIdGen.getAndIncrement();
|
||||
}
|
||||
|
||||
/* Version control */
|
||||
|
||||
/**
|
||||
* @return current schema version
|
||||
*/
|
||||
public UUID getVersion()
|
||||
{
|
||||
return version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set new version of the schema
|
||||
* @param newVersion New version of the schema
|
||||
*/
|
||||
public void setVersion(UUID newVersion)
|
||||
{
|
||||
version = newVersion;
|
||||
}
|
||||
}
|
||||
|
|
@ -20,10 +20,7 @@
|
|||
*/
|
||||
package org.apache.cassandra.cql;
|
||||
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.config.ColumnDefinition;
|
||||
import org.apache.cassandra.config.ConfigurationException;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.config.*;
|
||||
import org.apache.cassandra.db.marshal.TypeParser;
|
||||
import org.apache.cassandra.db.migration.avro.CfDef;
|
||||
import org.apache.cassandra.db.migration.avro.ColumnDef;
|
||||
|
|
@ -56,7 +53,7 @@ public class AlterTableStatement
|
|||
|
||||
public CfDef getCfDef(String keyspace) throws ConfigurationException, InvalidRequestException
|
||||
{
|
||||
CFMetaData meta = DatabaseDescriptor.getCFMetaData(keyspace, columnFamily);
|
||||
CFMetaData meta = Schema.instance.getCFMetaData(keyspace, columnFamily);
|
||||
|
||||
CfDef cfDef = CFMetaData.convertToAvro(meta);
|
||||
|
||||
|
|
|
|||
|
|
@ -26,13 +26,12 @@ import java.util.List;
|
|||
|
||||
import org.apache.cassandra.auth.Permission;
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.config.Schema;
|
||||
import org.apache.cassandra.db.IMutation;
|
||||
import org.apache.cassandra.db.RowMutation;
|
||||
import org.apache.cassandra.db.filter.QueryPath;
|
||||
import org.apache.cassandra.db.marshal.AbstractType;
|
||||
import org.apache.cassandra.service.ClientState;
|
||||
import org.apache.cassandra.thrift.ConsistencyLevel;
|
||||
import org.apache.cassandra.thrift.InvalidRequestException;
|
||||
|
||||
import static org.apache.cassandra.thrift.ThriftValidation.validateColumnFamily;
|
||||
|
|
@ -76,7 +75,7 @@ public class DeleteStatement extends AbstractModification
|
|||
public List<IMutation> prepareRowMutations(String keyspace, ClientState clientState, Long timestamp) throws InvalidRequestException
|
||||
{
|
||||
clientState.hasColumnFamilyAccess(columnFamily, Permission.WRITE);
|
||||
AbstractType<?> keyType = DatabaseDescriptor.getCFMetaData(keyspace, columnFamily).getKeyValidator();
|
||||
AbstractType<?> keyType = Schema.instance.getCFMetaData(keyspace, columnFamily).getKeyValidator();
|
||||
|
||||
List<IMutation> rowMutations = new ArrayList<IMutation>();
|
||||
|
||||
|
|
|
|||
|
|
@ -21,13 +21,9 @@
|
|||
package org.apache.cassandra.cql;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.config.ConfigurationException;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.config.KSMetaData;
|
||||
import org.apache.cassandra.config.*;
|
||||
import org.apache.cassandra.db.migration.avro.CfDef;
|
||||
import org.apache.cassandra.db.migration.avro.ColumnDef;
|
||||
import org.apache.cassandra.db.migration.UpdateColumnFamily;
|
||||
|
|
@ -47,7 +43,7 @@ public class DropIndexStatement
|
|||
{
|
||||
CfDef cfDef = null;
|
||||
|
||||
KSMetaData ksm = DatabaseDescriptor.getTableDefinition(keyspace);
|
||||
KSMetaData ksm = Schema.instance.getTableDefinition(keyspace);
|
||||
|
||||
for (Map.Entry<String, CFMetaData> cf : ksm.cfMetaData().entrySet())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -144,8 +144,7 @@ public class QueryProcessor
|
|||
List<org.apache.cassandra.db.Row> rows;
|
||||
IPartitioner<?> p = StorageService.getPartitioner();
|
||||
|
||||
AbstractType<?> keyType = DatabaseDescriptor.getCFMetaData(keyspace,
|
||||
select.getColumnFamily()).getKeyValidator();
|
||||
AbstractType<?> keyType = Schema.instance.getCFMetaData(keyspace, select.getColumnFamily()).getKeyValidator();
|
||||
|
||||
ByteBuffer startKey = (select.getKeyStart() != null)
|
||||
? select.getKeyStart().getByteBuffer(keyType)
|
||||
|
|
@ -234,9 +233,8 @@ public class QueryProcessor
|
|||
IndexOperator.valueOf(columnRelation.operator().toString()),
|
||||
value));
|
||||
}
|
||||
|
||||
AbstractType<?> keyType = DatabaseDescriptor.getCFMetaData(keyspace,
|
||||
select.getColumnFamily()).getKeyValidator();
|
||||
|
||||
AbstractType<?> keyType = Schema.instance.getCFMetaData(keyspace, select.getColumnFamily()).getKeyValidator();
|
||||
ByteBuffer startKey = (!select.isKeyRange()) ? (new Term()).getByteBuffer() : select.getKeyStart().getByteBuffer(keyType);
|
||||
IndexClause thriftIndexClause = new IndexClause(expressions, startKey, select.getNumRecords());
|
||||
|
||||
|
|
@ -719,8 +717,7 @@ public class QueryProcessor
|
|||
CreateIndexStatement createIdx = (CreateIndexStatement)statement.statement;
|
||||
clientState.hasColumnFamilyListAccess(Permission.WRITE);
|
||||
validateSchemaAgreement();
|
||||
CFMetaData oldCfm = DatabaseDescriptor.getCFMetaData(CFMetaData.getId(keyspace,
|
||||
createIdx.getColumnFamily()));
|
||||
CFMetaData oldCfm = Schema.instance.getCFMetaData(keyspace, createIdx.getColumnFamily());
|
||||
if (oldCfm == null)
|
||||
throw new InvalidRequestException("No such column family: " + createIdx.getColumnFamily());
|
||||
|
||||
|
|
@ -975,7 +972,7 @@ public class QueryProcessor
|
|||
outer:
|
||||
while (limit - System.currentTimeMillis() >= 0)
|
||||
{
|
||||
String currentVersionId = DatabaseDescriptor.getDefsVersion().toString();
|
||||
String currentVersionId = Schema.instance.getVersion().toString();
|
||||
for (String version : describeSchemaVersions().keySet())
|
||||
{
|
||||
if (!version.equals(currentVersionId))
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.config.Schema;
|
||||
import org.apache.cassandra.db.marshal.AbstractType;
|
||||
import org.apache.cassandra.thrift.ConsistencyLevel;
|
||||
|
||||
|
|
@ -161,12 +161,12 @@ public class SelectStatement
|
|||
|
||||
public AbstractType getComparator(String keyspace)
|
||||
{
|
||||
return DatabaseDescriptor.getComparator(keyspace, columnFamily);
|
||||
return Schema.instance.getComparator(keyspace, columnFamily);
|
||||
}
|
||||
|
||||
public AbstractType getValueValidator(String keyspace, ByteBuffer column)
|
||||
{
|
||||
return DatabaseDescriptor.getValueValidator(keyspace, columnFamily, column);
|
||||
return Schema.instance.getValueValidator(keyspace, columnFamily, column);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ import java.util.*;
|
|||
|
||||
import org.apache.cassandra.auth.Permission;
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.config.Schema;
|
||||
import org.apache.cassandra.db.CounterMutation;
|
||||
import org.apache.cassandra.db.IMutation;
|
||||
import org.apache.cassandra.db.RowMutation;
|
||||
|
|
@ -280,16 +280,16 @@ public class UpdateStatement extends AbstractModification
|
|||
|
||||
public AbstractType<?> getKeyType(String keyspace)
|
||||
{
|
||||
return DatabaseDescriptor.getCFMetaData(keyspace, columnFamily).getKeyValidator();
|
||||
return Schema.instance.getCFMetaData(keyspace, columnFamily).getKeyValidator();
|
||||
}
|
||||
|
||||
public AbstractType<?> getComparator(String keyspace)
|
||||
{
|
||||
return DatabaseDescriptor.getComparator(keyspace, columnFamily);
|
||||
return Schema.instance.getComparator(keyspace, columnFamily);
|
||||
}
|
||||
|
||||
public AbstractType<?> getValueValidator(String keyspace, ByteBuffer column)
|
||||
{
|
||||
return DatabaseDescriptor.getValueValidator(keyspace, columnFamily, column);
|
||||
return Schema.instance.getValueValidator(keyspace, columnFamily, column);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,11 +22,9 @@ import static org.apache.cassandra.db.DBConstants.*;
|
|||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.db.filter.IFilter;
|
||||
import org.apache.cassandra.config.Schema;
|
||||
import org.apache.cassandra.db.filter.QueryPath;
|
||||
import org.apache.cassandra.db.marshal.AbstractType;
|
||||
import org.apache.cassandra.db.marshal.MarshalException;
|
||||
|
|
@ -48,17 +46,17 @@ public class ColumnFamily extends AbstractColumnContainer
|
|||
|
||||
public static ColumnFamily create(Integer cfId)
|
||||
{
|
||||
return create(DatabaseDescriptor.getCFMetaData(cfId));
|
||||
return create(Schema.instance.getCFMetaData(cfId));
|
||||
}
|
||||
|
||||
public static ColumnFamily create(Integer cfId, ISortedColumns.Factory factory)
|
||||
{
|
||||
return create(DatabaseDescriptor.getCFMetaData(cfId), factory);
|
||||
return create(Schema.instance.getCFMetaData(cfId), factory);
|
||||
}
|
||||
|
||||
public static ColumnFamily create(String tableName, String cfName)
|
||||
{
|
||||
return create(DatabaseDescriptor.getCFMetaData(tableName, cfName));
|
||||
return create(Schema.instance.getCFMetaData(tableName, cfName));
|
||||
}
|
||||
|
||||
public static ColumnFamily create(CFMetaData cfm)
|
||||
|
|
@ -295,8 +293,8 @@ public class ColumnFamily extends AbstractColumnContainer
|
|||
public static AbstractType getComparatorFor(String table, String columnFamilyName, ByteBuffer superColumnName)
|
||||
{
|
||||
return superColumnName == null
|
||||
? DatabaseDescriptor.getComparator(table, columnFamilyName)
|
||||
: DatabaseDescriptor.getSubComparator(table, columnFamilyName);
|
||||
? Schema.instance.getComparator(table, columnFamilyName)
|
||||
: Schema.instance.getSubComparator(table, columnFamilyName);
|
||||
}
|
||||
|
||||
public static ColumnFamily diff(ColumnFamily cf1, ColumnFamily cf2)
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import java.io.IOException;
|
|||
import java.io.RandomAccessFile;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.apache.cassandra.config.Schema;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
@ -120,7 +121,7 @@ public class ColumnFamilySerializer implements ICompactSerializer3<ColumnFamily>
|
|||
|
||||
// create a ColumnFamily based on the cf id
|
||||
int cfId = dis.readInt();
|
||||
if (CFMetaData.getCF(cfId) == null)
|
||||
if (Schema.instance.getCF(cfId) == null)
|
||||
throw new UnserializableColumnFamilyException("Couldn't find cfId=" + cfId, cfId);
|
||||
ColumnFamily cf = ColumnFamily.create(cfId, factory);
|
||||
deserializeFromSSTableNoColumns(cf, dis);
|
||||
|
|
|
|||
|
|
@ -43,10 +43,7 @@ import org.apache.cassandra.cache.ICache;
|
|||
import org.apache.cassandra.concurrent.JMXEnabledThreadPoolExecutor;
|
||||
import org.apache.cassandra.concurrent.NamedThreadFactory;
|
||||
import org.apache.cassandra.concurrent.StageManager;
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.config.ColumnDefinition;
|
||||
import org.apache.cassandra.config.ConfigurationException;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.config.*;
|
||||
import org.apache.cassandra.db.columniterator.IColumnIterator;
|
||||
import org.apache.cassandra.db.commitlog.CommitLog;
|
||||
import org.apache.cassandra.db.commitlog.ReplayPosition;
|
||||
|
|
@ -307,7 +304,7 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean
|
|||
|
||||
public static ColumnFamilyStore createColumnFamilyStore(Table table, String columnFamily)
|
||||
{
|
||||
return createColumnFamilyStore(table, columnFamily, StorageService.getPartitioner(), DatabaseDescriptor.getCFMetaData(table.name, columnFamily));
|
||||
return createColumnFamilyStore(table, columnFamily, StorageService.getPartitioner(), Schema.instance.getCFMetaData(table.name, columnFamily));
|
||||
}
|
||||
|
||||
public static synchronized ColumnFamilyStore createColumnFamilyStore(Table table, String columnFamily, IPartitioner partitioner, CFMetaData metadata)
|
||||
|
|
@ -399,7 +396,7 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean
|
|||
}
|
||||
|
||||
// also clean out any index leftovers.
|
||||
CFMetaData cfm = DatabaseDescriptor.getCFMetaData(table, columnFamily);
|
||||
CFMetaData cfm = Schema.instance.getCFMetaData(table, columnFamily);
|
||||
if (cfm != null) // secondary indexes aren't stored in DD.
|
||||
{
|
||||
for (ColumnDefinition def : cfm.getColumn_metadata().values())
|
||||
|
|
@ -712,8 +709,8 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean
|
|||
public boolean isDropped()
|
||||
{
|
||||
return isIndex()
|
||||
? DatabaseDescriptor.getCFMetaData(table.name, getParentColumnfamily()) == null
|
||||
: DatabaseDescriptor.getCFMetaData(metadata.cfId) == null;
|
||||
? Schema.instance.getCFMetaData(table.name, getParentColumnfamily()) == null
|
||||
: Schema.instance.getCFMetaData(metadata.cfId) == null;
|
||||
}
|
||||
|
||||
public Future<?> forceFlush()
|
||||
|
|
@ -1512,7 +1509,7 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean
|
|||
|
||||
public static Iterable<ColumnFamilyStore> all()
|
||||
{
|
||||
Iterable<ColumnFamilyStore>[] stores = new Iterable[DatabaseDescriptor.getTables().size()];
|
||||
Iterable<ColumnFamilyStore>[] stores = new Iterable[Schema.instance.getTables().size()];
|
||||
int i = 0;
|
||||
for (Table table : Table.all())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import org.apache.cassandra.concurrent.Stage;
|
||||
import org.apache.cassandra.concurrent.StageManager;
|
||||
import org.apache.cassandra.config.Schema;
|
||||
import org.apache.cassandra.config.ConfigurationException;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.db.migration.Migration;
|
||||
import org.apache.cassandra.net.IVerbHandler;
|
||||
import org.apache.cassandra.net.Message;
|
||||
|
|
@ -52,7 +52,7 @@ public class DefinitionsUpdateVerbHandler implements IVerbHandler
|
|||
for (Column col : cols)
|
||||
{
|
||||
final UUID version = UUIDGen.getUUID(col.name());
|
||||
if (version.timestamp() > DatabaseDescriptor.getDefsVersion().timestamp())
|
||||
if (version.timestamp() > Schema.instance.getVersion().timestamp())
|
||||
{
|
||||
final Migration m = Migration.deserialize(col.value(), message.getVersion());
|
||||
assert m.getVersion().equals(version);
|
||||
|
|
@ -61,9 +61,9 @@ public class DefinitionsUpdateVerbHandler implements IVerbHandler
|
|||
protected void runMayThrow() throws Exception
|
||||
{
|
||||
// check to make sure the current version is before this one.
|
||||
if (DatabaseDescriptor.getDefsVersion().timestamp() == version.timestamp())
|
||||
if (Schema.instance.getVersion().timestamp() == version.timestamp())
|
||||
logger.debug("Not appling (equal) " + version.toString());
|
||||
else if (DatabaseDescriptor.getDefsVersion().timestamp() > version.timestamp())
|
||||
else if (Schema.instance.getVersion().timestamp() > version.timestamp())
|
||||
logger.debug("Not applying (before)" + version.toString());
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -47,14 +47,14 @@ public class DefsTable
|
|||
final ByteBuffer versionKey = Migration.toUTF8Bytes(version);
|
||||
|
||||
// build a list of keyspaces
|
||||
Collection<String> ksnames = DatabaseDescriptor.getNonSystemTables();
|
||||
Collection<String> ksnames = org.apache.cassandra.config.Schema.instance.getNonSystemTables();
|
||||
|
||||
// persist keyspaces under new version
|
||||
RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, versionKey);
|
||||
long now = System.currentTimeMillis();
|
||||
for (String ksname : ksnames)
|
||||
{
|
||||
KSMetaData ksm = DatabaseDescriptor.getTableDefinition(ksname);
|
||||
KSMetaData ksm = org.apache.cassandra.config.Schema.instance.getTableDefinition(ksname);
|
||||
rm.add(new QueryPath(Migration.SCHEMA_CF, null, ByteBufferUtil.bytes(ksm.name)), SerDeUtils.serialize(ksm.deflate()), now);
|
||||
}
|
||||
// add the schema
|
||||
|
|
|
|||
|
|
@ -22,10 +22,10 @@ import java.io.*;
|
|||
import java.nio.ByteBuffer;
|
||||
import java.util.*;
|
||||
|
||||
import org.apache.cassandra.config.Schema;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.config.KSMetaData;
|
||||
import org.apache.cassandra.db.filter.QueryPath;
|
||||
import org.apache.cassandra.io.ICompactSerializer;
|
||||
|
|
@ -187,7 +187,7 @@ public class RowMutation implements IMutation, MessageProducer
|
|||
*/
|
||||
public void add(QueryPath path, ByteBuffer value, long timestamp, int timeToLive)
|
||||
{
|
||||
Integer id = CFMetaData.getId(table_, path.columnFamilyName);
|
||||
Integer id = Schema.instance.getId(table_, path.columnFamilyName);
|
||||
ColumnFamily columnFamily = modifications_.get(id);
|
||||
if (columnFamily == null)
|
||||
{
|
||||
|
|
@ -199,7 +199,7 @@ public class RowMutation implements IMutation, MessageProducer
|
|||
|
||||
public void addCounter(QueryPath path, long value)
|
||||
{
|
||||
Integer id = CFMetaData.getId(table_, path.columnFamilyName);
|
||||
Integer id = Schema.instance.getId(table_, path.columnFamilyName);
|
||||
ColumnFamily columnFamily = modifications_.get(id);
|
||||
if (columnFamily == null)
|
||||
{
|
||||
|
|
@ -216,7 +216,7 @@ public class RowMutation implements IMutation, MessageProducer
|
|||
|
||||
public void delete(QueryPath path, long timestamp)
|
||||
{
|
||||
Integer id = CFMetaData.getId(table_, path.columnFamilyName);
|
||||
Integer id = Schema.instance.getId(table_, path.columnFamilyName);
|
||||
|
||||
int localDeleteTime = (int) (System.currentTimeMillis() / 1000);
|
||||
|
||||
|
|
@ -249,7 +249,7 @@ public class RowMutation implements IMutation, MessageProducer
|
|||
*/
|
||||
public void apply() throws IOException
|
||||
{
|
||||
KSMetaData ksm = DatabaseDescriptor.getTableDefinition(getTable());
|
||||
KSMetaData ksm = Schema.instance.getTableDefinition(getTable());
|
||||
|
||||
Table.open(table_).apply(this, ksm.isDurableWrites());
|
||||
}
|
||||
|
|
@ -300,7 +300,7 @@ public class RowMutation implements IMutation, MessageProducer
|
|||
List<String> cfnames = new ArrayList<String>();
|
||||
for (Integer cfid : modifications_.keySet())
|
||||
{
|
||||
CFMetaData cfm = DatabaseDescriptor.getCFMetaData(cfid);
|
||||
CFMetaData cfm = Schema.instance.getCFMetaData(cfid);
|
||||
cfnames.add(cfm == null ? "-dropped-" : cfm.cfName);
|
||||
}
|
||||
buff.append(StringUtils.join(cfnames, ", "));
|
||||
|
|
@ -342,7 +342,7 @@ public class RowMutation implements IMutation, MessageProducer
|
|||
{
|
||||
for(ByteBuffer c : del.predicate.column_names)
|
||||
{
|
||||
if (del.super_column == null && DatabaseDescriptor.getColumnFamilyType(table_, cfName) == ColumnFamilyType.Super)
|
||||
if (del.super_column == null && Schema.instance.getColumnFamilyType(table_, cfName) == ColumnFamilyType.Super)
|
||||
delete(new QueryPath(cfName, c), del.timestamp);
|
||||
else
|
||||
delete(new QueryPath(cfName, del.super_column, c), del.timestamp);
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package org.apache.cassandra.db;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.config.Schema;
|
||||
import org.apache.cassandra.net.IVerbHandler;
|
||||
import org.apache.cassandra.net.Message;
|
||||
import org.apache.cassandra.net.MessagingService;
|
||||
|
|
@ -34,7 +34,7 @@ public class SchemaCheckVerbHandler implements IVerbHandler
|
|||
public void doVerb(Message message, String id)
|
||||
{
|
||||
logger.debug("Received schema check request.");
|
||||
Message response = message.getInternalReply(DatabaseDescriptor.getDefsVersion().toString().getBytes(), message.getVersion());
|
||||
Message response = message.getInternalReply(Schema.instance.getVersion().toString().getBytes(), message.getVersion());
|
||||
MessagingService.instance().sendReply(response, id, message.getFrom());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,11 +37,7 @@ import java.util.concurrent.ExecutionException;
|
|||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.config.Config;
|
||||
import org.apache.cassandra.config.ConfigurationException;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.config.KSMetaData;
|
||||
import org.apache.cassandra.config.*;
|
||||
import org.apache.cassandra.db.commitlog.CommitLog;
|
||||
import org.apache.cassandra.db.filter.QueryFilter;
|
||||
import org.apache.cassandra.db.filter.QueryPath;
|
||||
|
|
@ -54,7 +50,6 @@ import org.apache.cassandra.locator.AbstractReplicationStrategy;
|
|||
import org.apache.cassandra.service.StorageService;
|
||||
import org.apache.cassandra.utils.ByteBufferUtil;
|
||||
import org.apache.cassandra.utils.NodeId;
|
||||
import org.cliffc.high_scale_lib.NonBlockingHashMap;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
@ -97,9 +92,6 @@ public class Table
|
|||
}
|
||||
}
|
||||
|
||||
/** Table objects, one per keyspace. only one instance should ever exist for any given keyspace. */
|
||||
private static final Map<String, Table> instances = new NonBlockingHashMap<String, Table>();
|
||||
|
||||
/* Table name. */
|
||||
public final String name;
|
||||
/* ColumnFamilyStore per column family */
|
||||
|
|
@ -109,19 +101,25 @@ public class Table
|
|||
|
||||
public static Table open(String table)
|
||||
{
|
||||
Table tableInstance = instances.get(table);
|
||||
return open(table, Schema.instance);
|
||||
}
|
||||
|
||||
public static Table open(String table, Schema schema)
|
||||
{
|
||||
Table tableInstance = schema.getTableInstance(table);
|
||||
|
||||
if (tableInstance == null)
|
||||
{
|
||||
// instantiate the Table. we could use putIfAbsent but it's important to making sure it is only done once
|
||||
// per keyspace, so we synchronize and re-check before doing it.
|
||||
synchronized (Table.class)
|
||||
{
|
||||
tableInstance = instances.get(table);
|
||||
tableInstance = schema.getTableInstance(table);
|
||||
if (tableInstance == null)
|
||||
{
|
||||
// open and store the table
|
||||
tableInstance = new Table(table);
|
||||
instances.put(table, tableInstance);
|
||||
schema.storeTableInstance(tableInstance);
|
||||
|
||||
//table has to be constructed and in the cache before cacheRow can be called
|
||||
for (ColumnFamilyStore cfs : tableInstance.getColumnFamilyStores())
|
||||
|
|
@ -133,10 +131,15 @@ public class Table
|
|||
}
|
||||
|
||||
public static Table clear(String table) throws IOException
|
||||
{
|
||||
return clear(table, Schema.instance);
|
||||
}
|
||||
|
||||
public static Table clear(String table, Schema schema) throws IOException
|
||||
{
|
||||
synchronized (Table.class)
|
||||
{
|
||||
Table t = instances.remove(table);
|
||||
Table t = schema.removeTableInstance(table);
|
||||
if (t != null)
|
||||
{
|
||||
for (ColumnFamilyStore cfs : t.getColumnFamilyStores())
|
||||
|
|
@ -153,7 +156,7 @@ public class Table
|
|||
|
||||
public ColumnFamilyStore getColumnFamilyStore(String cfName)
|
||||
{
|
||||
Integer id = CFMetaData.getId(name, cfName);
|
||||
Integer id = Schema.instance.getId(name, cfName);
|
||||
if (id == null)
|
||||
throw new IllegalArgumentException(String.format("Unknown table/cf pair (%s.%s)", name, cfName));
|
||||
return getColumnFamilyStore(id);
|
||||
|
|
@ -277,7 +280,7 @@ public class Table
|
|||
private Table(String table)
|
||||
{
|
||||
name = table;
|
||||
KSMetaData ksm = DatabaseDescriptor.getKSMetaData(table);
|
||||
KSMetaData ksm = Schema.instance.getKSMetaData(table);
|
||||
assert ksm != null : "Unknown keyspace " + table;
|
||||
try
|
||||
{
|
||||
|
|
@ -311,7 +314,7 @@ public class Table
|
|||
}
|
||||
}
|
||||
|
||||
for (CFMetaData cfm : new ArrayList<CFMetaData>(DatabaseDescriptor.getTableDefinition(table).cfMetaData().values()))
|
||||
for (CFMetaData cfm : new ArrayList<CFMetaData>(Schema.instance.getTableDefinition(table).cfMetaData().values()))
|
||||
{
|
||||
logger.debug("Initializing {}.{}", name, cfm.cfName);
|
||||
initCf(cfm.cfId, cfm.cfName);
|
||||
|
|
@ -612,7 +615,7 @@ public class Table
|
|||
return Table.open(tableName);
|
||||
}
|
||||
};
|
||||
return Iterables.transform(DatabaseDescriptor.getTables(), transformer);
|
||||
return Iterables.transform(Schema.instance.getTables(), transformer);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import java.util.zip.Checksum;
|
|||
|
||||
import com.google.common.collect.Ordering;
|
||||
|
||||
import org.apache.cassandra.config.Schema;
|
||||
import org.apache.cassandra.db.*;
|
||||
import org.apache.cassandra.io.util.*;
|
||||
import org.apache.cassandra.net.MessagingService;
|
||||
|
|
@ -39,7 +40,6 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import org.apache.cassandra.concurrent.Stage;
|
||||
import org.apache.cassandra.concurrent.StageManager;
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.config.Config;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.io.DeletionService;
|
||||
|
|
@ -307,7 +307,7 @@ public class CommitLog implements CommitLogMBean
|
|||
{
|
||||
public void runMayThrow() throws IOException
|
||||
{
|
||||
if (DatabaseDescriptor.getKSMetaData(frm.getTable()) == null)
|
||||
if (Schema.instance.getKSMetaData(frm.getTable()) == null)
|
||||
return;
|
||||
final Table table = Table.open(frm.getTable());
|
||||
RowMutation newRm = new RowMutation(frm.getTable(), frm.key());
|
||||
|
|
@ -317,7 +317,7 @@ public class CommitLog implements CommitLogMBean
|
|||
// thing based on the cfid instead.
|
||||
for (ColumnFamily columnFamily : frm.getColumnFamilies())
|
||||
{
|
||||
if (CFMetaData.getCF(columnFamily.id()) == null)
|
||||
if (Schema.instance.getCF(columnFamily.id()) == null)
|
||||
// null means the cf has been dropped
|
||||
continue;
|
||||
|
||||
|
|
@ -571,7 +571,7 @@ public class CommitLog implements CommitLogMBean
|
|||
assert oldestSegment != null; // has to be at least the one we just added
|
||||
for (Integer dirtyCFId : oldestSegment.cfLastWrite.keySet())
|
||||
{
|
||||
String keypace = CFMetaData.getCF(dirtyCFId).left;
|
||||
String keypace = Schema.instance.getCF(dirtyCFId).left;
|
||||
Table.open(keypace).getColumnFamilyStore(dirtyCFId).forceFlush();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import java.util.zip.CRC32;
|
|||
import java.util.zip.Checksum;
|
||||
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.config.Schema;
|
||||
import org.apache.cassandra.io.util.SequentialWriter;
|
||||
import org.apache.cassandra.net.MessagingService;
|
||||
import org.slf4j.Logger;
|
||||
|
|
@ -107,7 +108,7 @@ public class CommitLogSegment
|
|||
{
|
||||
// check for null cfm in case a cl write goes through after the cf is
|
||||
// defined but before a new segment is created.
|
||||
CFMetaData cfm = DatabaseDescriptor.getCFMetaData(columnFamily.id());
|
||||
CFMetaData cfm = Schema.instance.getCFMetaData(columnFamily.id());
|
||||
if (cfm == null)
|
||||
{
|
||||
logger.error("Attempted to write commit log entry for unrecognized column family: " + columnFamily.id());
|
||||
|
|
@ -211,7 +212,7 @@ public class CommitLogSegment
|
|||
StringBuilder sb = new StringBuilder();
|
||||
for (Integer cfId : cfLastWrite.keySet())
|
||||
{
|
||||
CFMetaData m = DatabaseDescriptor.getCFMetaData(cfId);
|
||||
CFMetaData m = Schema.instance.getCFMetaData(cfId);
|
||||
sb.append(m == null ? "<deleted>" : m.cfName).append(" (").append(cfId).append("), ");
|
||||
}
|
||||
return sb.toString();
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ import org.apache.cassandra.cache.AutoSavingCache;
|
|||
import org.apache.cassandra.concurrent.DebuggableThreadPoolExecutor;
|
||||
import org.apache.cassandra.concurrent.NamedThreadFactory;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.config.Schema;
|
||||
import org.apache.cassandra.db.*;
|
||||
import org.apache.cassandra.db.index.SecondaryIndexBuilder;
|
||||
import org.apache.cassandra.dht.Range;
|
||||
|
|
@ -285,7 +286,7 @@ public class CompactionManager implements CompactionManagerMBean
|
|||
|
||||
public void forceUserDefinedCompaction(String ksname, String dataFiles)
|
||||
{
|
||||
if (!DatabaseDescriptor.getTables().contains(ksname))
|
||||
if (!Schema.instance.getTables().contains(ksname))
|
||||
throw new IllegalArgumentException("Unknown keyspace " + ksname);
|
||||
|
||||
File directory = new File(ksname);
|
||||
|
|
@ -435,7 +436,7 @@ public class CompactionManager implements CompactionManagerMBean
|
|||
/* Used in tests. */
|
||||
public void disableAutoCompaction()
|
||||
{
|
||||
for (String ksname : DatabaseDescriptor.getNonSystemTables())
|
||||
for (String ksname : Schema.instance.getNonSystemTables())
|
||||
{
|
||||
for (ColumnFamilyStore cfs : Table.open(ksname).getColumnFamilyStores())
|
||||
cfs.disableAutoCompaction();
|
||||
|
|
@ -1021,7 +1022,7 @@ public class CompactionManager implements CompactionManagerMBean
|
|||
public int getPendingTasks()
|
||||
{
|
||||
int n = 0;
|
||||
for (String tableName : DatabaseDescriptor.getTables())
|
||||
for (String tableName : Schema.instance.getTables())
|
||||
{
|
||||
for (ColumnFamilyStore cfs : Table.open(tableName).getColumnFamilyStores())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -40,9 +40,9 @@ public class AddColumnFamily extends Migration
|
|||
|
||||
public AddColumnFamily(CFMetaData cfm) throws ConfigurationException, IOException
|
||||
{
|
||||
super(UUIDGen.makeType1UUIDFromHost(FBUtilities.getBroadcastAddress()), DatabaseDescriptor.getDefsVersion());
|
||||
super(UUIDGen.makeType1UUIDFromHost(FBUtilities.getBroadcastAddress()), Schema.instance.getVersion());
|
||||
this.cfm = cfm;
|
||||
KSMetaData ksm = DatabaseDescriptor.getTableDefinition(cfm.ksName);
|
||||
KSMetaData ksm = schema.getTableDefinition(cfm.ksName);
|
||||
|
||||
if (ksm == null)
|
||||
throw new ConfigurationException("No such keyspace: " + cfm.ksName);
|
||||
|
|
@ -62,7 +62,7 @@ public class AddColumnFamily extends Migration
|
|||
// clone ksm but include the new cf def.
|
||||
KSMetaData newKsm = makeNewKeyspaceDefinition(ksm);
|
||||
|
||||
rm = Migration.makeDefinitionMutation(newKsm, null, newVersion);
|
||||
rm = makeDefinitionMutation(newKsm, null, newVersion);
|
||||
}
|
||||
|
||||
private KSMetaData makeNewKeyspaceDefinition(KSMetaData ksm)
|
||||
|
|
@ -75,22 +75,22 @@ public class AddColumnFamily extends Migration
|
|||
public void applyModels() throws IOException
|
||||
{
|
||||
// reinitialize the table.
|
||||
KSMetaData ksm = DatabaseDescriptor.getTableDefinition(cfm.ksName);
|
||||
KSMetaData ksm = schema.getTableDefinition(cfm.ksName);
|
||||
ksm = makeNewKeyspaceDefinition(ksm);
|
||||
try
|
||||
{
|
||||
CFMetaData.map(cfm);
|
||||
schema.load(cfm);
|
||||
}
|
||||
catch (ConfigurationException ex)
|
||||
{
|
||||
throw new IOException(ex);
|
||||
}
|
||||
Table.open(cfm.ksName); // make sure it's init-ed w/ the old definitions first, since we're going to call initCf on the new one manually
|
||||
DatabaseDescriptor.setTableDefinition(ksm, newVersion);
|
||||
Table.open(cfm.ksName, schema); // make sure it's init-ed w/ the old definitions first, since we're going to call initCf on the new one manually
|
||||
schema.setTableDefinition(ksm, newVersion);
|
||||
// these definitions could have come from somewhere else.
|
||||
CFMetaData.fixMaxId();
|
||||
schema.fixCFMaxId();
|
||||
if (!StorageService.instance.isClientMode())
|
||||
Table.open(ksm.name).initCf(cfm.cfId, cfm.cfName);
|
||||
Table.open(ksm.name, schema).initCf(cfm.cfId, cfm.cfName);
|
||||
}
|
||||
|
||||
public void subdeflate(org.apache.cassandra.db.migration.avro.Migration mi)
|
||||
|
|
|
|||
|
|
@ -20,10 +20,7 @@ package org.apache.cassandra.db.migration;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.config.ConfigurationException;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.config.KSMetaData;
|
||||
import org.apache.cassandra.config.*;
|
||||
import org.apache.cassandra.db.Table;
|
||||
import org.apache.cassandra.service.StorageService;
|
||||
import org.apache.cassandra.utils.FBUtilities;
|
||||
|
|
@ -38,9 +35,9 @@ public class AddKeyspace extends Migration
|
|||
|
||||
public AddKeyspace(KSMetaData ksm) throws ConfigurationException, IOException
|
||||
{
|
||||
super(UUIDGen.makeType1UUIDFromHost(FBUtilities.getBroadcastAddress()), DatabaseDescriptor.getDefsVersion());
|
||||
super(UUIDGen.makeType1UUIDFromHost(FBUtilities.getBroadcastAddress()), Schema.instance.getVersion());
|
||||
|
||||
if (DatabaseDescriptor.getTableDefinition(ksm.name) != null)
|
||||
if (schema.getTableDefinition(ksm.name) != null)
|
||||
throw new ConfigurationException("Keyspace already exists.");
|
||||
if (!Migration.isLegalName(ksm.name))
|
||||
throw new ConfigurationException("Invalid keyspace name: " + ksm.name);
|
||||
|
|
@ -58,7 +55,7 @@ public class AddKeyspace extends Migration
|
|||
{
|
||||
try
|
||||
{
|
||||
CFMetaData.map(cfm);
|
||||
schema.load(cfm);
|
||||
}
|
||||
catch (ConfigurationException ex)
|
||||
{
|
||||
|
|
@ -67,12 +64,12 @@ public class AddKeyspace extends Migration
|
|||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
DatabaseDescriptor.setTableDefinition(ksm, newVersion);
|
||||
schema.setTableDefinition(ksm, newVersion);
|
||||
// these definitions could have come from somewhere else.
|
||||
CFMetaData.fixMaxId();
|
||||
schema.fixCFMaxId();
|
||||
if (!StorageService.instance.isClientMode())
|
||||
{
|
||||
Table.open(ksm.name);
|
||||
Table.open(ksm.name, schema);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,10 +4,7 @@ import java.io.IOException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.config.ConfigurationException;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.config.KSMetaData;
|
||||
import org.apache.cassandra.config.*;
|
||||
import org.apache.cassandra.db.ColumnFamilyStore;
|
||||
import org.apache.cassandra.db.compaction.CompactionManager;
|
||||
import org.apache.cassandra.db.Table;
|
||||
|
|
@ -44,18 +41,18 @@ public class DropColumnFamily extends Migration
|
|||
|
||||
public DropColumnFamily(String tableName, String cfName) throws ConfigurationException, IOException
|
||||
{
|
||||
super(UUIDGen.makeType1UUIDFromHost(FBUtilities.getBroadcastAddress()), DatabaseDescriptor.getDefsVersion());
|
||||
super(UUIDGen.makeType1UUIDFromHost(FBUtilities.getBroadcastAddress()), Schema.instance.getVersion());
|
||||
this.tableName = tableName;
|
||||
this.cfName = cfName;
|
||||
|
||||
KSMetaData ksm = DatabaseDescriptor.getTableDefinition(tableName);
|
||||
KSMetaData ksm = schema.getTableDefinition(tableName);
|
||||
if (ksm == null)
|
||||
throw new ConfigurationException("No such keyspace: " + tableName);
|
||||
else if (!ksm.cfMetaData().containsKey(cfName))
|
||||
throw new ConfigurationException("CF is not defined in that keyspace.");
|
||||
|
||||
KSMetaData newKsm = makeNewKeyspaceDefinition(ksm);
|
||||
rm = Migration.makeDefinitionMutation(newKsm, null, newVersion);
|
||||
rm = makeDefinitionMutation(newKsm, null, newVersion);
|
||||
}
|
||||
|
||||
private KSMetaData makeNewKeyspaceDefinition(KSMetaData ksm)
|
||||
|
|
@ -70,14 +67,14 @@ public class DropColumnFamily extends Migration
|
|||
|
||||
public void applyModels() throws IOException
|
||||
{
|
||||
ColumnFamilyStore cfs = Table.open(tableName).getColumnFamilyStore(cfName);
|
||||
ColumnFamilyStore cfs = Table.open(tableName, schema).getColumnFamilyStore(cfName);
|
||||
|
||||
// reinitialize the table.
|
||||
KSMetaData existing = DatabaseDescriptor.getTableDefinition(tableName);
|
||||
KSMetaData existing = schema.getTableDefinition(tableName);
|
||||
CFMetaData cfm = existing.cfMetaData().get(cfName);
|
||||
KSMetaData ksm = makeNewKeyspaceDefinition(existing);
|
||||
CFMetaData.purge(cfm);
|
||||
DatabaseDescriptor.setTableDefinition(ksm, newVersion);
|
||||
schema.purge(cfm);
|
||||
schema.setTableDefinition(ksm, newVersion);
|
||||
|
||||
if (!StorageService.instance.isClientMode())
|
||||
{
|
||||
|
|
@ -87,7 +84,7 @@ public class DropColumnFamily extends Migration
|
|||
cfs.flushLock.lock();
|
||||
try
|
||||
{
|
||||
Table.open(ksm.name).dropCf(cfm.cfId);
|
||||
Table.open(ksm.name, schema).dropCf(cfm.cfId);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
|
|||
|
|
@ -20,13 +20,9 @@ package org.apache.cassandra.db.migration;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.config.ConfigurationException;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.config.KSMetaData;
|
||||
import org.apache.cassandra.config.*;
|
||||
import org.apache.cassandra.db.ColumnFamilyStore;
|
||||
import org.apache.cassandra.db.compaction.CompactionManager;
|
||||
import org.apache.cassandra.db.HintedHandOffManager;
|
||||
import org.apache.cassandra.db.Table;
|
||||
import org.apache.cassandra.service.StorageService;
|
||||
import org.apache.cassandra.utils.FBUtilities;
|
||||
|
|
@ -41,9 +37,9 @@ public class DropKeyspace extends Migration
|
|||
|
||||
public DropKeyspace(String name) throws ConfigurationException, IOException
|
||||
{
|
||||
super(UUIDGen.makeType1UUIDFromHost(FBUtilities.getBroadcastAddress()), DatabaseDescriptor.getDefsVersion());
|
||||
super(UUIDGen.makeType1UUIDFromHost(FBUtilities.getBroadcastAddress()), Schema.instance.getVersion());
|
||||
this.name = name;
|
||||
KSMetaData ksm = DatabaseDescriptor.getTableDefinition(name);
|
||||
KSMetaData ksm = schema.getTableDefinition(name);
|
||||
if (ksm == null)
|
||||
throw new ConfigurationException("Keyspace does not exist.");
|
||||
rm = makeDefinitionMutation(null, ksm, newVersion);
|
||||
|
|
@ -55,20 +51,20 @@ public class DropKeyspace extends Migration
|
|||
CompactionManager.instance.getCompactionLock().lock();
|
||||
try
|
||||
{
|
||||
KSMetaData ksm = DatabaseDescriptor.getTableDefinition(name);
|
||||
KSMetaData ksm = schema.getTableDefinition(name);
|
||||
|
||||
// remove all cfs from the table instance.
|
||||
for (CFMetaData cfm : ksm.cfMetaData().values())
|
||||
{
|
||||
ColumnFamilyStore cfs = Table.open(ksm.name).getColumnFamilyStore(cfm.cfName);
|
||||
CFMetaData.purge(cfm);
|
||||
ColumnFamilyStore cfs = Table.open(ksm.name, schema).getColumnFamilyStore(cfm.cfName);
|
||||
schema.purge(cfm);
|
||||
if (!StorageService.instance.isClientMode())
|
||||
{
|
||||
cfs.snapshot(snapshotName);
|
||||
cfs.flushLock.lock();
|
||||
try
|
||||
{
|
||||
Table.open(ksm.name).dropCf(cfm.cfId);
|
||||
Table.open(ksm.name, schema).dropCf(cfm.cfId);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
@ -78,10 +74,10 @@ public class DropKeyspace extends Migration
|
|||
}
|
||||
|
||||
// remove the table from the static instances.
|
||||
Table table = Table.clear(ksm.name);
|
||||
Table table = Table.clear(ksm.name, schema);
|
||||
assert table != null;
|
||||
// reset defs.
|
||||
DatabaseDescriptor.clearTableDefinition(ksm, newVersion);
|
||||
schema.clearTableDefinition(ksm, newVersion);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
|
|||
|
|
@ -28,12 +28,12 @@ import java.util.UUID;
|
|||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import org.apache.cassandra.config.Schema;
|
||||
import org.apache.cassandra.net.MessagingService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.apache.cassandra.config.ConfigurationException;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.config.KSMetaData;
|
||||
import org.apache.cassandra.db.*;
|
||||
import org.apache.cassandra.db.filter.QueryFilter;
|
||||
|
|
@ -79,6 +79,9 @@ public abstract class Migration
|
|||
// the migration in column form, used when announcing to others
|
||||
private IColumn column;
|
||||
|
||||
// cast of the schema at the time when migration was initialized
|
||||
protected final Schema schema = Schema.instance;
|
||||
|
||||
/** Subclasses must have a matching constructor */
|
||||
protected Migration() { }
|
||||
|
||||
|
|
@ -88,12 +91,12 @@ public abstract class Migration
|
|||
this.newVersion = newVersion;
|
||||
this.lastVersion = lastVersion;
|
||||
}
|
||||
|
||||
|
||||
/** apply changes */
|
||||
public final void apply() throws IOException, ConfigurationException
|
||||
{
|
||||
// ensure migration is serial. don't apply unless the previous version matches.
|
||||
if (!DatabaseDescriptor.getDefsVersion().equals(lastVersion))
|
||||
if (!schema.getVersion().equals(lastVersion))
|
||||
throw new ConfigurationException("Previous version mismatch. cannot apply.");
|
||||
if (newVersion.timestamp() <= lastVersion.timestamp())
|
||||
throw new ConfigurationException("New version timestamp is not newer than the current version timestamp.");
|
||||
|
|
@ -199,15 +202,15 @@ public abstract class Migration
|
|||
* (containing the Avro Schema) and a column per keyspace. Each keyspace column contains a avro.KsDef object
|
||||
* encoded with the Avro schema.
|
||||
*/
|
||||
static RowMutation makeDefinitionMutation(KSMetaData add, KSMetaData remove, UUID versionId) throws IOException
|
||||
final RowMutation makeDefinitionMutation(KSMetaData add, KSMetaData remove, UUID versionId) throws IOException
|
||||
{
|
||||
// collect all keyspaces, while removing 'remove' and adding 'add'
|
||||
List<KSMetaData> ksms = new ArrayList<KSMetaData>();
|
||||
for (String tableName : DatabaseDescriptor.getNonSystemTables())
|
||||
for (String tableName : schema.getNonSystemTables())
|
||||
{
|
||||
if (remove != null && remove.name.equals(tableName) || add != null && add.name.equals(tableName))
|
||||
continue;
|
||||
ksms.add(DatabaseDescriptor.getTableDefinition(tableName));
|
||||
ksms.add(schema.getTableDefinition(tableName));
|
||||
}
|
||||
if (add != null)
|
||||
ksms.add(add);
|
||||
|
|
|
|||
|
|
@ -4,10 +4,7 @@ import java.io.IOException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.config.ConfigurationException;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.config.KSMetaData;
|
||||
import org.apache.cassandra.config.*;
|
||||
import org.apache.cassandra.db.Table;
|
||||
import org.apache.cassandra.service.StorageService;
|
||||
import org.apache.cassandra.utils.FBUtilities;
|
||||
|
|
@ -47,12 +44,12 @@ public class RenameColumnFamily extends Migration
|
|||
// be called during deserialization of this migration.
|
||||
public RenameColumnFamily(String tableName, String oldName, String newName) throws ConfigurationException, IOException
|
||||
{
|
||||
super(UUIDGen.makeType1UUIDFromHost(FBUtilities.getBroadcastAddress()), DatabaseDescriptor.getDefsVersion());
|
||||
super(UUIDGen.makeType1UUIDFromHost(FBUtilities.getBroadcastAddress()), Schema.instance.getVersion());
|
||||
this.tableName = tableName;
|
||||
this.oldName = oldName;
|
||||
this.newName = newName;
|
||||
|
||||
KSMetaData ksm = DatabaseDescriptor.getTableDefinition(tableName);
|
||||
KSMetaData ksm = schema.getTableDefinition(tableName);
|
||||
if (ksm == null)
|
||||
throw new ConfigurationException("No such keyspace: " + tableName);
|
||||
if (!ksm.cfMetaData().containsKey(oldName))
|
||||
|
|
@ -66,7 +63,7 @@ public class RenameColumnFamily extends Migration
|
|||
|
||||
// clone the ksm, replacing cfm with the new one.
|
||||
KSMetaData newKsm = makeNewKeyspaceDefinition(ksm);
|
||||
rm = Migration.makeDefinitionMutation(newKsm, null, newVersion);
|
||||
rm = makeDefinitionMutation(newKsm, null, newVersion);
|
||||
}
|
||||
|
||||
private KSMetaData makeNewKeyspaceDefinition(KSMetaData ksm)
|
||||
|
|
@ -86,12 +83,12 @@ public class RenameColumnFamily extends Migration
|
|||
// attempting row mutations on oldcfName right now would be really bad.
|
||||
|
||||
// reset defs.
|
||||
KSMetaData oldKsm = DatabaseDescriptor.getTableDefinition(tableName);
|
||||
CFMetaData.purge(oldKsm.cfMetaData().get(oldName));
|
||||
KSMetaData ksm = makeNewKeyspaceDefinition(DatabaseDescriptor.getTableDefinition(tableName));
|
||||
KSMetaData oldKsm = schema.getTableDefinition(tableName);
|
||||
schema.purge(oldKsm.cfMetaData().get(oldName));
|
||||
KSMetaData ksm = makeNewKeyspaceDefinition(schema.getTableDefinition(tableName));
|
||||
try
|
||||
{
|
||||
CFMetaData.map(ksm.cfMetaData().get(newName));
|
||||
schema.load(ksm.cfMetaData().get(newName));
|
||||
}
|
||||
catch (ConfigurationException ex)
|
||||
{
|
||||
|
|
@ -99,11 +96,11 @@ public class RenameColumnFamily extends Migration
|
|||
// been checked in the constructor and shouldn't happen.
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
DatabaseDescriptor.setTableDefinition(ksm, newVersion);
|
||||
schema.setTableDefinition(ksm, newVersion);
|
||||
|
||||
if (!StorageService.instance.isClientMode())
|
||||
{
|
||||
Table.open(ksm.name).renameCf(cfId, newName);
|
||||
Table.open(ksm.name, schema).renameCf(cfId, newName);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,12 +23,9 @@ import java.io.IOException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.cassandra.config.*;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.config.ConfigurationException;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.config.KSMetaData;
|
||||
import org.apache.cassandra.db.Table;
|
||||
import org.apache.cassandra.service.StorageService;
|
||||
import org.apache.cassandra.utils.FBUtilities;
|
||||
|
|
@ -46,14 +43,14 @@ public class RenameKeyspace extends Migration
|
|||
|
||||
public RenameKeyspace(String oldName, String newName) throws ConfigurationException, IOException
|
||||
{
|
||||
super(UUIDGen.makeType1UUIDFromHost(FBUtilities.getBroadcastAddress()), DatabaseDescriptor.getDefsVersion());
|
||||
super(UUIDGen.makeType1UUIDFromHost(FBUtilities.getBroadcastAddress()), Schema.instance.getVersion());
|
||||
this.oldName = oldName;
|
||||
this.newName = newName;
|
||||
|
||||
KSMetaData oldKsm = DatabaseDescriptor.getTableDefinition(oldName);
|
||||
KSMetaData oldKsm = schema.getTableDefinition(oldName);
|
||||
if (oldKsm == null)
|
||||
throw new ConfigurationException("Keyspace either does not exist or does not match the one currently defined.");
|
||||
if (DatabaseDescriptor.getTableDefinition(newName) != null)
|
||||
if (schema.getTableDefinition(newName) != null)
|
||||
throw new ConfigurationException("Keyspace already exists.");
|
||||
if (!Migration.isLegalName(newName))
|
||||
throw new ConfigurationException("Invalid keyspace name: " + newName);
|
||||
|
|
@ -64,7 +61,7 @@ public class RenameKeyspace extends Migration
|
|||
rm = makeDefinitionMutation(newKsm, oldKsm, newVersion);
|
||||
}
|
||||
|
||||
private static KSMetaData rename(KSMetaData ksm, String newName, boolean purgeOldCfs)
|
||||
private KSMetaData rename(KSMetaData ksm, String newName, boolean purgeOldCfs)
|
||||
{
|
||||
// cfs will need to have their tablenames reset. CFMetaData are immutable, so new ones get created with the
|
||||
// same ids.
|
||||
|
|
@ -72,7 +69,7 @@ public class RenameKeyspace extends Migration
|
|||
for (CFMetaData oldCf : ksm.cfMetaData().values())
|
||||
{
|
||||
if (purgeOldCfs)
|
||||
CFMetaData.purge(oldCf);
|
||||
schema.purge(oldCf);
|
||||
newCfs.add(CFMetaData.renameTable(oldCf, newName));
|
||||
}
|
||||
return new KSMetaData(newName, ksm.strategyClass, ksm.strategyOptions, newCfs.toArray(new CFMetaData[newCfs.size()]));
|
||||
|
|
@ -83,15 +80,15 @@ public class RenameKeyspace extends Migration
|
|||
if (!StorageService.instance.isClientMode())
|
||||
renameKsStorageFiles(oldName, newName);
|
||||
|
||||
KSMetaData oldKsm = DatabaseDescriptor.getTableDefinition(oldName);
|
||||
KSMetaData oldKsm = schema.getTableDefinition(oldName);
|
||||
for (CFMetaData cfm : oldKsm.cfMetaData().values())
|
||||
CFMetaData.purge(cfm);
|
||||
schema.purge(cfm);
|
||||
KSMetaData newKsm = rename(oldKsm, newName, true);
|
||||
for (CFMetaData cfm : newKsm.cfMetaData().values())
|
||||
{
|
||||
try
|
||||
{
|
||||
CFMetaData.map(cfm);
|
||||
schema.load(cfm);
|
||||
}
|
||||
catch (ConfigurationException ex)
|
||||
{
|
||||
|
|
@ -102,13 +99,13 @@ public class RenameKeyspace extends Migration
|
|||
}
|
||||
// ^^ at this point, the static methods in CFMetaData will start returning references to the new table, so
|
||||
// it helps if the node is reasonably quiescent with respect to this ks.
|
||||
DatabaseDescriptor.clearTableDefinition(oldKsm, newVersion);
|
||||
DatabaseDescriptor.setTableDefinition(newKsm, newVersion);
|
||||
schema.clearTableDefinition(oldKsm, newVersion);
|
||||
schema.setTableDefinition(newKsm, newVersion);
|
||||
|
||||
if (!StorageService.instance.isClientMode())
|
||||
{
|
||||
Table.clear(oldKsm.name);
|
||||
Table.open(newName);
|
||||
Table.clear(oldKsm.name, schema);
|
||||
Table.open(newName, schema);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,9 +39,9 @@ public class UpdateColumnFamily extends Migration
|
|||
/** assumes validation has already happened. That is, replacing oldCfm with newCfm is neither illegal or totally whackass. */
|
||||
public UpdateColumnFamily(org.apache.cassandra.db.migration.avro.CfDef cf_def) throws ConfigurationException, IOException
|
||||
{
|
||||
super(UUIDGen.makeType1UUIDFromHost(FBUtilities.getBroadcastAddress()), DatabaseDescriptor.getDefsVersion());
|
||||
super(UUIDGen.makeType1UUIDFromHost(FBUtilities.getBroadcastAddress()), Schema.instance.getVersion());
|
||||
|
||||
KSMetaData ksm = DatabaseDescriptor.getTableDefinition(cf_def.keyspace.toString());
|
||||
KSMetaData ksm = schema.getTableDefinition(cf_def.keyspace.toString());
|
||||
if (ksm == null)
|
||||
throw new ConfigurationException("No such keyspace: " + cf_def.keyspace.toString());
|
||||
if (cf_def.column_metadata != null)
|
||||
|
|
@ -53,7 +53,7 @@ public class UpdateColumnFamily extends Migration
|
|||
}
|
||||
}
|
||||
|
||||
CFMetaData oldCfm = DatabaseDescriptor.getCFMetaData(CFMetaData.getId(cf_def.keyspace.toString(), cf_def.name.toString()));
|
||||
CFMetaData oldCfm = schema.getCFMetaData(cf_def.keyspace.toString(), cf_def.name.toString());
|
||||
|
||||
// create a copy of the old CF meta data. Apply new settings on top of it.
|
||||
this.metadata = CFMetaData.inflate(oldCfm.deflate());
|
||||
|
|
@ -62,26 +62,26 @@ public class UpdateColumnFamily extends Migration
|
|||
// create a copy of the old KS meta data. Use it to create a RowMutation that gets applied to schema and migrations.
|
||||
KSMetaData newKsMeta = KSMetaData.inflate(ksm.deflate());
|
||||
newKsMeta.cfMetaData().get(cf_def.name.toString()).apply(cf_def);
|
||||
rm = Migration.makeDefinitionMutation(newKsMeta, null, newVersion);
|
||||
rm = makeDefinitionMutation(newKsMeta, null, newVersion);
|
||||
}
|
||||
|
||||
void applyModels() throws IOException
|
||||
{
|
||||
logger.debug("Updating " + DatabaseDescriptor.getCFMetaData(metadata.cfId) + " to " + metadata);
|
||||
logger.debug("Updating " + schema.getCFMetaData(metadata.cfId) + " to " + metadata);
|
||||
// apply the meta update.
|
||||
try
|
||||
{
|
||||
DatabaseDescriptor.getCFMetaData(metadata.cfId).apply(CFMetaData.convertToAvro(metadata));
|
||||
schema.getCFMetaData(metadata.cfId).apply(CFMetaData.convertToAvro(metadata));
|
||||
}
|
||||
catch (ConfigurationException ex)
|
||||
{
|
||||
throw new IOException(ex);
|
||||
}
|
||||
DatabaseDescriptor.setTableDefinition(null, newVersion);
|
||||
schema.setTableDefinition(null, newVersion);
|
||||
|
||||
if (!StorageService.instance.isClientMode())
|
||||
{
|
||||
Table table = Table.open(metadata.ksName);
|
||||
Table table = Table.open(metadata.ksName, schema);
|
||||
ColumnFamilyStore oldCfs = table.getColumnFamilyStore(metadata.cfName);
|
||||
oldCfs.reload();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,10 +2,7 @@ package org.apache.cassandra.db.migration;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.config.ConfigurationException;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.config.KSMetaData;
|
||||
import org.apache.cassandra.config.*;
|
||||
import org.apache.cassandra.db.Table;
|
||||
import org.apache.cassandra.utils.FBUtilities;
|
||||
import org.apache.cassandra.utils.UUIDGen;
|
||||
|
|
@ -40,7 +37,7 @@ public class UpdateKeyspace extends Migration
|
|||
/** create migration based on thrift parameters */
|
||||
public UpdateKeyspace(KSMetaData ksm) throws ConfigurationException, IOException
|
||||
{
|
||||
super(UUIDGen.makeType1UUIDFromHost(FBUtilities.getBroadcastAddress()), DatabaseDescriptor.getDefsVersion());
|
||||
super(UUIDGen.makeType1UUIDFromHost(FBUtilities.getBroadcastAddress()), Schema.instance.getVersion());
|
||||
|
||||
assert ksm != null;
|
||||
assert ksm.cfMetaData() != null;
|
||||
|
|
@ -48,7 +45,7 @@ public class UpdateKeyspace extends Migration
|
|||
throw new ConfigurationException("Updated keyspace must not contain any column families");
|
||||
|
||||
// create the new ksm by merging the one passed in with the cf defs from the exisitng ksm.
|
||||
oldKsm = DatabaseDescriptor.getKSMetaData(ksm.name);
|
||||
oldKsm = schema.getKSMetaData(ksm.name);
|
||||
if (oldKsm == null)
|
||||
throw new ConfigurationException(ksm.name + " cannot be updated because it doesn't exist.");
|
||||
|
||||
|
|
@ -58,10 +55,10 @@ public class UpdateKeyspace extends Migration
|
|||
|
||||
void applyModels() throws IOException
|
||||
{
|
||||
DatabaseDescriptor.clearTableDefinition(oldKsm, newVersion);
|
||||
DatabaseDescriptor.setTableDefinition(newKsm, newVersion);
|
||||
schema.clearTableDefinition(oldKsm, newVersion);
|
||||
schema.setTableDefinition(newKsm, newVersion);
|
||||
|
||||
Table table = Table.open(newKsm.name);
|
||||
Table table = Table.open(newKsm.name, schema);
|
||||
try
|
||||
{
|
||||
table.createReplicationStrategy(newKsm);
|
||||
|
|
|
|||
|
|
@ -20,19 +20,12 @@ package org.apache.cassandra.dht;
|
|||
|
||||
import java.math.BigInteger;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.*;
|
||||
|
||||
import org.apache.cassandra.config.ConfigurationException;
|
||||
import org.apache.cassandra.config.*;
|
||||
import org.apache.cassandra.utils.ByteBufferUtil;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.db.DecoratedKey;
|
||||
import org.apache.cassandra.service.StorageService;
|
||||
import org.apache.cassandra.utils.FBUtilities;
|
||||
|
|
@ -197,9 +190,9 @@ public abstract class AbstractByteOrderedPartitioner implements IPartitioner<Byt
|
|||
lastToken = node;
|
||||
}
|
||||
|
||||
for (String ks : DatabaseDescriptor.getTables())
|
||||
for (String ks : Schema.instance.getTables())
|
||||
{
|
||||
for (CFMetaData cfmd : DatabaseDescriptor.getKSMetaData(ks).cfMetaData().values())
|
||||
for (CFMetaData cfmd : Schema.instance.getKSMetaData(ks).cfMetaData().values())
|
||||
{
|
||||
for (Range r : sortedRanges)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ package org.apache.cassandra.dht;
|
|||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import org.apache.cassandra.config.Schema;
|
||||
import org.apache.cassandra.gms.Gossiper;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
|
@ -82,7 +83,7 @@ public class BootStrapper
|
|||
final Multimap<String, Map.Entry<InetAddress, Collection<Range>>> rangesToFetch = HashMultimap.create();
|
||||
|
||||
int requests = 0;
|
||||
for (String table : DatabaseDescriptor.getNonSystemTables())
|
||||
for (String table : Schema.instance.getNonSystemTables())
|
||||
{
|
||||
Map<InetAddress, Collection<Range>> workMap = getWorkMap(getRangesWithSources(table)).asMap();
|
||||
for (Map.Entry<InetAddress, Collection<Range>> entry : workMap.entrySet())
|
||||
|
|
|
|||
|
|
@ -23,9 +23,7 @@ import java.nio.ByteBuffer;
|
|||
import java.nio.charset.CharacterCodingException;
|
||||
import java.util.*;
|
||||
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.config.ConfigurationException;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.config.*;
|
||||
import org.apache.cassandra.db.DecoratedKey;
|
||||
import org.apache.cassandra.gms.VersionedValue;
|
||||
import org.apache.cassandra.service.StorageService;
|
||||
|
|
@ -189,9 +187,9 @@ public class OrderPreservingPartitioner implements IPartitioner<StringToken>
|
|||
lastToken = node;
|
||||
}
|
||||
|
||||
for (String ks : DatabaseDescriptor.getTables())
|
||||
for (String ks : Schema.instance.getTables())
|
||||
{
|
||||
for (CFMetaData cfmd : DatabaseDescriptor.getKSMetaData(ks).cfMetaData().values())
|
||||
for (CFMetaData cfmd : Schema.instance.getKSMetaData(ks).cfMetaData().values())
|
||||
{
|
||||
for (Range r : sortedRanges)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Collections2;
|
||||
import org.apache.cassandra.config.Schema;
|
||||
import org.apache.cassandra.io.compress.CompressedRandomAccessReader;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
@ -105,7 +106,7 @@ public class SSTableReader extends SSTable
|
|||
public static SSTableReader open(Descriptor desc) throws IOException
|
||||
{
|
||||
Set<Component> components = componentsFor(desc, Descriptor.TempState.ANY);
|
||||
return open(desc, components, DatabaseDescriptor.getCFMetaData(desc.ksname, desc.cfname), StorageService.getPartitioner());
|
||||
return open(desc, components, Schema.instance.getCFMetaData(desc.ksname, desc.cfname), StorageService.getPartitioner());
|
||||
}
|
||||
|
||||
public static SSTableReader open(Descriptor descriptor, Set<Component> components, CFMetaData metadata, IPartitioner partitioner) throws IOException
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import java.util.*;
|
|||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import org.apache.cassandra.config.Schema;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
@ -56,7 +57,7 @@ public class SSTableWriter extends SSTable
|
|||
{
|
||||
this(filename,
|
||||
keyCount,
|
||||
DatabaseDescriptor.getCFMetaData(Descriptor.fromFilename(filename)),
|
||||
Schema.instance.getCFMetaData(Descriptor.fromFilename(filename)),
|
||||
StorageService.getPartitioner(),
|
||||
SSTableMetadata.createCollector());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,20 +20,16 @@ package org.apache.cassandra.service;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.net.InetAddress;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
import java.util.concurrent.SynchronousQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import javax.management.MBeanServer;
|
||||
import javax.management.ObjectName;
|
||||
|
||||
import org.apache.cassandra.config.Schema;
|
||||
import org.apache.cassandra.gms.Gossiper;
|
||||
import org.apache.log4j.PropertyConfigurator;
|
||||
import org.slf4j.Logger;
|
||||
|
|
@ -49,7 +45,6 @@ import org.apache.cassandra.db.Table;
|
|||
import org.apache.cassandra.db.commitlog.CommitLog;
|
||||
import org.apache.cassandra.db.migration.Migration;
|
||||
import org.apache.cassandra.utils.CLibrary;
|
||||
import org.apache.cassandra.utils.FBUtilities;
|
||||
import org.apache.cassandra.utils.Mx4jTool;
|
||||
|
||||
/**
|
||||
|
|
@ -141,7 +136,7 @@ public abstract class AbstractCassandraDaemon implements CassandraDaemon
|
|||
// check the system table to keep user from shooting self in foot by changing partitioner, cluster name, etc.
|
||||
// we do a one-off scrub of the system table first; we can't load the list of the rest of the tables,
|
||||
// until system table is opened.
|
||||
for (CFMetaData cfm : DatabaseDescriptor.getTableMetaData(Table.SYSTEM_TABLE).values())
|
||||
for (CFMetaData cfm : Schema.instance.getTableMetaData(Table.SYSTEM_TABLE).values())
|
||||
ColumnFamilyStore.scrubDataDirectories(Table.SYSTEM_TABLE, cfm.cfName);
|
||||
try
|
||||
{
|
||||
|
|
@ -165,16 +160,16 @@ public abstract class AbstractCassandraDaemon implements CassandraDaemon
|
|||
}
|
||||
|
||||
// clean up debris in the rest of the tables
|
||||
for (String table : DatabaseDescriptor.getTables())
|
||||
for (String table : Schema.instance.getTables())
|
||||
{
|
||||
for (CFMetaData cfm : DatabaseDescriptor.getTableMetaData(table).values())
|
||||
for (CFMetaData cfm : Schema.instance.getTableMetaData(table).values())
|
||||
{
|
||||
ColumnFamilyStore.scrubDataDirectories(table, cfm.cfName);
|
||||
}
|
||||
}
|
||||
|
||||
// initialize keyspaces
|
||||
for (String table : DatabaseDescriptor.getTables())
|
||||
for (String table : Schema.instance.getTables())
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("opening keyspace " + table);
|
||||
|
|
@ -196,7 +191,7 @@ public abstract class AbstractCassandraDaemon implements CassandraDaemon
|
|||
// check to see if CL.recovery modified the lastMigrationId. if it did, we need to re apply migrations. this isn't
|
||||
// the same as merely reloading the schema (which wouldn't perform file deletion after a DROP). The solution
|
||||
// is to read those migrations from disk and apply them.
|
||||
UUID currentMigration = DatabaseDescriptor.getDefsVersion();
|
||||
UUID currentMigration = Schema.instance.getVersion();
|
||||
UUID lastMigration = Migration.getLastMigrationId();
|
||||
if ((lastMigration != null) && (lastMigration.timestamp() > currentMigration.timestamp()))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -28,13 +28,13 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.MapMaker;
|
||||
import org.apache.cassandra.config.Schema;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.apache.cassandra.concurrent.Stage;
|
||||
import org.apache.cassandra.concurrent.StageManager;
|
||||
import org.apache.cassandra.config.ConfigurationException;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.db.Column;
|
||||
import org.apache.cassandra.db.IColumn;
|
||||
import org.apache.cassandra.db.marshal.TimeUUIDType;
|
||||
|
|
@ -42,9 +42,7 @@ import org.apache.cassandra.db.migration.Migration;
|
|||
import org.apache.cassandra.gms.*;
|
||||
import org.apache.cassandra.io.util.FastByteArrayInputStream;
|
||||
import org.apache.cassandra.io.util.FastByteArrayOutputStream;
|
||||
import org.apache.cassandra.net.CachingMessageProducer;
|
||||
import org.apache.cassandra.net.Message;
|
||||
import org.apache.cassandra.net.MessageProducer;
|
||||
import org.apache.cassandra.net.MessagingService;
|
||||
import org.apache.cassandra.utils.ByteBufferUtil;
|
||||
import org.apache.cassandra.utils.FBUtilities;
|
||||
|
|
@ -88,7 +86,7 @@ public class MigrationManager implements IEndpointStateChangeSubscriber
|
|||
*/
|
||||
public static void rectify(UUID theirVersion, InetAddress endpoint)
|
||||
{
|
||||
UUID myVersion = DatabaseDescriptor.getDefsVersion();
|
||||
UUID myVersion = Schema.instance.getVersion();
|
||||
if (theirVersion.timestamp() < myVersion.timestamp()
|
||||
&& !StorageService.instance.isClientMode())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import java.util.concurrent.TimeUnit;
|
|||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.apache.cassandra.config.Schema;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
@ -97,7 +98,7 @@ public class ReadCallback<T> implements IAsyncCallback
|
|||
assert command instanceof ReadCommand : command;
|
||||
String table = ((RowDigestResolver) resolver).table;
|
||||
String columnFamily = ((ReadCommand) command).getColumnFamilyName();
|
||||
CFMetaData cfmd = DatabaseDescriptor.getTableMetaData(table).get(columnFamily);
|
||||
CFMetaData cfmd = Schema.instance.getTableMetaData(table).get(columnFamily);
|
||||
return cfmd.getReadRepairChance() > random.get().nextDouble();
|
||||
}
|
||||
// we don't read repair on range scans
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import com.google.common.collect.HashMultimap;
|
|||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
import org.apache.cassandra.config.Schema;
|
||||
import org.apache.cassandra.net.*;
|
||||
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
|
|
@ -802,7 +803,7 @@ public class StorageProxy implements StorageProxyMBean
|
|||
*/
|
||||
public static Map<String, List<String>> describeSchemaVersions()
|
||||
{
|
||||
final String myVersion = DatabaseDescriptor.getDefsVersion().toString();
|
||||
final String myVersion = Schema.instance.getVersion().toString();
|
||||
final Map<InetAddress, UUID> versions = new ConcurrentHashMap<InetAddress, UUID>();
|
||||
final Set<InetAddress> liveHosts = Gossiper.instance.getLiveMembers();
|
||||
final CountDownLatch latch = new CountDownLatch(liveHosts.size());
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ import javax.management.ObjectName;
|
|||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import org.apache.cassandra.config.*;
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
|
|
@ -41,10 +42,6 @@ import org.slf4j.LoggerFactory;
|
|||
import org.apache.cassandra.concurrent.DebuggableScheduledThreadPoolExecutor;
|
||||
import org.apache.cassandra.concurrent.Stage;
|
||||
import org.apache.cassandra.concurrent.StageManager;
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.config.ConfigurationException;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.config.KSMetaData;
|
||||
import org.apache.cassandra.db.*;
|
||||
import org.apache.cassandra.db.commitlog.CommitLog;
|
||||
import org.apache.cassandra.dht.*;
|
||||
|
|
@ -364,7 +361,7 @@ public class StorageService implements IEndpointStateChangeSubscriber, StorageSe
|
|||
{
|
||||
throw new IOError(ex);
|
||||
}
|
||||
MigrationManager.passiveAnnounce(DatabaseDescriptor.getDefsVersion());
|
||||
MigrationManager.passiveAnnounce(Schema.instance.getVersion());
|
||||
}
|
||||
|
||||
public synchronized void initServer() throws IOException, ConfigurationException
|
||||
|
|
@ -418,7 +415,7 @@ public class StorageService implements IEndpointStateChangeSubscriber, StorageSe
|
|||
List<Future<?>> flushes = new ArrayList<Future<?>>();
|
||||
for (Table table : Table.all())
|
||||
{
|
||||
KSMetaData ksm = DatabaseDescriptor.getKSMetaData(table.name);
|
||||
KSMetaData ksm = Schema.instance.getKSMetaData(table.name);
|
||||
if (!ksm.isDurableWrites())
|
||||
{
|
||||
for (ColumnFamilyStore cfs : table.getColumnFamilyStores())
|
||||
|
|
@ -460,7 +457,7 @@ public class StorageService implements IEndpointStateChangeSubscriber, StorageSe
|
|||
|
||||
MessagingService.instance().listen(FBUtilities.getLocalAddress());
|
||||
LoadBroadcaster.instance.startBroadcasting();
|
||||
MigrationManager.passiveAnnounce(DatabaseDescriptor.getDefsVersion());
|
||||
MigrationManager.passiveAnnounce(Schema.instance.getVersion());
|
||||
Gossiper.instance.addLocalApplicationState(ApplicationState.RELEASE_VERSION, valueFactory.releaseVersion());
|
||||
|
||||
HintedHandOffManager.instance.registerMBean();
|
||||
|
|
@ -493,7 +490,7 @@ public class StorageService implements IEndpointStateChangeSubscriber, StorageSe
|
|||
setMode("Joining: getting bootstrap token", true);
|
||||
token = BootStrapper.getBootstrapToken(tokenMetadata_, LoadBroadcaster.instance.getLoadInfo());
|
||||
// don't bootstrap if there are no tables defined.
|
||||
if (DatabaseDescriptor.getNonSystemTables().size() > 0)
|
||||
if (Schema.instance.getNonSystemTables().size() > 0)
|
||||
{
|
||||
bootstrap(token);
|
||||
assert !isBootstrapMode; // bootstrap will block until finished
|
||||
|
|
@ -598,7 +595,7 @@ public class StorageService implements IEndpointStateChangeSubscriber, StorageSe
|
|||
// some people just want to get a visual representation of things. Allow null and set it to the first
|
||||
// non-system table.
|
||||
if (keyspace == null)
|
||||
keyspace = DatabaseDescriptor.getNonSystemTables().get(0);
|
||||
keyspace = Schema.instance.getNonSystemTables().get(0);
|
||||
|
||||
/* All the ranges for the tokens */
|
||||
Map<Range, List<String>> map = new HashMap<Range, List<String>>();
|
||||
|
|
@ -622,7 +619,7 @@ public class StorageService implements IEndpointStateChangeSubscriber, StorageSe
|
|||
// some people just want to get a visual representation of things. Allow null and set it to the first
|
||||
// non-system table.
|
||||
if (keyspace == null)
|
||||
keyspace = DatabaseDescriptor.getNonSystemTables().get(0);
|
||||
keyspace = Schema.instance.getNonSystemTables().get(0);
|
||||
|
||||
Map<Range, List<String>> map = new HashMap<Range, List<String>>();
|
||||
for (Map.Entry<Range, Collection<InetAddress>> entry : tokenMetadata_.getPendingRanges(keyspace).entrySet())
|
||||
|
|
@ -992,7 +989,7 @@ public class StorageService implements IEndpointStateChangeSubscriber, StorageSe
|
|||
*/
|
||||
private void calculatePendingRanges()
|
||||
{
|
||||
for (String table : DatabaseDescriptor.getNonSystemTables())
|
||||
for (String table : Schema.instance.getNonSystemTables())
|
||||
calculatePendingRanges(Table.open(table).getReplicationStrategy(), table);
|
||||
}
|
||||
|
||||
|
|
@ -1153,7 +1150,7 @@ public class StorageService implements IEndpointStateChangeSubscriber, StorageSe
|
|||
|
||||
final InetAddress myAddress = FBUtilities.getBroadcastAddress();
|
||||
|
||||
for (String table : DatabaseDescriptor.getNonSystemTables())
|
||||
for (String table : Schema.instance.getNonSystemTables())
|
||||
{
|
||||
Multimap<Range, InetAddress> changedRanges = getChangedRangesForLeaving(table, endpoint);
|
||||
Set<Range> myNewRanges = new HashSet<Range>();
|
||||
|
|
@ -1268,7 +1265,7 @@ public class StorageService implements IEndpointStateChangeSubscriber, StorageSe
|
|||
public double getLoad()
|
||||
{
|
||||
double bytes = 0;
|
||||
for (String tableName : DatabaseDescriptor.getTables())
|
||||
for (String tableName : Schema.instance.getTables())
|
||||
{
|
||||
Table table = Table.open(tableName);
|
||||
for (ColumnFamilyStore cfs : table.getColumnFamilyStores())
|
||||
|
|
@ -1472,7 +1469,7 @@ public class StorageService implements IEndpointStateChangeSubscriber, StorageSe
|
|||
|
||||
private Table getValidTable(String tableName) throws IOException
|
||||
{
|
||||
if (!DatabaseDescriptor.getTables().contains(tableName))
|
||||
if (!Schema.instance.getTables().contains(tableName))
|
||||
{
|
||||
throw new IOException("Table " + tableName + "does not exist");
|
||||
}
|
||||
|
|
@ -1689,7 +1686,7 @@ public class StorageService implements IEndpointStateChangeSubscriber, StorageSe
|
|||
*/
|
||||
public List<InetAddress> getNaturalEndpoints(String table, String cf, String key)
|
||||
{
|
||||
CFMetaData cfMetaData = DatabaseDescriptor.getTableDefinition(table).cfMetaData().get(cf);
|
||||
CFMetaData cfMetaData = Schema.instance.getTableDefinition(table).cfMetaData().get(cf);
|
||||
return getNaturalEndpoints(table, partitioner.getToken(cfMetaData.getKeyValidator().fromString(key)));
|
||||
}
|
||||
|
||||
|
|
@ -1832,7 +1829,7 @@ public class StorageService implements IEndpointStateChangeSubscriber, StorageSe
|
|||
throw new UnsupportedOperationException("local node is not a member of the token ring yet");
|
||||
if (tokenMetadata_.cloneAfterAllLeft().sortedTokens().size() < 2)
|
||||
throw new UnsupportedOperationException("no other normal nodes in the ring; decommission would be pointless");
|
||||
for (String table : DatabaseDescriptor.getNonSystemTables())
|
||||
for (String table : Schema.instance.getNonSystemTables())
|
||||
{
|
||||
if (tokenMetadata_.getPendingRanges(table, FBUtilities.getBroadcastAddress()).size() > 0)
|
||||
throw new UnsupportedOperationException("data is currently moving to this node; unable to leave the ring");
|
||||
|
|
@ -1880,7 +1877,7 @@ public class StorageService implements IEndpointStateChangeSubscriber, StorageSe
|
|||
{
|
||||
Map<String, Multimap<Range, InetAddress>> rangesToStream = new HashMap<String, Multimap<Range, InetAddress>>();
|
||||
|
||||
for (final String table : DatabaseDescriptor.getNonSystemTables())
|
||||
for (final String table : Schema.instance.getNonSystemTables())
|
||||
{
|
||||
Multimap<Range, InetAddress> rangesMM = getChangedRangesForLeaving(table, FBUtilities.getBroadcastAddress());
|
||||
|
||||
|
|
@ -1932,7 +1929,7 @@ public class StorageService implements IEndpointStateChangeSubscriber, StorageSe
|
|||
|
||||
// address of the current node
|
||||
InetAddress localAddress = FBUtilities.getBroadcastAddress();
|
||||
List<String> tablesToProcess = DatabaseDescriptor.getNonSystemTables();
|
||||
List<String> tablesToProcess = Schema.instance.getNonSystemTables();
|
||||
|
||||
// checking if data is moving to this node
|
||||
for (String table : tablesToProcess)
|
||||
|
|
@ -2121,7 +2118,7 @@ public class StorageService implements IEndpointStateChangeSubscriber, StorageSe
|
|||
throw new UnsupportedOperationException("This node is already processing a removal. Wait for it to complete, or use 'removetoken force' if this has failed.");
|
||||
|
||||
// Find the endpoints that are going to become responsible for data
|
||||
for (String table : DatabaseDescriptor.getNonSystemTables())
|
||||
for (String table : Schema.instance.getNonSystemTables())
|
||||
{
|
||||
// if the replication factor is 1 the data is lost so we shouldn't wait for confirmation
|
||||
if (Table.open(table).getReplicationStrategy().getReplicationFactor() == 1)
|
||||
|
|
@ -2253,7 +2250,7 @@ public class StorageService implements IEndpointStateChangeSubscriber, StorageSe
|
|||
// lets flush.
|
||||
setMode("Draining: flushing column families", false);
|
||||
List<ColumnFamilyStore> cfses = new ArrayList<ColumnFamilyStore>();
|
||||
for (String tableName : DatabaseDescriptor.getNonSystemTables())
|
||||
for (String tableName : Schema.instance.getNonSystemTables())
|
||||
{
|
||||
Table table = Table.open(tableName);
|
||||
cfses.addAll(table.getColumnFamilyStores());
|
||||
|
|
@ -2319,7 +2316,7 @@ public class StorageService implements IEndpointStateChangeSubscriber, StorageSe
|
|||
|
||||
public List<String> getKeyspaces()
|
||||
{
|
||||
List<String> tableslist = new ArrayList<String>(DatabaseDescriptor.getTables());
|
||||
List<String> tableslist = new ArrayList<String>(Schema.instance.getTables());
|
||||
return Collections.unmodifiableList(tableslist);
|
||||
}
|
||||
|
||||
|
|
@ -2339,7 +2336,7 @@ public class StorageService implements IEndpointStateChangeSubscriber, StorageSe
|
|||
|
||||
// point snitch references to the new instance
|
||||
DatabaseDescriptor.setEndpointSnitch(newSnitch);
|
||||
for (String ks : DatabaseDescriptor.getTables())
|
||||
for (String ks : Schema.instance.getTables())
|
||||
{
|
||||
Table.open(ks).getReplicationStrategy().snitch = newSnitch;
|
||||
}
|
||||
|
|
@ -2578,7 +2575,7 @@ public class StorageService implements IEndpointStateChangeSubscriber, StorageSe
|
|||
|
||||
public boolean validateColumnFamily(String keyspace, String cfName)
|
||||
{
|
||||
return DatabaseDescriptor.getCFMetaData(keyspace, cfName) != null;
|
||||
return Schema.instance.getCFMetaData(keyspace, cfName) != null;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@
|
|||
|
||||
package org.apache.cassandra.thrift;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.SocketAddress;
|
||||
|
|
@ -649,8 +648,8 @@ public class CassandraServer implements Cassandra.Iface
|
|||
public KsDef describe_keyspace(String table) throws NotFoundException, InvalidRequestException
|
||||
{
|
||||
state().hasKeyspaceListAccess(Permission.READ);
|
||||
|
||||
KSMetaData ksm = DatabaseDescriptor.getTableDefinition(table);
|
||||
|
||||
KSMetaData ksm = Schema.instance.getTableDefinition(table);
|
||||
if (ksm == null)
|
||||
throw new NotFoundException();
|
||||
|
||||
|
|
@ -754,8 +753,8 @@ public class CassandraServer implements Cassandra.Iface
|
|||
public List<KsDef> describe_keyspaces() throws TException, InvalidRequestException
|
||||
{
|
||||
state().hasKeyspaceListAccess(Permission.READ);
|
||||
|
||||
Set<String> keyspaces = DatabaseDescriptor.getTables();
|
||||
|
||||
Set<String> keyspaces = Schema.instance.getTables();
|
||||
List<KsDef> ksset = new ArrayList<KsDef>();
|
||||
for (String ks : keyspaces)
|
||||
{
|
||||
|
|
@ -783,7 +782,7 @@ public class CassandraServer implements Cassandra.Iface
|
|||
|
||||
public List<TokenRange> describe_ring(String keyspace)throws InvalidRequestException
|
||||
{
|
||||
if (keyspace == null || !DatabaseDescriptor.getNonSystemTables().contains(keyspace))
|
||||
if (keyspace == null || !Schema.instance.getNonSystemTables().contains(keyspace))
|
||||
throw new InvalidRequestException("There is no ring for the keyspace: " + keyspace);
|
||||
List<TokenRange> ranges = new ArrayList<TokenRange>();
|
||||
Token.TokenFactory tf = StorageService.getPartitioner().getTokenFactory();
|
||||
|
|
@ -882,7 +881,7 @@ public class CassandraServer implements Cassandra.Iface
|
|||
try
|
||||
{
|
||||
applyMigrationOnStage(new AddColumnFamily(CFMetaData.fromThrift(cf_def)));
|
||||
return DatabaseDescriptor.getDefsVersion().toString();
|
||||
return Schema.instance.getVersion().toString();
|
||||
}
|
||||
catch (ConfigurationException e)
|
||||
{
|
||||
|
|
@ -908,7 +907,7 @@ public class CassandraServer implements Cassandra.Iface
|
|||
try
|
||||
{
|
||||
applyMigrationOnStage(new DropColumnFamily(state().getKeyspace(), column_family));
|
||||
return DatabaseDescriptor.getDefsVersion().toString();
|
||||
return Schema.instance.getVersion().toString();
|
||||
}
|
||||
catch (ConfigurationException e)
|
||||
{
|
||||
|
|
@ -952,7 +951,7 @@ public class CassandraServer implements Cassandra.Iface
|
|||
|
||||
ThriftValidation.validateKsDef(ks_def);
|
||||
applyMigrationOnStage(new AddKeyspace(KSMetaData.fromThrift(ks_def, cfDefs.toArray(new CFMetaData[cfDefs.size()]))));
|
||||
return DatabaseDescriptor.getDefsVersion().toString();
|
||||
return Schema.instance.getVersion().toString();
|
||||
}
|
||||
catch (ConfigurationException e)
|
||||
{
|
||||
|
|
@ -978,7 +977,7 @@ public class CassandraServer implements Cassandra.Iface
|
|||
try
|
||||
{
|
||||
applyMigrationOnStage(new DropKeyspace(keyspace));
|
||||
return DatabaseDescriptor.getDefsVersion().toString();
|
||||
return Schema.instance.getVersion().toString();
|
||||
}
|
||||
catch (ConfigurationException e)
|
||||
{
|
||||
|
|
@ -1010,7 +1009,7 @@ public class CassandraServer implements Cassandra.Iface
|
|||
{
|
||||
ThriftValidation.validateKsDef(ks_def);
|
||||
applyMigrationOnStage(new UpdateKeyspace(KSMetaData.fromThrift(ks_def)));
|
||||
return DatabaseDescriptor.getDefsVersion().toString();
|
||||
return Schema.instance.getVersion().toString();
|
||||
}
|
||||
catch (ConfigurationException e)
|
||||
{
|
||||
|
|
@ -1033,7 +1032,7 @@ public class CassandraServer implements Cassandra.Iface
|
|||
state().hasColumnFamilyListAccess(Permission.WRITE);
|
||||
if (cf_def.keyspace == null || cf_def.name == null)
|
||||
throw new InvalidRequestException("Keyspace and CF name must be set.");
|
||||
CFMetaData oldCfm = DatabaseDescriptor.getCFMetaData(CFMetaData.getId(cf_def.keyspace, cf_def.name));
|
||||
CFMetaData oldCfm = Schema.instance.getCFMetaData(cf_def.keyspace, cf_def.name);
|
||||
if (oldCfm == null)
|
||||
throw new InvalidRequestException("Could not find column family definition to modify.");
|
||||
CFMetaData.addDefaultIndexNames(cf_def);
|
||||
|
|
@ -1046,7 +1045,7 @@ public class CassandraServer implements Cassandra.Iface
|
|||
CFMetaData.applyImplicitDefaults(cf_def);
|
||||
UpdateColumnFamily update = new UpdateColumnFamily(CFMetaData.convertToAvro(cf_def));
|
||||
applyMigrationOnStage(update);
|
||||
return DatabaseDescriptor.getDefsVersion().toString();
|
||||
return Schema.instance.getVersion().toString();
|
||||
}
|
||||
catch (ConfigurationException e)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ public class ThriftValidation
|
|||
|
||||
public static void validateTable(String tablename) throws KeyspaceNotDefinedException
|
||||
{
|
||||
if (!DatabaseDescriptor.getTables().contains(tablename))
|
||||
if (!Schema.instance.getTables().contains(tablename))
|
||||
{
|
||||
throw new KeyspaceNotDefinedException("Keyspace " + tablename + " does not exist");
|
||||
}
|
||||
|
|
@ -125,7 +125,7 @@ public class ThriftValidation
|
|||
if (cfName.isEmpty())
|
||||
throw new InvalidRequestException("non-empty columnfamily is required");
|
||||
|
||||
CFMetaData metadata = DatabaseDescriptor.getCFMetaData(tablename, cfName);
|
||||
CFMetaData metadata = Schema.instance.getCFMetaData(tablename, cfName);
|
||||
if (metadata == null)
|
||||
throw new InvalidRequestException("unconfigured columnfamily " + cfName);
|
||||
|
||||
|
|
@ -523,7 +523,7 @@ public class ThriftValidation
|
|||
me.getMessage()));
|
||||
}
|
||||
|
||||
AbstractType valueValidator = DatabaseDescriptor.getValueValidator(metadata.ksName, metadata.cfName, expression.column_name);
|
||||
AbstractType valueValidator = Schema.instance.getValueValidator(metadata.ksName, metadata.cfName, expression.column_name);
|
||||
try
|
||||
{
|
||||
valueValidator.validate(expression.value);
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import java.util.*;
|
|||
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.config.Schema;
|
||||
import org.apache.cassandra.db.*;
|
||||
import org.apache.cassandra.db.marshal.AbstractType;
|
||||
import org.apache.cassandra.io.util.RandomAccessReader;
|
||||
|
|
@ -387,7 +388,7 @@ public class SSTableExport
|
|||
String ssTableFileName = new File(cmd.getArgs()[0]).getAbsolutePath();
|
||||
|
||||
DatabaseDescriptor.loadSchemas();
|
||||
if (DatabaseDescriptor.getNonSystemTables().size() < 1)
|
||||
if (Schema.instance.getNonSystemTables().size() < 1)
|
||||
{
|
||||
String msg = "no non-system tables are defined";
|
||||
System.err.println(msg);
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import java.io.IOException;
|
|||
import java.nio.ByteBuffer;
|
||||
import java.util.*;
|
||||
|
||||
import org.apache.cassandra.config.Schema;
|
||||
import org.apache.cassandra.db.marshal.AbstractType;
|
||||
import org.apache.cassandra.db.marshal.BytesType;
|
||||
import org.apache.cassandra.db.marshal.MarshalException;
|
||||
|
|
@ -464,7 +465,7 @@ public class SSTableImport
|
|||
}
|
||||
|
||||
DatabaseDescriptor.loadSchemas();
|
||||
if (DatabaseDescriptor.getNonSystemTables().size() < 1)
|
||||
if (Schema.instance.getNonSystemTables().size() < 1)
|
||||
{
|
||||
String msg = "no non-system tables are defined";
|
||||
System.err.println(msg);
|
||||
|
|
|
|||
|
|
@ -18,27 +18,15 @@
|
|||
*/
|
||||
package org.apache.cassandra.db.compaction;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.*;
|
||||
|
||||
import org.apache.cassandra.config.Schema;
|
||||
import org.junit.Test;
|
||||
import org.apache.cassandra.CleanupHelper;
|
||||
import org.apache.cassandra.Util;
|
||||
import org.apache.cassandra.db.*;
|
||||
import org.apache.cassandra.db.compaction.CompactionManager;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.io.util.FileUtils;
|
||||
import org.apache.cassandra.io.sstable.Component;
|
||||
import org.apache.cassandra.io.sstable.SSTableReader;
|
||||
import org.apache.cassandra.io.sstable.SSTableUtils;
|
||||
import org.apache.cassandra.io.sstable.SSTableWriter;
|
||||
import org.apache.cassandra.streaming.OperationType;
|
||||
import org.apache.cassandra.utils.ByteBufferUtil;
|
||||
import org.apache.cassandra.utils.FBUtilities;
|
||||
import org.apache.cassandra.utils.NodeId;
|
||||
import static org.apache.cassandra.db.context.CounterContext.ContextState;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
|
||||
|
|
@ -104,7 +92,7 @@ public class LongCompactionSpeedTest extends CleanupHelper
|
|||
Thread.sleep(1000);
|
||||
|
||||
long start = System.currentTimeMillis();
|
||||
final int gcBefore = (int) (System.currentTimeMillis() / 1000) - DatabaseDescriptor.getCFMetaData(TABLE1, "Standard1").getGcGraceSeconds();
|
||||
final int gcBefore = (int) (System.currentTimeMillis() / 1000) - Schema.instance.getCFMetaData(TABLE1, "Standard1").getGcGraceSeconds();
|
||||
new CompactionTask(store, sstables, gcBefore).execute(null);
|
||||
System.out.println(String.format("%s: sstables=%d rowsper=%d colsper=%d: %d ms",
|
||||
this.getClass().getName(),
|
||||
|
|
|
|||
|
|
@ -22,12 +22,10 @@ import java.nio.ByteBuffer;
|
|||
import java.util.*;
|
||||
|
||||
import org.apache.cassandra.utils.ByteBufferUtil;
|
||||
import org.apache.commons.lang.NotImplementedException;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import org.apache.cassandra.config.*;
|
||||
import org.apache.cassandra.db.ColumnFamilyType;
|
||||
import org.apache.cassandra.db.KeyspaceNotDefinedException;
|
||||
import org.apache.cassandra.db.marshal.*;
|
||||
import org.apache.cassandra.locator.AbstractReplicationStrategy;
|
||||
import org.apache.cassandra.locator.SimpleStrategy;
|
||||
|
|
@ -54,12 +52,7 @@ public class SchemaLoader
|
|||
|
||||
try
|
||||
{
|
||||
for (KSMetaData ksm : schemaDefinition())
|
||||
{
|
||||
for (CFMetaData cfm : ksm.cfMetaData().values())
|
||||
CFMetaData.map(cfm);
|
||||
DatabaseDescriptor.setTableDefinition(ksm, DatabaseDescriptor.getDefsVersion());
|
||||
}
|
||||
Schema.instance.load(schemaDefinition(), Schema.instance.getVersion());
|
||||
}
|
||||
catch (ConfigurationException e)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -47,9 +47,9 @@ public class DatabaseDescriptorTest
|
|||
public void testCFMetaDataSerialization() throws IOException, ConfigurationException
|
||||
{
|
||||
// test serialization of all defined test CFs.
|
||||
for (String table : DatabaseDescriptor.getNonSystemTables())
|
||||
for (String table : Schema.instance.getNonSystemTables())
|
||||
{
|
||||
for (CFMetaData cfm : DatabaseDescriptor.getTableMetaData(table).values())
|
||||
for (CFMetaData cfm : Schema.instance.getTableMetaData(table).values())
|
||||
{
|
||||
CFMetaData cfmDupe = CFMetaData.inflate(serDe(cfm.deflate(), new org.apache.cassandra.db.migration.avro.CfDef()));
|
||||
assert cfmDupe != null;
|
||||
|
|
@ -61,7 +61,7 @@ public class DatabaseDescriptorTest
|
|||
@Test
|
||||
public void testKSMetaDataSerialization() throws IOException, ConfigurationException
|
||||
{
|
||||
for (KSMetaData ksm : DatabaseDescriptor.tables.values())
|
||||
for (KSMetaData ksm : Schema.instance.getTableDefinitions())
|
||||
{
|
||||
// Not testing round-trip on the KsDef via serDe() because maps
|
||||
// cannot be compared in avro.
|
||||
|
|
@ -77,26 +77,26 @@ public class DatabaseDescriptorTest
|
|||
{
|
||||
CleanupHelper.cleanupAndLeaveDirs();
|
||||
DatabaseDescriptor.loadSchemas();
|
||||
assert DatabaseDescriptor.getNonSystemTables().size() == 0;
|
||||
assert Schema.instance.getNonSystemTables().size() == 0;
|
||||
|
||||
// add a few.
|
||||
AddKeyspace ks0 = new AddKeyspace(new KSMetaData("ks0", SimpleStrategy.class, KSMetaData.optsWithRF(3)));
|
||||
ks0.apply();
|
||||
AddKeyspace ks1 = new AddKeyspace(new KSMetaData("ks1", SimpleStrategy.class, KSMetaData.optsWithRF(3)));
|
||||
ks1.apply();
|
||||
|
||||
assert DatabaseDescriptor.getTableDefinition("ks0") != null;
|
||||
assert DatabaseDescriptor.getTableDefinition("ks1") != null;
|
||||
|
||||
DatabaseDescriptor.clearTableDefinition(DatabaseDescriptor.getTableDefinition("ks0"), new UUID(4096, 0));
|
||||
DatabaseDescriptor.clearTableDefinition(DatabaseDescriptor.getTableDefinition("ks1"), new UUID(4096, 0));
|
||||
|
||||
assert DatabaseDescriptor.getTableDefinition("ks0") == null;
|
||||
assert DatabaseDescriptor.getTableDefinition("ks1") == null;
|
||||
|
||||
assert Schema.instance.getTableDefinition("ks0") != null;
|
||||
assert Schema.instance.getTableDefinition("ks1") != null;
|
||||
|
||||
Schema.instance.clearTableDefinition(Schema.instance.getTableDefinition("ks0"), new UUID(4096, 0));
|
||||
Schema.instance.clearTableDefinition(Schema.instance.getTableDefinition("ks1"), new UUID(4096, 0));
|
||||
|
||||
assert Schema.instance.getTableDefinition("ks0") == null;
|
||||
assert Schema.instance.getTableDefinition("ks1") == null;
|
||||
|
||||
DatabaseDescriptor.loadSchemas();
|
||||
|
||||
assert DatabaseDescriptor.getTableDefinition("ks0") != null;
|
||||
assert DatabaseDescriptor.getTableDefinition("ks1") != null;
|
||||
|
||||
assert Schema.instance.getTableDefinition("ks0") != null;
|
||||
assert Schema.instance.getTableDefinition("ks1") != null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,11 +29,7 @@ import java.util.concurrent.ExecutionException;
|
|||
import org.apache.avro.util.Utf8;
|
||||
import org.apache.cassandra.CleanupHelper;
|
||||
import org.apache.cassandra.Util;
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.config.ColumnDefinition;
|
||||
import org.apache.cassandra.config.ConfigurationException;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.config.KSMetaData;
|
||||
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.BytesType;
|
||||
|
|
@ -170,10 +166,10 @@ public class DefsTest extends CleanupHelper
|
|||
List<KSMetaData> defs = new ArrayList<KSMetaData>(DefsTable.loadFromStorage(first));
|
||||
|
||||
assert defs.size() > 0;
|
||||
assert defs.size() == DatabaseDescriptor.getNonSystemTables().size();
|
||||
assert defs.size() == Schema.instance.getNonSystemTables().size();
|
||||
for (KSMetaData loaded : defs)
|
||||
{
|
||||
KSMetaData defined = DatabaseDescriptor.getTableDefinition(loaded.name);
|
||||
KSMetaData defined = Schema.instance.getTableDefinition(loaded.name);
|
||||
assert defined.equals(loaded);
|
||||
}
|
||||
}
|
||||
|
|
@ -200,10 +196,10 @@ public class DefsTest extends CleanupHelper
|
|||
public void testMigrations() throws IOException, ConfigurationException
|
||||
{
|
||||
// do a save. make sure it doesn't mess with the defs version.
|
||||
UUID prior = DatabaseDescriptor.getDefsVersion();
|
||||
UUID prior = Schema.instance.getVersion();
|
||||
UUID ver0 = UUIDGen.makeType1UUIDFromHost(FBUtilities.getBroadcastAddress());
|
||||
DefsTable.dumpToStorage(ver0);
|
||||
assert DatabaseDescriptor.getDefsVersion().equals(prior);
|
||||
assert Schema.instance.getVersion().equals(prior);
|
||||
|
||||
// add a cf.
|
||||
CFMetaData newCf1 = addTestCF("Keyspace1", "MigrationCf_1", "Migration CF");
|
||||
|
|
@ -211,19 +207,19 @@ public class DefsTest extends CleanupHelper
|
|||
Migration m1 = new AddColumnFamily(newCf1);
|
||||
m1.apply();
|
||||
UUID ver1 = m1.getVersion();
|
||||
assert DatabaseDescriptor.getDefsVersion().equals(ver1);
|
||||
assert Schema.instance.getVersion().equals(ver1);
|
||||
|
||||
// rename it.
|
||||
Migration m2 = new RenameColumnFamily("Keyspace1", "MigrationCf_1", "MigrationCf_2");
|
||||
m2.apply();
|
||||
UUID ver2 = m2.getVersion();
|
||||
assert DatabaseDescriptor.getDefsVersion().equals(ver2);
|
||||
assert Schema.instance.getVersion().equals(ver2);
|
||||
|
||||
// drop it.
|
||||
Migration m3 = new DropColumnFamily("Keyspace1", "MigrationCf_2");
|
||||
m3.apply();
|
||||
UUID ver3 = m3.getVersion();
|
||||
assert DatabaseDescriptor.getDefsVersion().equals(ver3);
|
||||
assert Schema.instance.getVersion().equals(ver3);
|
||||
|
||||
// now lets load the older migrations to see if that code works.
|
||||
Collection<IColumn> serializedMigrations = Migration.getLocalMigrations(ver1, ver3);
|
||||
|
|
@ -255,15 +251,15 @@ public class DefsTest extends CleanupHelper
|
|||
{
|
||||
final String ks = "Keyspace1";
|
||||
final String cf = "BrandNewCfWithNull";
|
||||
KSMetaData original = DatabaseDescriptor.getTableDefinition(ks);
|
||||
KSMetaData original = Schema.instance.getTableDefinition(ks);
|
||||
|
||||
CFMetaData newCf = addTestCF(original.name, cf, null);
|
||||
|
||||
assert !DatabaseDescriptor.getTableDefinition(ks).cfMetaData().containsKey(newCf.cfName);
|
||||
assert !Schema.instance.getTableDefinition(ks).cfMetaData().containsKey(newCf.cfName);
|
||||
new AddColumnFamily(newCf).apply();
|
||||
|
||||
assert DatabaseDescriptor.getTableDefinition(ks).cfMetaData().containsKey(newCf.cfName);
|
||||
assert DatabaseDescriptor.getTableDefinition(ks).cfMetaData().get(newCf.cfName).equals(newCf);
|
||||
assert Schema.instance.getTableDefinition(ks).cfMetaData().containsKey(newCf.cfName);
|
||||
assert Schema.instance.getTableDefinition(ks).cfMetaData().get(newCf.cfName).equals(newCf);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -271,15 +267,15 @@ public class DefsTest extends CleanupHelper
|
|||
{
|
||||
final String ks = "Keyspace1";
|
||||
final String cf = "BrandNewCf";
|
||||
KSMetaData original = DatabaseDescriptor.getTableDefinition(ks);
|
||||
KSMetaData original = Schema.instance.getTableDefinition(ks);
|
||||
|
||||
CFMetaData newCf = addTestCF(original.name, cf, "A New Column Family");
|
||||
|
||||
assert !DatabaseDescriptor.getTableDefinition(ks).cfMetaData().containsKey(newCf.cfName);
|
||||
assert !Schema.instance.getTableDefinition(ks).cfMetaData().containsKey(newCf.cfName);
|
||||
new AddColumnFamily(newCf).apply();
|
||||
|
||||
assert DatabaseDescriptor.getTableDefinition(ks).cfMetaData().containsKey(newCf.cfName);
|
||||
assert DatabaseDescriptor.getTableDefinition(ks).cfMetaData().get(newCf.cfName).equals(newCf);
|
||||
assert Schema.instance.getTableDefinition(ks).cfMetaData().containsKey(newCf.cfName);
|
||||
assert Schema.instance.getTableDefinition(ks).cfMetaData().get(newCf.cfName).equals(newCf);
|
||||
|
||||
// now read and write to it.
|
||||
DecoratedKey dk = Util.dk("key0");
|
||||
|
|
@ -301,7 +297,7 @@ public class DefsTest extends CleanupHelper
|
|||
{
|
||||
DecoratedKey dk = Util.dk("dropCf");
|
||||
// sanity
|
||||
final KSMetaData ks = DatabaseDescriptor.getTableDefinition("Keyspace1");
|
||||
final KSMetaData ks = Schema.instance.getTableDefinition("Keyspace1");
|
||||
assert ks != null;
|
||||
final CFMetaData cfm = ks.cfMetaData().get("Standard1");
|
||||
assert cfm != null;
|
||||
|
|
@ -318,8 +314,8 @@ public class DefsTest extends CleanupHelper
|
|||
assert DefsTable.getFiles(cfm.ksName, cfm.cfName).size() > 0;
|
||||
|
||||
new DropColumnFamily(ks.name, cfm.cfName).apply();
|
||||
|
||||
assert !DatabaseDescriptor.getTableDefinition(ks.name).cfMetaData().containsKey(cfm.cfName);
|
||||
|
||||
assert !Schema.instance.getTableDefinition(ks.name).cfMetaData().containsKey(cfm.cfName);
|
||||
|
||||
// any write should fail.
|
||||
rm = new RowMutation(ks.name, dk.key);
|
||||
|
|
@ -347,7 +343,7 @@ public class DefsTest extends CleanupHelper
|
|||
public void renameCf() throws ConfigurationException, IOException, ExecutionException, InterruptedException
|
||||
{
|
||||
DecoratedKey dk = Util.dk("key0");
|
||||
final KSMetaData ks = DatabaseDescriptor.getTableDefinition("Keyspace2");
|
||||
final KSMetaData ks = Schema.instance.getTableDefinition("Keyspace2");
|
||||
assert ks != null;
|
||||
final CFMetaData oldCfm = ks.cfMetaData().get("Standard1");
|
||||
assert oldCfm != null;
|
||||
|
|
@ -365,9 +361,9 @@ public class DefsTest extends CleanupHelper
|
|||
|
||||
final String cfName = "St4ndard1Replacement";
|
||||
new RenameColumnFamily(oldCfm.ksName, oldCfm.cfName, cfName).apply();
|
||||
|
||||
assert !DatabaseDescriptor.getTableDefinition(ks.name).cfMetaData().containsKey(oldCfm.cfName);
|
||||
assert DatabaseDescriptor.getTableDefinition(ks.name).cfMetaData().containsKey(cfName);
|
||||
|
||||
assert !Schema.instance.getTableDefinition(ks.name).cfMetaData().containsKey(oldCfm.cfName);
|
||||
assert Schema.instance.getTableDefinition(ks.name).cfMetaData().containsKey(cfName);
|
||||
|
||||
// verify that new files are there.
|
||||
assert DefsTable.getFiles(oldCfm.ksName, cfName).size() == fileCount;
|
||||
|
|
@ -398,9 +394,9 @@ public class DefsTest extends CleanupHelper
|
|||
KSMetaData newKs = new KSMetaData(newCf.ksName, SimpleStrategy.class, KSMetaData.optsWithRF(5), newCf);
|
||||
|
||||
new AddKeyspace(newKs).apply();
|
||||
|
||||
assert DatabaseDescriptor.getTableDefinition(newCf.ksName) != null;
|
||||
assert DatabaseDescriptor.getTableDefinition(newCf.ksName) == newKs;
|
||||
|
||||
assert Schema.instance.getTableDefinition(newCf.ksName) != null;
|
||||
assert Schema.instance.getTableDefinition(newCf.ksName) == newKs;
|
||||
|
||||
// test reads and writes.
|
||||
RowMutation rm = new RowMutation(newCf.ksName, dk.key);
|
||||
|
|
@ -421,7 +417,7 @@ public class DefsTest extends CleanupHelper
|
|||
{
|
||||
DecoratedKey dk = Util.dk("dropKs");
|
||||
// sanity
|
||||
final KSMetaData ks = DatabaseDescriptor.getTableDefinition("Keyspace1");
|
||||
final KSMetaData ks = Schema.instance.getTableDefinition("Keyspace1");
|
||||
assert ks != null;
|
||||
final CFMetaData cfm = ks.cfMetaData().get("Standard2");
|
||||
assert cfm != null;
|
||||
|
|
@ -437,8 +433,8 @@ public class DefsTest extends CleanupHelper
|
|||
assert DefsTable.getFiles(cfm.ksName, cfm.cfName).size() > 0;
|
||||
|
||||
new DropKeyspace(ks.name).apply();
|
||||
|
||||
assert DatabaseDescriptor.getTableDefinition(ks.name) == null;
|
||||
|
||||
assert Schema.instance.getTableDefinition(ks.name) == null;
|
||||
|
||||
// write should fail.
|
||||
rm = new RowMutation(ks.name, dk.key);
|
||||
|
|
@ -472,7 +468,7 @@ public class DefsTest extends CleanupHelper
|
|||
{
|
||||
DecoratedKey dk = Util.dk("dropKs");
|
||||
// sanity
|
||||
final KSMetaData ks = DatabaseDescriptor.getTableDefinition("Keyspace3");
|
||||
final KSMetaData ks = Schema.instance.getTableDefinition("Keyspace3");
|
||||
assert ks != null;
|
||||
final CFMetaData cfm = ks.cfMetaData().get("Standard1");
|
||||
assert cfm != null;
|
||||
|
|
@ -485,14 +481,14 @@ public class DefsTest extends CleanupHelper
|
|||
|
||||
new DropKeyspace(ks.name).apply();
|
||||
|
||||
assert DatabaseDescriptor.getTableDefinition(ks.name) == null;
|
||||
assert Schema.instance.getTableDefinition(ks.name) == null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void renameKs() throws ConfigurationException, IOException, ExecutionException, InterruptedException
|
||||
{
|
||||
DecoratedKey dk = Util.dk("renameKs");
|
||||
final KSMetaData oldKs = DatabaseDescriptor.getTableDefinition("Keyspace2");
|
||||
final KSMetaData oldKs = Schema.instance.getTableDefinition("Keyspace2");
|
||||
assert oldKs != null;
|
||||
final String cfName = "Standard3";
|
||||
assert oldKs.cfMetaData().containsKey(cfName);
|
||||
|
|
@ -510,9 +506,9 @@ public class DefsTest extends CleanupHelper
|
|||
|
||||
final String newKsName = "RenamedKeyspace2";
|
||||
new RenameKeyspace(oldKs.name, newKsName).apply();
|
||||
KSMetaData newKs = DatabaseDescriptor.getTableDefinition(newKsName);
|
||||
|
||||
assert DatabaseDescriptor.getTableDefinition(oldKs.name) == null;
|
||||
KSMetaData newKs = Schema.instance.getTableDefinition(newKsName);
|
||||
|
||||
assert Schema.instance.getTableDefinition(oldKs.name) == null;
|
||||
assert newKs != null;
|
||||
assert newKs.name.equals(newKsName);
|
||||
assert newKs.cfMetaData().containsKey(cfName);
|
||||
|
|
@ -572,23 +568,23 @@ public class DefsTest extends CleanupHelper
|
|||
@Test
|
||||
public void createEmptyKsAddNewCf() throws ConfigurationException, IOException, ExecutionException, InterruptedException
|
||||
{
|
||||
assert DatabaseDescriptor.getTableDefinition("EmptyKeyspace") == null;
|
||||
assert Schema.instance.getTableDefinition("EmptyKeyspace") == null;
|
||||
|
||||
KSMetaData newKs = new KSMetaData("EmptyKeyspace", SimpleStrategy.class, KSMetaData.optsWithRF(5));
|
||||
|
||||
new AddKeyspace(newKs).apply();
|
||||
assert DatabaseDescriptor.getTableDefinition("EmptyKeyspace") != null;
|
||||
assert Schema.instance.getTableDefinition("EmptyKeyspace") != null;
|
||||
|
||||
CFMetaData newCf = addTestCF("EmptyKeyspace", "AddedLater", "A new CF to add to an empty KS");
|
||||
|
||||
//should not exist until apply
|
||||
assert !DatabaseDescriptor.getTableDefinition(newKs.name).cfMetaData().containsKey(newCf.cfName);
|
||||
assert !Schema.instance.getTableDefinition(newKs.name).cfMetaData().containsKey(newCf.cfName);
|
||||
|
||||
//add the new CF to the empty space
|
||||
new AddColumnFamily(newCf).apply();
|
||||
|
||||
assert DatabaseDescriptor.getTableDefinition(newKs.name).cfMetaData().containsKey(newCf.cfName);
|
||||
assert DatabaseDescriptor.getTableDefinition(newKs.name).cfMetaData().get(newCf.cfName).equals(newCf);
|
||||
assert Schema.instance.getTableDefinition(newKs.name).cfMetaData().containsKey(newCf.cfName);
|
||||
assert Schema.instance.getTableDefinition(newKs.name).cfMetaData().get(newCf.cfName).equals(newCf);
|
||||
|
||||
// now read and write to it.
|
||||
DecoratedKey dk = Util.dk("key0");
|
||||
|
|
@ -613,9 +609,9 @@ public class DefsTest extends CleanupHelper
|
|||
KSMetaData oldKs = new KSMetaData(cf.ksName, SimpleStrategy.class, KSMetaData.optsWithRF(5), cf);
|
||||
|
||||
new AddKeyspace(oldKs).apply();
|
||||
|
||||
assert DatabaseDescriptor.getTableDefinition(cf.ksName) != null;
|
||||
assert DatabaseDescriptor.getTableDefinition(cf.ksName) == oldKs;
|
||||
|
||||
assert Schema.instance.getTableDefinition(cf.ksName) != null;
|
||||
assert Schema.instance.getTableDefinition(cf.ksName) == oldKs;
|
||||
|
||||
// anything with cf defs should fail.
|
||||
CFMetaData cf2 = addTestCF(cf.ksName, "AddedStandard2", "A new cf for a new ks");
|
||||
|
|
@ -644,8 +640,8 @@ public class DefsTest extends CleanupHelper
|
|||
|
||||
KSMetaData newKs = new KSMetaData(cf.ksName, OldNetworkTopologyStrategy.class, KSMetaData.optsWithRF(1));
|
||||
new UpdateKeyspace(newKs).apply();
|
||||
|
||||
KSMetaData newFetchedKs = DatabaseDescriptor.getKSMetaData(newKs.name);
|
||||
|
||||
KSMetaData newFetchedKs = Schema.instance.getKSMetaData(newKs.name);
|
||||
assert newFetchedKs.strategyClass.equals(newKs.strategyClass);
|
||||
assert !newFetchedKs.strategyClass.equals(oldKs.strategyClass);
|
||||
}
|
||||
|
|
@ -657,10 +653,10 @@ public class DefsTest extends CleanupHelper
|
|||
CFMetaData cf = addTestCF("UpdatedCfKs", "Standard1added", "A new cf that will be updated");
|
||||
KSMetaData ksm = new KSMetaData(cf.ksName, SimpleStrategy.class, KSMetaData.optsWithRF(1), cf);
|
||||
new AddKeyspace(ksm).apply();
|
||||
|
||||
assert DatabaseDescriptor.getTableDefinition(cf.ksName) != null;
|
||||
assert DatabaseDescriptor.getTableDefinition(cf.ksName) == ksm;
|
||||
assert DatabaseDescriptor.getCFMetaData(cf.ksName, cf.cfName) != null;
|
||||
|
||||
assert Schema.instance.getTableDefinition(cf.ksName) != null;
|
||||
assert Schema.instance.getTableDefinition(cf.ksName) == ksm;
|
||||
assert Schema.instance.getCFMetaData(cf.ksName, cf.cfName) != null;
|
||||
|
||||
// updating certain fields should fail.
|
||||
org.apache.cassandra.db.migration.avro.CfDef cf_def = CFMetaData.convertToAvro(cf);
|
||||
|
|
@ -698,12 +694,12 @@ public class DefsTest extends CleanupHelper
|
|||
// can't test changing the reconciler because there is only one impl.
|
||||
|
||||
// check the cumulative affect.
|
||||
assert DatabaseDescriptor.getCFMetaData(cf.ksName, cf.cfName).getComment().equals(cf_def.comment);
|
||||
assert DatabaseDescriptor.getCFMetaData(cf.ksName, cf.cfName).getRowCacheSize() == cf_def.row_cache_size;
|
||||
assert DatabaseDescriptor.getCFMetaData(cf.ksName, cf.cfName).getKeyCacheSize() == cf_def.key_cache_size;
|
||||
assert DatabaseDescriptor.getCFMetaData(cf.ksName, cf.cfName).getReadRepairChance() == cf_def.read_repair_chance;
|
||||
assert DatabaseDescriptor.getCFMetaData(cf.ksName, cf.cfName).getGcGraceSeconds() == cf_def.gc_grace_seconds;
|
||||
assert DatabaseDescriptor.getCFMetaData(cf.ksName, cf.cfName).getDefaultValidator() == UTF8Type.instance;
|
||||
assert Schema.instance.getCFMetaData(cf.ksName, cf.cfName).getComment().equals(cf_def.comment);
|
||||
assert Schema.instance.getCFMetaData(cf.ksName, cf.cfName).getRowCacheSize() == cf_def.row_cache_size;
|
||||
assert Schema.instance.getCFMetaData(cf.ksName, cf.cfName).getKeyCacheSize() == cf_def.key_cache_size;
|
||||
assert Schema.instance.getCFMetaData(cf.ksName, cf.cfName).getReadRepairChance() == cf_def.read_repair_chance;
|
||||
assert Schema.instance.getCFMetaData(cf.ksName, cf.cfName).getGcGraceSeconds() == cf_def.gc_grace_seconds;
|
||||
assert Schema.instance.getCFMetaData(cf.ksName, cf.cfName).getDefaultValidator() == UTF8Type.instance;
|
||||
|
||||
// todo: we probably don't need to reset old values in the catches anymore.
|
||||
// make sure some invalid operations fail.
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ package org.apache.cassandra.db;
|
|||
|
||||
import org.apache.cassandra.AbstractSerializationsTester;
|
||||
import org.apache.cassandra.Util;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.config.Schema;
|
||||
import org.apache.cassandra.db.filter.QueryPath;
|
||||
import org.apache.cassandra.dht.AbstractBounds;
|
||||
import org.apache.cassandra.dht.IPartitioner;
|
||||
|
|
@ -312,7 +312,7 @@ public class SerializationsTest extends AbstractSerializationsTester
|
|||
private static final ColumnFamily StandardCf = ColumnFamily.create(Statics.KS, "Standard1");
|
||||
private static final ColumnFamily SuperCf = ColumnFamily.create(Statics.KS, "Super1");
|
||||
|
||||
private static final SuperColumn SuperCol = new SuperColumn(Statics.SC, DatabaseDescriptor.getComparator(Statics.KS, "Super1"))
|
||||
private static final SuperColumn SuperCol = new SuperColumn(Statics.SC, Schema.instance.getComparator(Statics.KS, "Super1"))
|
||||
{{
|
||||
addColumn(new Column(bb("aaaa")));
|
||||
addColumn(new Column(bb("bbbb"), bb("bbbbb-value")));
|
||||
|
|
@ -322,7 +322,7 @@ public class SerializationsTest extends AbstractSerializationsTester
|
|||
addColumn(new ExpiringColumn(bb("ffff"), bb("ffff-value"), 2000, 1000));
|
||||
addColumn(new ExpiringColumn(bb("gggg"), bb("gggg-value"), 2001, 1000, 2002));
|
||||
}};
|
||||
|
||||
|
||||
private static final Row StandardRow = new Row(Util.dk("key0"), Statics.StandardCf);
|
||||
private static final Row SuperRow = new Row(Util.dk("key1"), Statics.SuperCf);
|
||||
private static final Row NullRow = new Row(Util.dk("key2"), null);
|
||||
|
|
|
|||
|
|
@ -22,10 +22,9 @@ package org.apache.cassandra.db.migration;
|
|||
|
||||
|
||||
import org.apache.cassandra.AbstractSerializationsTester;
|
||||
import org.apache.cassandra.CleanupHelper;
|
||||
import org.apache.cassandra.config.ConfigurationException;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.config.KSMetaData;
|
||||
import org.apache.cassandra.config.Schema;
|
||||
import org.apache.cassandra.io.SerDeUtils;
|
||||
import org.apache.cassandra.utils.FBUtilities;
|
||||
import org.apache.cassandra.utils.UUIDGen;
|
||||
|
|
@ -35,8 +34,6 @@ import org.junit.Test;
|
|||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.UUID;
|
||||
|
||||
|
|
@ -49,9 +46,9 @@ public class SerializationsTest extends AbstractSerializationsTester
|
|||
for (int i = 0; i < ksCount; i++)
|
||||
{
|
||||
String tableName = "Keyspace" + (i + 1);
|
||||
KSMetaData ksm = DatabaseDescriptor.getKSMetaData(tableName);
|
||||
KSMetaData ksm = Schema.instance.getKSMetaData(tableName);
|
||||
UUID uuid = UUIDGen.makeType1UUIDFromHost(FBUtilities.getBroadcastAddress());
|
||||
DatabaseDescriptor.clearTableDefinition(ksm, uuid);
|
||||
Schema.instance.clearTableDefinition(ksm, uuid);
|
||||
Migration m = new AddKeyspace(ksm);
|
||||
ByteBuffer bytes = m.serialize();
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
|
||||
import org.apache.cassandra.CleanupHelper;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.config.Schema;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.Test;
|
||||
|
|
@ -145,7 +145,7 @@ public class BootStrapperTest extends CleanupHelper
|
|||
public void testSourceTargetComputation() throws UnknownHostException
|
||||
{
|
||||
final int[] clusterSizes = new int[] { 1, 3, 5, 10, 100};
|
||||
for (String table : DatabaseDescriptor.getNonSystemTables())
|
||||
for (String table : Schema.instance.getNonSystemTables())
|
||||
{
|
||||
int replicationFactor = Table.open(table).getReplicationStrategy().getReplicationFactor();
|
||||
for (int clusterSize : clusterSizes)
|
||||
|
|
|
|||
|
|
@ -21,17 +21,16 @@ package org.apache.cassandra.locator;
|
|||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.cassandra.config.Schema;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.cassandra.CleanupHelper;
|
||||
import org.apache.cassandra.config.ConfigurationException;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.config.KSMetaData;
|
||||
import org.apache.cassandra.db.Table;
|
||||
import org.apache.cassandra.dht.*;
|
||||
|
|
@ -81,7 +80,7 @@ public class SimpleStrategyTest extends CleanupHelper
|
|||
{
|
||||
TokenMetadata tmd;
|
||||
AbstractReplicationStrategy strategy;
|
||||
for (String table : DatabaseDescriptor.getNonSystemTables())
|
||||
for (String table : Schema.instance.getNonSystemTables())
|
||||
{
|
||||
tmd = new TokenMetadata();
|
||||
strategy = getStrategy(table, tmd);
|
||||
|
|
@ -136,7 +135,7 @@ public class SimpleStrategyTest extends CleanupHelper
|
|||
tmd.addBootstrapToken(bsToken, bootstrapEndpoint);
|
||||
|
||||
AbstractReplicationStrategy strategy = null;
|
||||
for (String table : DatabaseDescriptor.getNonSystemTables())
|
||||
for (String table : Schema.instance.getNonSystemTables())
|
||||
{
|
||||
strategy = getStrategy(table, tmd);
|
||||
|
||||
|
|
@ -178,7 +177,7 @@ public class SimpleStrategyTest extends CleanupHelper
|
|||
|
||||
private AbstractReplicationStrategy getStrategy(String table, TokenMetadata tmd) throws ConfigurationException
|
||||
{
|
||||
KSMetaData ksmd = DatabaseDescriptor.getKSMetaData(table);
|
||||
KSMetaData ksmd = Schema.instance.getKSMetaData(table);
|
||||
return AbstractReplicationStrategy.createReplicationStrategy(
|
||||
table,
|
||||
ksmd.strategyClass,
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import java.util.concurrent.Callable;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
import org.apache.cassandra.config.Schema;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
|
@ -32,7 +33,6 @@ import org.apache.cassandra.CleanupHelper;
|
|||
import org.apache.cassandra.Util;
|
||||
import org.apache.cassandra.concurrent.Stage;
|
||||
import org.apache.cassandra.concurrent.StageManager;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.db.*;
|
||||
import org.apache.cassandra.db.compaction.PrecompactedRow;
|
||||
import org.apache.cassandra.dht.IPartitioner;
|
||||
|
|
@ -152,7 +152,7 @@ public abstract class AntiEntropyServiceTestAbstract extends CleanupHelper
|
|||
|
||||
// add a row
|
||||
validator.add(new PrecompactedRow(new DecoratedKey(mid, ByteBufferUtil.bytes("inconceivable!")),
|
||||
ColumnFamily.create(DatabaseDescriptor.getCFMetaData(tablename, cfname))));
|
||||
ColumnFamily.create(Schema.instance.getCFMetaData(tablename, cfname))));
|
||||
validator.completeTree();
|
||||
|
||||
// confirm that the tree was validated
|
||||
|
|
|
|||
|
|
@ -26,12 +26,12 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import org.apache.cassandra.config.Schema;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.cassandra.CleanupHelper;
|
||||
import org.apache.cassandra.Util;
|
||||
import org.apache.cassandra.config.ConfigurationException;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.config.KSMetaData;
|
||||
import org.apache.cassandra.db.Row;
|
||||
import org.apache.cassandra.dht.IPartitioner;
|
||||
|
|
@ -72,7 +72,7 @@ public class ConsistencyLevelTest extends CleanupHelper
|
|||
|
||||
AbstractReplicationStrategy strategy;
|
||||
|
||||
for (final String table : DatabaseDescriptor.getNonSystemTables())
|
||||
for (final String table : Schema.instance.getNonSystemTables())
|
||||
{
|
||||
strategy = getStrategy(table, tmd);
|
||||
StorageService.calculatePendingRanges(strategy, table);
|
||||
|
|
@ -178,7 +178,7 @@ public class ConsistencyLevelTest extends CleanupHelper
|
|||
|
||||
private AbstractReplicationStrategy getStrategy(String table, TokenMetadata tmd) throws ConfigurationException
|
||||
{
|
||||
KSMetaData ksmd = DatabaseDescriptor.getKSMetaData(table);
|
||||
KSMetaData ksmd = Schema.instance.getKSMetaData(table);
|
||||
return AbstractReplicationStrategy.createReplicationStrategy(
|
||||
table,
|
||||
ksmd.strategyClass,
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import java.net.UnknownHostException;
|
|||
import java.util.*;
|
||||
|
||||
import org.apache.cassandra.config.ConfigurationException;
|
||||
import org.apache.cassandra.config.Schema;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
|
@ -31,7 +32,6 @@ import com.google.common.collect.HashMultimap;
|
|||
import com.google.common.collect.Multimap;
|
||||
import org.apache.cassandra.CleanupHelper;
|
||||
import org.apache.cassandra.Util;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.config.KSMetaData;
|
||||
import org.apache.cassandra.dht.*;
|
||||
import org.apache.cassandra.gms.ApplicationState;
|
||||
|
|
@ -67,7 +67,7 @@ public class LeaveAndBootstrapTest extends CleanupHelper
|
|||
Util.createInitialRing(ss, partitioner, endpointTokens, keyTokens, hosts, RING_SIZE);
|
||||
|
||||
Map<Token, List<InetAddress>> expectedEndpoints = new HashMap<Token, List<InetAddress>>();
|
||||
for (String table : DatabaseDescriptor.getNonSystemTables())
|
||||
for (String table : Schema.instance.getNonSystemTables())
|
||||
{
|
||||
for (Token token : keyTokens)
|
||||
{
|
||||
|
|
@ -88,7 +88,7 @@ public class LeaveAndBootstrapTest extends CleanupHelper
|
|||
assertTrue(tmd.isLeaving(hosts.get(LEAVING_NODE)));
|
||||
|
||||
AbstractReplicationStrategy strategy;
|
||||
for (String table : DatabaseDescriptor.getNonSystemTables())
|
||||
for (String table : Schema.instance.getNonSystemTables())
|
||||
{
|
||||
strategy = getStrategy(table, tmd);
|
||||
for (Token token : keyTokens)
|
||||
|
|
@ -614,7 +614,7 @@ public class LeaveAndBootstrapTest extends CleanupHelper
|
|||
|
||||
private AbstractReplicationStrategy getStrategy(String table, TokenMetadata tmd) throws ConfigurationException
|
||||
{
|
||||
KSMetaData ksmd = DatabaseDescriptor.getKSMetaData(table);
|
||||
KSMetaData ksmd = Schema.instance.getKSMetaData(table);
|
||||
return AbstractReplicationStrategy.createReplicationStrategy(
|
||||
table,
|
||||
ksmd.strategyClass,
|
||||
|
|
|
|||
|
|
@ -19,12 +19,12 @@
|
|||
|
||||
package org.apache.cassandra.service;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.*;
|
||||
|
||||
import org.apache.cassandra.config.ConfigurationException;
|
||||
import org.apache.cassandra.config.Schema;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
|
@ -32,7 +32,6 @@ import com.google.common.collect.HashMultimap;
|
|||
import com.google.common.collect.Multimap;
|
||||
import org.apache.cassandra.CleanupHelper;
|
||||
import org.apache.cassandra.Util;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.config.KSMetaData;
|
||||
import org.apache.cassandra.dht.*;
|
||||
import org.apache.cassandra.gms.ApplicationState;
|
||||
|
|
@ -68,7 +67,7 @@ public class MoveTest extends CleanupHelper
|
|||
Util.createInitialRing(ss, partitioner, endpointTokens, keyTokens, hosts, RING_SIZE);
|
||||
|
||||
Map<Token, List<InetAddress>> expectedEndpoints = new HashMap<Token, List<InetAddress>>();
|
||||
for (String table : DatabaseDescriptor.getNonSystemTables())
|
||||
for (String table : Schema.instance.getNonSystemTables())
|
||||
{
|
||||
for (Token token : keyTokens)
|
||||
{
|
||||
|
|
@ -91,7 +90,7 @@ public class MoveTest extends CleanupHelper
|
|||
assertTrue(tmd.isMoving(hosts.get(MOVING_NODE)));
|
||||
|
||||
AbstractReplicationStrategy strategy;
|
||||
for (String table : DatabaseDescriptor.getNonSystemTables())
|
||||
for (String table : Schema.instance.getNonSystemTables())
|
||||
{
|
||||
strategy = getStrategy(table, tmd);
|
||||
for (Token token : keyTokens)
|
||||
|
|
@ -505,7 +504,7 @@ public class MoveTest extends CleanupHelper
|
|||
|
||||
private AbstractReplicationStrategy getStrategy(String table, TokenMetadata tmd) throws ConfigurationException
|
||||
{
|
||||
KSMetaData ksmd = DatabaseDescriptor.getKSMetaData(table);
|
||||
KSMetaData ksmd = Schema.instance.getKSMetaData(table);
|
||||
return AbstractReplicationStrategy.createReplicationStrategy(
|
||||
table,
|
||||
ksmd.strategyClass,
|
||||
|
|
|
|||
|
|
@ -23,8 +23,7 @@ package org.apache.cassandra.thrift;
|
|||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.config.*;
|
||||
import org.apache.cassandra.db.marshal.AsciiType;
|
||||
import org.apache.cassandra.db.marshal.UTF8Type;
|
||||
|
||||
|
|
@ -32,14 +31,8 @@ import org.junit.Test;
|
|||
|
||||
import org.apache.cassandra.CleanupHelper;
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.config.ConfigurationException;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.db.marshal.AsciiType;
|
||||
import org.apache.cassandra.db.marshal.UTF8Type;
|
||||
import org.apache.cassandra.utils.FBUtilities;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
public class ThriftValidationTest extends CleanupHelper
|
||||
{
|
||||
@Test(expected=InvalidRequestException.class)
|
||||
|
|
@ -57,7 +50,7 @@ public class ThriftValidationTest extends CleanupHelper
|
|||
@Test
|
||||
public void testColumnValueSizeForIndexedColumn() throws ConfigurationException, InvalidRequestException
|
||||
{
|
||||
CfDef cfDef = CFMetaData.convertToThrift(DatabaseDescriptor.getCFMetaData("Keyspace1", "Standard1"));
|
||||
CfDef cfDef = CFMetaData.convertToThrift(Schema.instance.getCFMetaData("Keyspace1", "Standard1"));
|
||||
ByteBuffer columnName = AsciiType.instance.fromString("indexed");
|
||||
|
||||
// add an indexed column definition
|
||||
|
|
@ -106,7 +99,7 @@ public class ThriftValidationTest extends CleanupHelper
|
|||
@Test
|
||||
public void testColumnNameEqualToKeyAlias()
|
||||
{
|
||||
CFMetaData metaData = DatabaseDescriptor.getCFMetaData("Keyspace1", "Standard1");
|
||||
CFMetaData metaData = Schema.instance.getCFMetaData("Keyspace1", "Standard1");
|
||||
CfDef newMetadata = CFMetaData.convertToThrift(metaData);
|
||||
|
||||
boolean gotException = false;
|
||||
|
|
|
|||
Loading…
Reference in New Issue