Search in sources :

Example 81 with ConfigurationException

use of org.apache.cassandra.exceptions.ConfigurationException in project cassandra by apache.

the class MigrationManager method announceTableUpdate.

public static void announceTableUpdate(TableMetadata updated, boolean announceLocally) {
    updated.validate();
    TableMetadata current = Schema.instance.getTableMetadata(updated.keyspace, updated.name);
    if (current == null)
        throw new ConfigurationException(String.format("Cannot update non existing table '%s' in keyspace '%s'.", updated.name, updated.keyspace));
    KeyspaceMetadata ksm = Schema.instance.getKeyspaceMetadata(current.keyspace);
    updated.validateCompatibility(current);
    long timestamp = FBUtilities.timestampMicros();
    logger.info("Update table '{}/{}' From {} To {}", current.keyspace, current.name, current, updated);
    Mutation.SimpleBuilder builder = SchemaKeyspace.makeUpdateTableMutation(ksm, current, updated, timestamp);
    announce(builder, announceLocally);
}
Also used : ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException)

Example 82 with ConfigurationException

use of org.apache.cassandra.exceptions.ConfigurationException in project cassandra by apache.

the class CompressionParams method removeSstableCompressionClass.

/**
 * Removes the option specifying the name of the compression class
 *
 * @param options the options
 * @return the name of the compression class
 */
private static String removeSstableCompressionClass(Map<String, String> options) {
    if (options.containsKey(CLASS)) {
        if (options.containsKey(SSTABLE_COMPRESSION))
            throw new ConfigurationException(format("The '%s' option must not be used if the compression algorithm is already specified by the '%s' option", SSTABLE_COMPRESSION, CLASS));
        String clazz = options.remove(CLASS);
        if (clazz.isEmpty())
            throw new ConfigurationException(format("The '%s' option must not be empty. To disable compression use 'enabled' : false", CLASS));
        return clazz;
    }
    if (options.containsKey(SSTABLE_COMPRESSION) && !hasLoggedSsTableCompressionWarning) {
        hasLoggedSsTableCompressionWarning = true;
        logger.warn("The {} option has been deprecated. You should use {} instead", SSTABLE_COMPRESSION, CLASS);
    }
    return options.remove(SSTABLE_COMPRESSION);
}
Also used : ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException)

Example 83 with ConfigurationException

use of org.apache.cassandra.exceptions.ConfigurationException in project cassandra by apache.

the class AlterKeyspaceStatement method validateTransientReplication.

private void validateTransientReplication(AbstractReplicationStrategy oldStrategy, AbstractReplicationStrategy newStrategy) {
    // that a good default is to not allow unsafe changes
    if (allow_unsafe_transient_changes)
        return;
    ReplicationFactor oldRF = oldStrategy.getReplicationFactor();
    ReplicationFactor newRF = newStrategy.getReplicationFactor();
    int oldTrans = oldRF.transientReplicas();
    int oldFull = oldRF.fullReplicas;
    int newTrans = newRF.transientReplicas();
    int newFull = newRF.fullReplicas;
    if (newTrans > 0) {
        if (DatabaseDescriptor.getNumTokens() > 1)
            throw new ConfigurationException(String.format("Transient replication is not supported with vnodes yet"));
        Keyspace ks = Keyspace.open(keyspaceName);
        for (ColumnFamilyStore cfs : ks.getColumnFamilyStores()) {
            if (cfs.viewManager.hasViews()) {
                throw new ConfigurationException("Cannot use transient replication on keyspaces using materialized views");
            }
            if (cfs.indexManager.hasIndexes()) {
                throw new ConfigurationException("Cannot use transient replication on keyspaces using secondary indexes");
            }
        }
    }
    // to read from a transient replica as if it were a full replica.
    if (oldFull > newFull && oldTrans > 0)
        throw new ConfigurationException("Can't add full replicas if there are any transient replicas. You must first remove all transient replicas, then change the # of full replicas, then add back the transient replicas");
    // Don't increase transient replication factor by more than one at a time if changing number of replicas
    // Just like with changing full replicas it's not safe to do this as you could read from too many replicas
    // that don't have the necessary data. W/O transient replication this alteration was allowed and it's not clear
    // if it should be.
    // This is structured so you can convert as many full replicas to transient replicas as you want.
    boolean numReplicasChanged = oldTrans + oldFull != newTrans + newFull;
    if (numReplicasChanged && (newTrans > oldTrans && newTrans != oldTrans + 1))
        throw new ConfigurationException("Can only safely increase number of transients one at a time with incremental repair run in between each time");
}
Also used : ReplicationFactor(org.apache.cassandra.locator.ReplicationFactor) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) Keyspace(org.apache.cassandra.db.Keyspace) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore)

Example 84 with ConfigurationException

use of org.apache.cassandra.exceptions.ConfigurationException in project titan by thinkaurelius.

the class CassandraEmbeddedStoreManager method ensureKeyspaceExists.

private void ensureKeyspaceExists(String keyspaceName) throws StorageException {
    if (null != Schema.instance.getTableInstance(keyspaceName))
        return;
    // Keyspace not found; create it
    String strategyName = "org.apache.cassandra.locator.SimpleStrategy";
    Map<String, String> options = new HashMap<String, String>() {

        {
            put("replication_factor", String.valueOf(replicationFactor));
        }
    };
    KSMetaData ksm;
    try {
        ksm = KSMetaData.newKeyspace(keyspaceName, strategyName, options, true);
    } catch (ConfigurationException e) {
        throw new PermanentStorageException("Failed to instantiate keyspace metadata for " + keyspaceName, e);
    }
    try {
        MigrationManager.announceNewKeyspace(ksm);
        log.debug("Created keyspace {}", keyspaceName);
    } catch (ConfigurationException e) {
        throw new PermanentStorageException("Failed to create keyspace " + keyspaceName, e);
    }
}
Also used : HashMap(java.util.HashMap) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) KSMetaData(org.apache.cassandra.config.KSMetaData)

Aggregations

ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)84 IOException (java.io.IOException)12 URL (java.net.URL)6 HashMap (java.util.HashMap)6 Keyspace (org.apache.cassandra.db.Keyspace)5 DataInputStream (java.io.DataInputStream)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 HttpURLConnection (java.net.HttpURLConnection)4 Map (java.util.Map)4 Matcher (java.util.regex.Matcher)4 File (org.apache.cassandra.io.util.File)4 FilterInputStream (java.io.FilterInputStream)3 UnknownHostException (java.net.UnknownHostException)3 CFMetaData (org.apache.cassandra.config.CFMetaData)3 IPartitioner (org.apache.cassandra.dht.IPartitioner)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 PermanentStorageException (com.thinkaurelius.titan.diskstorage.PermanentStorageException)2 InputStream (java.io.InputStream)2 InetAddress (java.net.InetAddress)2 HashSet (java.util.HashSet)2