Search in sources :

Example 21 with ConfigurationException

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

the class LeveledCompactionStrategy method validateOptions.

public static Map<String, String> validateOptions(Map<String, String> options) throws ConfigurationException {
    Map<String, String> uncheckedOptions = AbstractCompactionStrategy.validateOptions(options);
    String size = options.containsKey(SSTABLE_SIZE_OPTION) ? options.get(SSTABLE_SIZE_OPTION) : "1";
    try {
        int ssSize = Integer.parseInt(size);
        if (ssSize < 1) {
            throw new ConfigurationException(String.format("%s must be larger than 0, but was %s", SSTABLE_SIZE_OPTION, ssSize));
        }
    } catch (NumberFormatException ex) {
        throw new ConfigurationException(String.format("%s is not a parsable int (base10) for %s", size, SSTABLE_SIZE_OPTION), ex);
    }
    uncheckedOptions.remove(SSTABLE_SIZE_OPTION);
    // Validate the fanout_size option
    String levelFanoutSize = options.containsKey(LEVEL_FANOUT_SIZE_OPTION) ? options.get(LEVEL_FANOUT_SIZE_OPTION) : String.valueOf(DEFAULT_LEVEL_FANOUT_SIZE);
    try {
        int fanoutSize = Integer.parseInt(levelFanoutSize);
        if (fanoutSize < 1) {
            throw new ConfigurationException(String.format("%s must be larger than 0, but was %s", LEVEL_FANOUT_SIZE_OPTION, fanoutSize));
        }
    } catch (NumberFormatException ex) {
        throw new ConfigurationException(String.format("%s is not a parsable int (base10) for %s", size, LEVEL_FANOUT_SIZE_OPTION), ex);
    }
    uncheckedOptions.remove(LEVEL_FANOUT_SIZE_OPTION);
    uncheckedOptions = SizeTieredCompactionStrategyOptions.validateOptions(options, uncheckedOptions);
    return uncheckedOptions;
}
Also used : ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException)

Example 22 with ConfigurationException

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

the class TokenAllocation method adjustForCrossDatacenterClashes.

private static Collection<Token> adjustForCrossDatacenterClashes(final TokenMetadata tokenMetadata, StrategyAdapter strategy, Collection<Token> tokens) {
    List<Token> filtered = Lists.newArrayListWithCapacity(tokens.size());
    for (Token t : tokens) {
        while (tokenMetadata.getEndpoint(t) != null) {
            InetAddress other = tokenMetadata.getEndpoint(t);
            if (strategy.inAllocationRing(other))
                throw new ConfigurationException(String.format("Allocated token %s already assigned to node %s. Is another node also allocating tokens?", t, other));
            t = t.increaseSlightly();
        }
        filtered.add(t);
    }
    return filtered;
}
Also used : ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) Token(org.apache.cassandra.dht.Token) InetAddress(java.net.InetAddress)

Example 23 with ConfigurationException

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

the class TokenAllocation method getStrategy.

static StrategyAdapter getStrategy(final TokenMetadata tokenMetadata, final NetworkTopologyStrategy rs, final IEndpointSnitch snitch, final InetAddress endpoint) {
    final String dc = snitch.getDatacenter(endpoint);
    final int replicas = rs.getReplicationFactor(dc);
    if (replicas == 0 || replicas == 1) {
        // No replication, each node is treated as separate.
        return new StrategyAdapter() {

            @Override
            public int replicas() {
                return 1;
            }

            @Override
            public Object getGroup(InetAddress unit) {
                return unit;
            }

            @Override
            public boolean inAllocationRing(InetAddress other) {
                return dc.equals(snitch.getDatacenter(other));
            }
        };
    }
    Topology topology = tokenMetadata.getTopology();
    int racks = topology.getDatacenterRacks().get(dc).asMap().size();
    if (racks >= replicas) {
        return new StrategyAdapter() {

            @Override
            public int replicas() {
                return replicas;
            }

            @Override
            public Object getGroup(InetAddress unit) {
                return snitch.getRack(unit);
            }

            @Override
            public boolean inAllocationRing(InetAddress other) {
                return dc.equals(snitch.getDatacenter(other));
            }
        };
    } else if (racks == 1) {
        // One rack, each node treated as separate.
        return new StrategyAdapter() {

            @Override
            public int replicas() {
                return replicas;
            }

            @Override
            public Object getGroup(InetAddress unit) {
                return unit;
            }

            @Override
            public boolean inAllocationRing(InetAddress other) {
                return dc.equals(snitch.getDatacenter(other));
            }
        };
    } else
        throw new ConfigurationException(String.format("Token allocation failed: the number of racks %d in datacenter %s is lower than its replication factor %d.", racks, dc, replicas));
}
Also used : ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) Topology(org.apache.cassandra.locator.TokenMetadata.Topology) InetAddress(java.net.InetAddress)

