Search in sources :

Example 16 with ConfigurationException

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

the class CommitLogArchiver method maybeRestoreArchive.

public void maybeRestoreArchive() {
    if (Strings.isNullOrEmpty(restoreDirectories))
        return;
    for (String dir : restoreDirectories.split(DELIMITER)) {
        File[] files = new File(dir).listFiles();
        if (files == null) {
            throw new RuntimeException("Unable to list directory " + dir);
        }
        for (File fromFile : files) {
            CommitLogDescriptor fromHeader = CommitLogDescriptor.fromHeader(fromFile, DatabaseDescriptor.getEncryptionContext());
            CommitLogDescriptor fromName = CommitLogDescriptor.isValid(fromFile.getName()) ? CommitLogDescriptor.fromFileName(fromFile.getName()) : null;
            CommitLogDescriptor descriptor;
            if (fromHeader == null && fromName == null)
                throw new IllegalStateException("Cannot safely construct descriptor for segment, either from its name or its header: " + fromFile.getPath());
            else if (fromHeader != null && fromName != null && !fromHeader.equalsIgnoringCompression(fromName))
                throw new IllegalStateException(String.format("Cannot safely construct descriptor for segment, as name and header descriptors do not match (%s vs %s): %s", fromHeader, fromName, fromFile.getPath()));
            else if (fromName != null && fromHeader == null)
                throw new IllegalStateException("Cannot safely construct descriptor for segment, as name descriptor implies a version that should contain a header descriptor, but that descriptor could not be read: " + fromFile.getPath());
            else if (fromHeader != null)
                descriptor = fromHeader;
            else
                descriptor = fromName;
            if (descriptor.version > CommitLogDescriptor.current_version)
                throw new IllegalStateException("Unsupported commit log version: " + descriptor.version);
            if (descriptor.compression != null) {
                try {
                    CompressionParams.createCompressor(descriptor.compression);
                } catch (ConfigurationException e) {
                    throw new IllegalStateException("Unknown compression", e);
                }
            }
            File toFile = new File(DatabaseDescriptor.getCommitLogLocation(), descriptor.fileName());
            if (toFile.exists()) {
                logger.trace("Skipping restore of archive {} as the segment already exists in the restore location {}", fromFile.getPath(), toFile.getPath());
                continue;
            }
            String command = FROM.matcher(restoreCommand).replaceAll(Matcher.quoteReplacement(fromFile.getPath()));
            command = TO.matcher(command).replaceAll(Matcher.quoteReplacement(toFile.getPath()));
            try {
                exec(command);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
Also used : ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) IOException(java.io.IOException) File(java.io.File)

Example 17 with ConfigurationException

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

the class CommitLogDescriptor method writeHeader.

/**
     * @param additionalHeaders Allow segments to pass custom header data
     */
public static void writeHeader(ByteBuffer out, CommitLogDescriptor descriptor, Map<String, String> additionalHeaders) {
    CRC32 crc = new CRC32();
    out.putInt(descriptor.version);
    updateChecksumInt(crc, descriptor.version);
    out.putLong(descriptor.id);
    updateChecksumInt(crc, (int) (descriptor.id & 0xFFFFFFFFL));
    updateChecksumInt(crc, (int) (descriptor.id >>> 32));
    String parametersString = constructParametersString(descriptor.compression, descriptor.encryptionContext, additionalHeaders);
    byte[] parametersBytes = parametersString.getBytes(StandardCharsets.UTF_8);
    if (parametersBytes.length != (((short) parametersBytes.length) & 0xFFFF))
        throw new ConfigurationException(String.format("Compression parameters too long, length %d cannot be above 65535.", parametersBytes.length));
    out.putShort((short) parametersBytes.length);
    updateChecksumInt(crc, parametersBytes.length);
    out.put(parametersBytes);
    crc.update(parametersBytes, 0, parametersBytes.length);
    out.putInt((int) crc.getValue());
}
Also used : CRC32(java.util.zip.CRC32) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException)

Example 18 with ConfigurationException

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

the class AbstractCompactionStrategy method validateOptions.

public static Map<String, String> validateOptions(Map<String, String> options) throws ConfigurationException {
    String threshold = options.get(TOMBSTONE_THRESHOLD_OPTION);
    if (threshold != null) {
        try {
            float thresholdValue = Float.parseFloat(threshold);
            if (thresholdValue < 0) {
                throw new ConfigurationException(String.format("%s must be greater than 0, but was %f", TOMBSTONE_THRESHOLD_OPTION, thresholdValue));
            }
        } catch (NumberFormatException e) {
            throw new ConfigurationException(String.format("%s is not a parsable int (base10) for %s", threshold, TOMBSTONE_THRESHOLD_OPTION), e);
        }
    }
    String interval = options.get(TOMBSTONE_COMPACTION_INTERVAL_OPTION);
    if (interval != null) {
        try {
            long tombstoneCompactionInterval = Long.parseLong(interval);
            if (tombstoneCompactionInterval < 0) {
                throw new ConfigurationException(String.format("%s must be greater than 0, but was %d", TOMBSTONE_COMPACTION_INTERVAL_OPTION, tombstoneCompactionInterval));
            }
        } catch (NumberFormatException e) {
            throw new ConfigurationException(String.format("%s is not a parsable int (base10) for %s", interval, TOMBSTONE_COMPACTION_INTERVAL_OPTION), e);
        }
    }
    String unchecked = options.get(UNCHECKED_TOMBSTONE_COMPACTION_OPTION);
    if (unchecked != null) {
        if (!unchecked.equalsIgnoreCase("true") && !unchecked.equalsIgnoreCase("false"))
            throw new ConfigurationException(String.format("'%s' should be either 'true' or 'false', not '%s'", UNCHECKED_TOMBSTONE_COMPACTION_OPTION, unchecked));
    }
    String logAll = options.get(LOG_ALL_OPTION);
    if (logAll != null) {
        if (!logAll.equalsIgnoreCase("true") && !logAll.equalsIgnoreCase("false")) {
            throw new ConfigurationException(String.format("'%s' should either be 'true' or 'false', not %s", LOG_ALL_OPTION, logAll));
        }
    }
    String compactionEnabled = options.get(COMPACTION_ENABLED);
    if (compactionEnabled != null) {
        if (!compactionEnabled.equalsIgnoreCase("true") && !compactionEnabled.equalsIgnoreCase("false")) {
            throw new ConfigurationException(String.format("enabled should either be 'true' or 'false', not %s", compactionEnabled));
        }
    }
    Map<String, String> uncheckedOptions = new HashMap<String, String>(options);
    uncheckedOptions.remove(TOMBSTONE_THRESHOLD_OPTION);
    uncheckedOptions.remove(TOMBSTONE_COMPACTION_INTERVAL_OPTION);
    uncheckedOptions.remove(UNCHECKED_TOMBSTONE_COMPACTION_OPTION);
    uncheckedOptions.remove(LOG_ALL_OPTION);
    uncheckedOptions.remove(COMPACTION_ENABLED);
    uncheckedOptions.remove(ONLY_PURGE_REPAIRED_TOMBSTONES);
    uncheckedOptions.remove(CompactionParams.Option.PROVIDE_OVERLAPPING_TOMBSTONES.toString());
    return uncheckedOptions;
}
Also used : ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException)

Example 19 with ConfigurationException

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

the class SystemKeyspace method checkHealth.

/**
     * One of three things will happen if you try to read the system keyspace:
     * 1. files are present and you can read them: great
     * 2. no files are there: great (new node is assumed)
     * 3. files are present but you can't read them: bad
     * @throws ConfigurationException
     */
public static void checkHealth() throws ConfigurationException {
    Keyspace keyspace;
    try {
        keyspace = Keyspace.open(SchemaConstants.SYSTEM_KEYSPACE_NAME);
    } catch (AssertionError err) {
        // this happens when a user switches from OPP to RP.
        ConfigurationException ex = new ConfigurationException("Could not read system keyspace!");
        ex.initCause(err);
        throw ex;
    }
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(LOCAL);
    String req = "SELECT cluster_name FROM system.%s WHERE key='%s'";
    UntypedResultSet result = executeInternal(format(req, LOCAL, LOCAL));
    if (result.isEmpty() || !result.one().has("cluster_name")) {
        // this is a brand new node
        if (!cfs.getLiveSSTables().isEmpty())
            throw new ConfigurationException("Found system keyspace files, but they couldn't be loaded!");
        // no system files.  this is a new node.
        return;
    }
    String savedClusterName = result.one().getString("cluster_name");
    if (!DatabaseDescriptor.getClusterName().equals(savedClusterName))
        throw new ConfigurationException("Saved cluster name " + savedClusterName + " != configured name " + DatabaseDescriptor.getClusterName());
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException)

Example 20 with ConfigurationException

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);
    }
    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 = SizeTieredCompactionStrategyOptions.validateOptions(options, uncheckedOptions);
    return uncheckedOptions;
}
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