Java Code Examples for org.apache.cassandra.config.CFMetaData#validateCompactionOptions()

The following examples show how to use org.apache.cassandra.config.CFMetaData#validateCompactionOptions() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CassandraServer.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public String system_add_column_family(CfDef cf_def)
throws InvalidRequestException, SchemaDisagreementException, TException
{
    logger.debug("add_column_family");

    try
    {
        ClientState cState = state();
        String keyspace = cState.getKeyspace();
        cState.hasKeyspaceAccess(keyspace, Permission.CREATE);
        cf_def.unsetId(); // explicitly ignore any id set by client (Hector likes to set zero)
        CFMetaData cfm = CFMetaData.fromThrift(cf_def);
        CFMetaData.validateCompactionOptions(cfm.compactionStrategyClass, cfm.compactionStrategyOptions);
        cfm.addDefaultIndexNames();

        if (!cfm.getTriggers().isEmpty())
            state().ensureIsSuper("Only superusers are allowed to add triggers.");

        MigrationManager.announceNewColumnFamily(cfm);
        return Schema.instance.getVersion().toString();
    }
    catch (RequestValidationException e)
    {
        throw ThriftConversion.toThrift(e);
    }
}
 
Example 2
Source File: CassandraServer.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public String system_update_column_family(CfDef cf_def)
throws InvalidRequestException, SchemaDisagreementException, TException
{
    logger.debug("update_column_family");

    try
    {
        if (cf_def.keyspace == null || cf_def.name == null)
            throw new InvalidRequestException("Keyspace and CF name must be set.");

        state().hasColumnFamilyAccess(cf_def.keyspace, cf_def.name, Permission.ALTER);
        CFMetaData oldCfm = Schema.instance.getCFMetaData(cf_def.keyspace, cf_def.name);

        if (oldCfm == null)
            throw new InvalidRequestException("Could not find column family definition to modify.");

        if (!oldCfm.isThriftCompatible())
            throw new InvalidRequestException("Cannot modify CQL3 table " + oldCfm.cfName + " as it may break the schema. You should use cqlsh to modify CQL3 tables instead.");

        CFMetaData cfm = CFMetaData.fromThriftForUpdate(cf_def, oldCfm);
        CFMetaData.validateCompactionOptions(cfm.compactionStrategyClass, cfm.compactionStrategyOptions);
        cfm.addDefaultIndexNames();

        if (!oldCfm.getTriggers().equals(cfm.getTriggers()))
            state().ensureIsSuper("Only superusers are allowed to add or remove triggers.");

        MigrationManager.announceColumnFamilyUpdate(cfm, true);
        return Schema.instance.getVersion().toString();
    }
    catch (RequestValidationException e)
    {
        throw ThriftConversion.toThrift(e);
    }
}
 
Example 3
Source File: CFPropDefs.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
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()));
}