Example 24 with ConfigurationException

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

the class BootStrapper method allocateTokens.

static Collection<Token> allocateTokens(final TokenMetadata metadata, InetAddress address, String allocationKeyspace, int numTokens, int schemaWaitDelay) {
    StorageService.instance.waitForSchema(schemaWaitDelay);
    if (!FBUtilities.getBroadcastAddress().equals(InetAddress.getLoopbackAddress()))
        Gossiper.waitToSettle();
    Keyspace ks = Keyspace.open(allocationKeyspace);
    if (ks == null)
        throw new ConfigurationException("Problem opening token allocation keyspace " + allocationKeyspace);
    AbstractReplicationStrategy rs = ks.getReplicationStrategy();
    return TokenAllocation.allocateTokens(metadata, rs, address, numTokens);
}
Also used : ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) Keyspace(org.apache.cassandra.db.Keyspace) AbstractReplicationStrategy(org.apache.cassandra.locator.AbstractReplicationStrategy)

Example 25 with ConfigurationException

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

the class BootStrapper method getBootstrapTokens.

/**
     * if initialtoken was specified, use that (split on comma).
     * otherwise, if allocationKeyspace is specified use the token allocation algorithm to generate suitable tokens
     * else choose num_tokens tokens at random
     */
public static Collection<Token> getBootstrapTokens(final TokenMetadata metadata, InetAddress address, int schemaWaitDelay) throws ConfigurationException {
    String allocationKeyspace = DatabaseDescriptor.getAllocateTokensForKeyspace();
    Collection<String> initialTokens = DatabaseDescriptor.getInitialTokens();
    if (initialTokens.size() > 0 && allocationKeyspace != null)
        logger.warn("manually specified tokens override automatic allocation");
    // if user specified tokens, use those
    if (initialTokens.size() > 0)
        return getSpecifiedTokens(metadata, initialTokens);
    int numTokens = DatabaseDescriptor.getNumTokens();
    if (numTokens < 1)
        throw new ConfigurationException("num_tokens must be >= 1");
    if (allocationKeyspace != null)
        return allocateTokens(metadata, address, allocationKeyspace, numTokens, schemaWaitDelay);
    if (numTokens == 1)
        logger.warn("Picking random token for a single vnode.  You should probably add more vnodes and/or use the automatic token allocation mechanism.");
    return getRandomTokens(metadata, numTokens);
}
Also used : ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException)

Aggregations

ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)59 IOException (java.io.IOException)11 URL (java.net.URL)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 DataInputStream (java.io.DataInputStream)3 File (java.io.File)3 HttpURLConnection (java.net.HttpURLConnection)3 InetAddress (java.net.InetAddress)3 UnknownHostException (java.net.UnknownHostException)3 HashMap (java.util.HashMap)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 FilterInputStream (java.io.FilterInputStream)2 InputStream (java.io.InputStream)2 NoSuchFileException (java.nio.file.NoSuchFileException)2 Map (java.util.Map)2 StartupException (org.apache.cassandra.exceptions.StartupException)2 CorruptSSTableException (org.apache.cassandra.io.sstable.CorruptSSTableException)2 ColumnMetadata (org.apache.cassandra.schema.ColumnMetadata)2 TableMetadata (org.apache.cassandra.schema.TableMetadata)2 BufferPoolMetricSet (com.codahale.metrics.jvm.BufferPoolMetricSet)1