Example #1
0
  public void validate() throws InvalidRequestException, ConfigurationException {
    compactionStrategyClass = CFMetaData.DEFAULT_COMPACTION_STRATEGY_CLASS;

    // we need to remove parent:key = value pairs from the main properties
    Set<String> propsToRemove = new HashSet<String>();

    // check if we have compaction/compression options
    for (String property : properties.keySet()) {
      if (!property.contains(":")) continue;

      String key = property.split(":")[1];
      String val = properties.get(property);

      if (property.startsWith(COMPACTION_OPTIONS_PREFIX)) {
        compactionStrategyOptions.put(key, val);
        propsToRemove.add(property);
      }

      if (property.startsWith(COMPRESSION_PARAMETERS_PREFIX)) {
        compressionParameters.put(key, val);
        propsToRemove.add(property);
      }
    }

    for (String property : propsToRemove) properties.remove(property);
    // Catch the case where someone passed a kwarg that is not recognized.
    for (String bogus : Sets.difference(properties.keySet(), allowedKeywords))
      throw new InvalidRequestException(
          bogus + " is not a valid keyword argument for CREATE COLUMNFAMILY");
    for (String obsolete : Sets.intersection(properties.keySet(), obsoleteKeywords))
      logger.warn("Ignoring obsolete property {}", obsolete);

    // Validate min/max compaction thresholds
    Integer minCompaction = getPropertyInt(KW_MINCOMPACTIONTHRESHOLD, null);
    Integer maxCompaction = getPropertyInt(KW_MAXCOMPACTIONTHRESHOLD, null);

    if ((minCompaction != null) && (maxCompaction != null)) // Both min and max are set
    {
      if ((minCompaction > maxCompaction) && (maxCompaction != 0))
        throw new InvalidRequestException(
            String.format(
                "%s cannot be larger than %s",
                KW_MINCOMPACTIONTHRESHOLD, KW_MAXCOMPACTIONTHRESHOLD));
    } else if (minCompaction != null) // Only the min threshold is set
    {
      if (minCompaction > CFMetaData.DEFAULT_MAX_COMPACTION_THRESHOLD)
        throw new InvalidRequestException(
            String.format(
                "%s cannot be larger than %s, (default %s)",
                KW_MINCOMPACTIONTHRESHOLD,
                KW_MAXCOMPACTIONTHRESHOLD,
                CFMetaData.DEFAULT_MAX_COMPACTION_THRESHOLD));
    } else if (maxCompaction != null) // Only the max threshold is set
    {
      if ((maxCompaction < CFMetaData.DEFAULT_MIN_COMPACTION_THRESHOLD) && (maxCompaction != 0))
        throw new InvalidRequestException(
            String.format(
                "%s cannot be smaller than %s, (default %s)",
                KW_MAXCOMPACTIONTHRESHOLD,
                KW_MINCOMPACTIONTHRESHOLD,
                CFMetaData.DEFAULT_MIN_COMPACTION_THRESHOLD));
    }

    CFMetaData.validateCompactionOptions(compactionStrategyClass, compactionStrategyOptions);
  }
Example #2
0
  public void validate() throws ConfigurationException, SyntaxException {
    // Skip validation if the comapction strategy class is already set as it means we've alreayd
    // prepared (and redoing it would set strategyClass back to null, which we don't want)
    if (compactionStrategyClass != null) return;

    validate(keywords, obsoleteKeywords);

    Map<String, String> compactionOptions = getCompactionOptions();
    if (!compactionOptions.isEmpty()) {
      String strategy = compactionOptions.get(COMPACTION_STRATEGY_CLASS_KEY);
      if (strategy == null)
        throw new ConfigurationException(
            "Missing sub-option '"
                + COMPACTION_STRATEGY_CLASS_KEY
                + "' for the '"
                + KW_COMPACTION
                + "' option.");

      compactionStrategyClass = CFMetaData.createCompactionStrategy(strategy);
      compactionOptions.remove(COMPACTION_STRATEGY_CLASS_KEY);

      CFMetaData.validateCompactionOptions(compactionStrategyClass, compactionOptions);
    }

    Map<String, String> compressionOptions = getCompressionOptions();
    if (!compressionOptions.isEmpty()) {
      String sstableCompressionClass =
          compressionOptions.get(CompressionParameters.SSTABLE_COMPRESSION);
      if (sstableCompressionClass == null)
        throw new ConfigurationException(
            "Missing sub-option '"
                + CompressionParameters.SSTABLE_COMPRESSION
                + "' for the '"
                + KW_COMPRESSION
                + "' option.");

      Integer chunkLength = CompressionParameters.DEFAULT_CHUNK_LENGTH;
      if (compressionOptions.containsKey(CompressionParameters.CHUNK_LENGTH_KB))
        chunkLength =
            CompressionParameters.parseChunkLength(
                compressionOptions.get(CompressionParameters.CHUNK_LENGTH_KB));

      Map<String, String> remainingOptions = new HashMap<>(compressionOptions);
      remainingOptions.remove(CompressionParameters.SSTABLE_COMPRESSION);
      remainingOptions.remove(CompressionParameters.CHUNK_LENGTH_KB);
      CompressionParameters cp =
          new CompressionParameters(sstableCompressionClass, chunkLength, remainingOptions);
      cp.validate();
    }

    validateMinimumInt(KW_DEFAULT_TIME_TO_LIVE, 0, CFMetaData.DEFAULT_DEFAULT_TIME_TO_LIVE);

    Integer minIndexInterval = getInt(KW_MIN_INDEX_INTERVAL, null);
    Integer maxIndexInterval = getInt(KW_MAX_INDEX_INTERVAL, null);
    if (minIndexInterval != null && minIndexInterval < 1)
      throw new ConfigurationException(KW_MIN_INDEX_INTERVAL + " must be greater than 0");
    if (maxIndexInterval != null && minIndexInterval != null && maxIndexInterval < minIndexInterval)
      throw new ConfigurationException(
          KW_MAX_INDEX_INTERVAL + " must be greater than " + KW_MIN_INDEX_INTERVAL);

    SpeculativeRetry.fromString(
        getString(KW_SPECULATIVE_RETRY, SpeculativeRetry.RetryType.NONE.name()));
  }