Search in sources :

Example 26 with ConfigurationException

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);
}
Also used : Mode(org.apache.cassandra.index.sasi.disk.OnDiskIndexBuilder.Mode) AsciiType(org.apache.cassandra.db.marshal.AsciiType) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) UTF8Type(org.apache.cassandra.db.marshal.UTF8Type) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException)

Example 27 with ConfigurationException

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;
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException)

Example 28 with ConfigurationException

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();
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) AbstractType(org.apache.cassandra.db.marshal.AbstractType) OperationType(org.apache.cassandra.db.compaction.OperationType) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) IndexMode(org.apache.cassandra.index.sasi.conf.IndexMode) Murmur3Partitioner(org.apache.cassandra.dht.Murmur3Partitioner)

Example 29 with ConfigurationException

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;
}
Also used : ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) ServerSocketChannel(java.nio.channels.ServerSocketChannel)

Example 30 with ConfigurationException

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();
}
Also used : UnknownHostException(java.net.UnknownHostException) HashMap(java.util.HashMap) InputStream(java.io.InputStream) Properties(java.util.Properties) UnknownHostException(java.net.UnknownHostException) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) InetAddress(java.net.InetAddress) HashMap(java.util.HashMap) Map(java.util.Map)

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