use of org.apache.cassandra.exceptions.ConfigurationException in project cassandra by apache.
the class IndexMode method getMode.
public static IndexMode getMode(ColumnMetadata column, Map<String, String> indexOptions) throws ConfigurationException {
if (indexOptions == null || indexOptions.isEmpty())
return IndexMode.NOT_INDEXED;
Mode mode;
try {
mode = indexOptions.get(INDEX_MODE_OPTION) == null ? Mode.PREFIX : Mode.mode(indexOptions.get(INDEX_MODE_OPTION));
} catch (IllegalArgumentException e) {
throw new ConfigurationException("Incorrect index mode: " + indexOptions.get(INDEX_MODE_OPTION));
}
boolean isAnalyzed = false;
Class analyzerClass = null;
try {
if (indexOptions.get(INDEX_ANALYZER_CLASS_OPTION) != null) {
analyzerClass = Class.forName(indexOptions.get(INDEX_ANALYZER_CLASS_OPTION));
isAnalyzed = indexOptions.get(INDEX_ANALYZED_OPTION) == null ? true : Boolean.parseBoolean(indexOptions.get(INDEX_ANALYZED_OPTION));
} else if (indexOptions.get(INDEX_ANALYZED_OPTION) != null) {
isAnalyzed = Boolean.parseBoolean(indexOptions.get(INDEX_ANALYZED_OPTION));
}
} catch (ClassNotFoundException e) {
// should not happen as we already validated we could instantiate an instance in validateAnalyzer()
logger.error("Failed to find specified analyzer class [{}]. Falling back to default analyzer", indexOptions.get(INDEX_ANALYZER_CLASS_OPTION));
}
boolean isLiteral = false;
try {
String literalOption = indexOptions.get(INDEX_IS_LITERAL_OPTION);
AbstractType<?> validator = column.cellValueType();
isLiteral = literalOption == null ? (validator instanceof UTF8Type || validator instanceof AsciiType) : Boolean.parseBoolean(literalOption);
} catch (Exception e) {
logger.error("failed to parse {} option, defaulting to 'false'.", INDEX_IS_LITERAL_OPTION);
}
Long maxMemMb = indexOptions.get(INDEX_MAX_FLUSH_MEMORY_OPTION) == null ? // 1G default for memtable
(long) (1073741824 * INDEX_MAX_FLUSH_DEFAULT_MULTIPLIER) : Long.parseLong(indexOptions.get(INDEX_MAX_FLUSH_MEMORY_OPTION));
return new IndexMode(mode, isLiteral, isAnalyzed, analyzerClass, maxMemMb);
}
use of org.apache.cassandra.exceptions.ConfigurationException in project cassandra by apache.
the class TargetParser method parse.
public static Pair<ColumnMetadata, IndexTarget.Type> parse(TableMetadata metadata, IndexMetadata indexDef) {
String target = indexDef.options.get("target");
assert target != null : String.format("No target definition found for index %s", indexDef.name);
Pair<ColumnMetadata, IndexTarget.Type> result = parse(metadata, target);
if (result == null)
throw new ConfigurationException(String.format("Unable to parse targets for index %s (%s)", indexDef.name, target));
return result;
}
use of org.apache.cassandra.exceptions.ConfigurationException in project cassandra by apache.
the class SASIIndex method validateOptions.
public static Map<String, String> validateOptions(Map<String, String> options, TableMetadata metadata) {
if (!(metadata.partitioner instanceof Murmur3Partitioner))
throw new ConfigurationException("SASI only supports Murmur3Partitioner.");
String targetColumn = options.get("target");
if (targetColumn == null)
throw new ConfigurationException("unknown target column");
Pair<ColumnMetadata, IndexTarget.Type> target = TargetParser.parse(metadata, targetColumn);
if (target == null)
throw new ConfigurationException("failed to retrieve target column for: " + targetColumn);
if (target.left.isComplex())
throw new ConfigurationException("complex columns are not yet supported by SASI");
IndexMode.validateAnalyzer(options);
IndexMode mode = IndexMode.getMode(target.left, options);
if (mode.mode == Mode.SPARSE) {
if (mode.isLiteral)
throw new ConfigurationException("SPARSE mode is only supported on non-literal columns.");
if (mode.isAnalyzed)
throw new ConfigurationException("SPARSE mode doesn't support analyzers.");
}
return Collections.emptyMap();
}
use of org.apache.cassandra.exceptions.ConfigurationException in project cassandra by apache.
the class MessagingService method getServerSockets.
@SuppressWarnings("resource")
private List<ServerSocket> getServerSockets(InetAddress localEp) throws ConfigurationException {
final List<ServerSocket> ss = new ArrayList<ServerSocket>(2);
if (DatabaseDescriptor.getServerEncryptionOptions().internode_encryption != ServerEncryptionOptions.InternodeEncryption.none) {
try {
ss.add(SSLFactory.getServerSocket(DatabaseDescriptor.getServerEncryptionOptions(), localEp, DatabaseDescriptor.getSSLStoragePort()));
} catch (IOException e) {
throw new ConfigurationException("Unable to create ssl socket", e);
}
// setReuseAddress happens in the factory.
logger.info("Starting Encrypted Messaging Service on SSL port {}", DatabaseDescriptor.getSSLStoragePort());
}
if (DatabaseDescriptor.getServerEncryptionOptions().internode_encryption != ServerEncryptionOptions.InternodeEncryption.all) {
ServerSocketChannel serverChannel = null;
try {
serverChannel = ServerSocketChannel.open();
} catch (IOException e) {
throw new RuntimeException(e);
}
ServerSocket socket = serverChannel.socket();
try {
socket.setReuseAddress(true);
} catch (SocketException e) {
FileUtils.closeQuietly(socket);
throw new ConfigurationException("Insufficient permissions to setReuseAddress", e);
}
InetSocketAddress address = new InetSocketAddress(localEp, DatabaseDescriptor.getStoragePort());
try {
socket.bind(address, 500);
} catch (BindException e) {
FileUtils.closeQuietly(socket);
if (e.getMessage().contains("in use"))
throw new ConfigurationException(address + " is in use by another process. Change listen_address:storage_port in cassandra.yaml to values that do not conflict with other services");
else if (e.getMessage().contains("Cannot assign requested address"))
throw new ConfigurationException("Unable to bind to address " + address + ". Set listen_address in cassandra.yaml to an interface you can bind to, e.g., your private IP address on EC2");
else
throw new RuntimeException(e);
} catch (IOException e) {
FileUtils.closeQuietly(socket);
throw new RuntimeException(e);
}
String nic = FBUtilities.getNetworkInterface(localEp);
logger.info("Starting Messaging Service on {}:{}{}", localEp, DatabaseDescriptor.getStoragePort(), nic == null ? "" : String.format(" (%s)", nic));
ss.add(socket);
}
return ss;
}
use of org.apache.cassandra.exceptions.ConfigurationException in project cassandra by apache.
the class PropertyFileSnitch method reloadConfiguration.
public void reloadConfiguration(boolean isUpdate) throws ConfigurationException {
HashMap<InetAddress, String[]> reloadedMap = new HashMap<>();
String[] reloadedDefaultDCRack = null;
Properties properties = new Properties();
try (InputStream stream = getClass().getClassLoader().getResourceAsStream(SNITCH_PROPERTIES_FILENAME)) {
properties.load(stream);
} catch (Exception e) {
throw new ConfigurationException("Unable to read " + SNITCH_PROPERTIES_FILENAME, e);
}
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
String key = (String) entry.getKey();
String value = (String) entry.getValue();
if ("default".equals(key)) {
String[] newDefault = value.split(":");
if (newDefault.length < 2)
reloadedDefaultDCRack = new String[] { "default", "default" };
else
reloadedDefaultDCRack = new String[] { newDefault[0].trim(), newDefault[1].trim() };
} else {
InetAddress host;
String hostString = StringUtils.remove(key, '/');
try {
host = InetAddress.getByName(hostString);
} catch (UnknownHostException e) {
throw new ConfigurationException("Unknown host " + hostString, e);
}
String[] token = value.split(":");
if (token.length < 2)
token = new String[] { "default", "default" };
else
token = new String[] { token[0].trim(), token[1].trim() };
reloadedMap.put(host, token);
}
}
InetAddress broadcastAddress = FBUtilities.getBroadcastAddress();
String[] localInfo = reloadedMap.get(broadcastAddress);
if (reloadedDefaultDCRack == null && localInfo == null)
throw new ConfigurationException(String.format("Snitch definitions at %s do not define a location for " + "this node's broadcast address %s, nor does it provides a default", SNITCH_PROPERTIES_FILENAME, broadcastAddress));
// OutboundTcpConnectionPool.getEndpoint() converts our broadcast address to local,
// make sure we can be found at that as well.
InetAddress localAddress = FBUtilities.getLocalAddress();
if (!localAddress.equals(broadcastAddress) && !reloadedMap.containsKey(localAddress))
reloadedMap.put(localAddress, localInfo);
if (isUpdate && !livenessCheck(reloadedMap, reloadedDefaultDCRack))
return;
if (logger.isTraceEnabled()) {
StringBuilder sb = new StringBuilder();
for (Map.Entry<InetAddress, String[]> entry : reloadedMap.entrySet()) sb.append(entry.getKey()).append(':').append(Arrays.toString(entry.getValue())).append(", ");
logger.trace("Loaded network topology from property file: {}", StringUtils.removeEnd(sb.toString(), ", "));
}
defaultDCRack = reloadedDefaultDCRack;
endpointMap = reloadedMap;
if (// null check tolerates circular dependency; see CASSANDRA-4145
StorageService.instance != null) {
if (isUpdate)
StorageService.instance.updateTopology();
else
StorageService.instance.getTokenMetadata().invalidateCachedRings();
}
if (gossipStarted)
StorageService.instance.gossipSnitchInfo();
}
Aggregations