use of org.apache.cassandra.exceptions.ConfigurationException in project cassandra by apache.
the class CompressionParams method createCompressor.
private static ICompressor createCompressor(Class<?> compressorClass, Map<String, String> compressionOptions) throws ConfigurationException {
if (compressorClass == null) {
if (!compressionOptions.isEmpty())
throw new ConfigurationException("Unknown compression options (" + compressionOptions.keySet() + ") since no compression class found");
return null;
}
if (compressionOptions.containsKey(CRC_CHECK_CHANCE)) {
if (!hasLoggedCrcCheckChanceWarning) {
logger.warn(CRC_CHECK_CHANCE_WARNING);
hasLoggedCrcCheckChanceWarning = true;
}
compressionOptions.remove(CRC_CHECK_CHANCE);
}
try {
Method method = compressorClass.getMethod("create", Map.class);
ICompressor compressor = (ICompressor) method.invoke(null, compressionOptions);
// Check for unknown options
for (String provided : compressionOptions.keySet()) if (!compressor.supportedOptions().contains(provided))
throw new ConfigurationException("Unknown compression options " + provided);
return compressor;
} catch (NoSuchMethodException e) {
throw new ConfigurationException("create method not found", e);
} catch (SecurityException e) {
throw new ConfigurationException("Access forbiden", e);
} catch (IllegalAccessException e) {
throw new ConfigurationException("Cannot access method create in " + compressorClass.getName(), e);
} catch (InvocationTargetException e) {
if (e.getTargetException() instanceof ConfigurationException)
throw (ConfigurationException) e.getTargetException();
Throwable cause = e.getCause() == null ? e : e.getCause();
throw new ConfigurationException(format("%s.create() threw an error: %s %s", compressorClass.getSimpleName(), cause.getClass().getName(), cause.getMessage()), e);
} catch (ExceptionInInitializerError e) {
throw new ConfigurationException("Cannot initialize class " + compressorClass.getName());
}
}
use of org.apache.cassandra.exceptions.ConfigurationException in project cassandra by apache.
the class IndexMetadata method validate.
public void validate(TableMetadata table) {
if (!isNameValid(name))
throw new ConfigurationException("Illegal index name " + name);
if (kind == null)
throw new ConfigurationException("Index kind is null for index " + name);
if (kind == Kind.CUSTOM) {
if (options == null || !options.containsKey(IndexTarget.CUSTOM_INDEX_OPTION_NAME))
throw new ConfigurationException(String.format("Required option missing for index %s : %s", name, IndexTarget.CUSTOM_INDEX_OPTION_NAME));
String className = options.get(IndexTarget.CUSTOM_INDEX_OPTION_NAME);
Class<Index> indexerClass = FBUtilities.classForName(className, "custom indexer");
if (!Index.class.isAssignableFrom(indexerClass))
throw new ConfigurationException(String.format("Specified Indexer class (%s) does not implement the Indexer interface", className));
validateCustomIndexOptions(table, indexerClass, options);
}
}
use of org.apache.cassandra.exceptions.ConfigurationException in project cassandra by apache.
the class CompactionParams method validate.
public void validate() {
try {
Map<?, ?> unknownOptions = (Map) klass.getMethod("validateOptions", Map.class).invoke(null, options);
if (!unknownOptions.isEmpty()) {
throw new ConfigurationException(format("Properties specified %s are not understood by %s", unknownOptions.keySet(), klass.getSimpleName()));
}
} catch (NoSuchMethodException e) {
logger.warn("Compaction strategy {} does not have a static validateOptions method. Validation ignored", klass.getName());
} catch (InvocationTargetException e) {
if (e.getTargetException() instanceof ConfigurationException)
throw (ConfigurationException) e.getTargetException();
Throwable cause = e.getCause() == null ? e : e.getCause();
throw new ConfigurationException(format("%s.validateOptions() threw an error: %s %s", klass.getName(), cause.getClass().getName(), cause.getMessage()), e);
} catch (IllegalAccessException e) {
throw new ConfigurationException("Cannot access method validateOptions in " + klass.getName(), e);
}
String minThreshold = options.get(Option.MIN_THRESHOLD.toString());
if (minThreshold != null && !StringUtils.isNumeric(minThreshold)) {
throw new ConfigurationException(format("Invalid value %s for '%s' compaction sub-option - must be an integer", minThreshold, Option.MIN_THRESHOLD));
}
String maxThreshold = options.get(Option.MAX_THRESHOLD.toString());
if (maxThreshold != null && !StringUtils.isNumeric(maxThreshold)) {
throw new ConfigurationException(format("Invalid value %s for '%s' compaction sub-option - must be an integer", maxThreshold, Option.MAX_THRESHOLD));
}
if (minCompactionThreshold() <= 0 || maxCompactionThreshold() <= 0) {
throw new ConfigurationException("Disabling compaction by setting compaction thresholds to 0 has been removed," + " set the compaction option 'enabled' to false instead.");
}
if (minCompactionThreshold() <= 1) {
throw new ConfigurationException(format("Min compaction threshold cannot be less than 2 (got %d)", minCompactionThreshold()));
}
if (minCompactionThreshold() > maxCompactionThreshold()) {
throw new ConfigurationException(format("Min compaction threshold (got %d) cannot be greater than max compaction threshold (got %d)", minCompactionThreshold(), maxCompactionThreshold()));
}
}
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.remove(SINGLE_SSTABLE_UPLEVEL_OPTION);
uncheckedOptions.remove(CompactionParams.Option.MIN_THRESHOLD.toString());
uncheckedOptions.remove(CompactionParams.Option.MAX_THRESHOLD.toString());
uncheckedOptions = SizeTieredCompactionStrategyOptions.validateOptions(options, uncheckedOptions);
return uncheckedOptions;
}
use of org.apache.cassandra.exceptions.ConfigurationException in project cassandra by apache.
the class TimeWindowCompactionStrategyOptions method validateOptions.
public static Map<String, String> validateOptions(Map<String, String> options, Map<String, String> uncheckedOptions) throws ConfigurationException {
String optionValue = options.get(TIMESTAMP_RESOLUTION_KEY);
try {
if (optionValue != null)
if (!validTimestampTimeUnits.contains(TimeUnit.valueOf(optionValue)))
throw new ConfigurationException(String.format("%s is not valid for %s", optionValue, TIMESTAMP_RESOLUTION_KEY));
} catch (IllegalArgumentException e) {
throw new ConfigurationException(String.format("%s is not valid for %s", optionValue, TIMESTAMP_RESOLUTION_KEY));
}
optionValue = options.get(COMPACTION_WINDOW_UNIT_KEY);
try {
if (optionValue != null)
if (!validWindowTimeUnits.contains(TimeUnit.valueOf(optionValue)))
throw new ConfigurationException(String.format("%s is not valid for %s", optionValue, COMPACTION_WINDOW_UNIT_KEY));
} catch (IllegalArgumentException e) {
throw new ConfigurationException(String.format("%s is not valid for %s", optionValue, COMPACTION_WINDOW_UNIT_KEY), e);
}
optionValue = options.get(COMPACTION_WINDOW_SIZE_KEY);
try {
int sstableWindowSize = optionValue == null ? DEFAULT_COMPACTION_WINDOW_SIZE : Integer.parseInt(optionValue);
if (sstableWindowSize < 1) {
throw new ConfigurationException(String.format("%d must be greater than 1 for %s", sstableWindowSize, COMPACTION_WINDOW_SIZE_KEY));
}
} catch (NumberFormatException e) {
throw new ConfigurationException(String.format("%s is not a parsable int (base10) for %s", optionValue, COMPACTION_WINDOW_SIZE_KEY), e);
}
optionValue = options.get(EXPIRED_SSTABLE_CHECK_FREQUENCY_SECONDS_KEY);
try {
long expiredCheckFrequency = optionValue == null ? DEFAULT_EXPIRED_SSTABLE_CHECK_FREQUENCY_SECONDS : Long.parseLong(optionValue);
if (expiredCheckFrequency < 0) {
throw new ConfigurationException(String.format("%s must not be negative, but was %d", EXPIRED_SSTABLE_CHECK_FREQUENCY_SECONDS_KEY, expiredCheckFrequency));
}
} catch (NumberFormatException e) {
throw new ConfigurationException(String.format("%s is not a parsable int (base10) for %s", optionValue, EXPIRED_SSTABLE_CHECK_FREQUENCY_SECONDS_KEY), e);
}
optionValue = options.get(UNSAFE_AGGRESSIVE_SSTABLE_EXPIRATION_KEY);
if (optionValue != null) {
if (!(optionValue.equalsIgnoreCase("true") || optionValue.equalsIgnoreCase("false")))
throw new ConfigurationException(String.format("%s is not 'true' or 'false' (%s)", UNSAFE_AGGRESSIVE_SSTABLE_EXPIRATION_KEY, optionValue));
if (optionValue.equalsIgnoreCase("true") && !Boolean.getBoolean(UNSAFE_AGGRESSIVE_SSTABLE_EXPIRATION_PROPERTY))
throw new ConfigurationException(String.format("%s is requested but not allowed, restart cassandra with -D%s=true to allow it", UNSAFE_AGGRESSIVE_SSTABLE_EXPIRATION_KEY, UNSAFE_AGGRESSIVE_SSTABLE_EXPIRATION_PROPERTY));
}
uncheckedOptions.remove(COMPACTION_WINDOW_SIZE_KEY);
uncheckedOptions.remove(COMPACTION_WINDOW_UNIT_KEY);
uncheckedOptions.remove(TIMESTAMP_RESOLUTION_KEY);
uncheckedOptions.remove(EXPIRED_SSTABLE_CHECK_FREQUENCY_SECONDS_KEY);
uncheckedOptions.remove(UNSAFE_AGGRESSIVE_SSTABLE_EXPIRATION_KEY);
uncheckedOptions = SizeTieredCompactionStrategyOptions.validateOptions(options, uncheckedOptions);
return uncheckedOptions;
}
Aggregations