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;
}
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;
}
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));
}
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);
}
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);
}
Aggregations