Search in sources :

Example 1 with CompressionParameters

use of org.apache.cassandra.io.compress.CompressionParameters in project titan by thinkaurelius.

the class CassandraEmbeddedStoreManager method ensureColumnFamilyExists.

private void ensureColumnFamilyExists(String keyspaceName, String columnfamilyName, AbstractType<?> comparator) throws BackendException {
    if (null != Schema.instance.getCFMetaData(keyspaceName, columnfamilyName))
        return;
    // Column Family not found; create it
    CFMetaData cfm = new CFMetaData(keyspaceName, columnfamilyName, ColumnFamilyType.Standard, CellNames.fromAbstractType(comparator, true));
    // Hard-coded caching settings
    if (columnfamilyName.startsWith(Backend.EDGESTORE_NAME)) {
        cfm.caching(CachingOptions.KEYS_ONLY);
    } else if (columnfamilyName.startsWith(Backend.INDEXSTORE_NAME)) {
        cfm.caching(CachingOptions.ROWS_ONLY);
    }
    // Configure sstable compression
    final CompressionParameters cp;
    if (compressionEnabled) {
        try {
            cp = new CompressionParameters(compressionClass, compressionChunkSizeKB * 1024, Collections.<String, String>emptyMap());
            // CompressionParameters doesn't override toString(), so be explicit
            log.debug("Creating CF {}: setting {}={} and {}={} on {}", new Object[] { columnfamilyName, CompressionParameters.SSTABLE_COMPRESSION, compressionClass, CompressionParameters.CHUNK_LENGTH_KB, compressionChunkSizeKB, cp });
        } catch (ConfigurationException ce) {
            throw new PermanentBackendException(ce);
        }
    } else {
        cp = new CompressionParameters(null);
        log.debug("Creating CF {}: setting {} to null to disable compression", columnfamilyName, CompressionParameters.SSTABLE_COMPRESSION);
    }
    cfm.compressionParameters(cp);
    try {
        cfm.addDefaultIndexNames();
    } catch (ConfigurationException e) {
        throw new PermanentBackendException("Failed to create column family metadata for " + keyspaceName + ":" + columnfamilyName, e);
    }
    try {
        MigrationManager.announceNewColumnFamily(cfm);
        log.info("Created CF {} in KS {}", columnfamilyName, keyspaceName);
    } catch (ConfigurationException e) {
        throw new PermanentBackendException("Failed to create column family " + keyspaceName + ":" + columnfamilyName, e);
    }
    /*
         * I'm chasing a nondetermistic exception that appears only rarely on my
         * machine when executing the embedded cassandra tests. If these dummy
         * reads ever actually fail and dump a log message, it could help debug
         * the root cause.
         *
         *   java.lang.RuntimeException: java.lang.IllegalArgumentException: Unknown table/cf pair (InternalCassandraEmbeddedKeyColumnValueTest.testStore1)
         *          at org.apache.cassandra.service.StorageProxy$DroppableRunnable.run(StorageProxy.java:1582)
         *           at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
         *           at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
         *           at java.lang.Thread.run(Thread.java:744)
         *   Caused by: java.lang.IllegalArgumentException: Unknown table/cf pair (InternalCassandraEmbeddedKeyColumnValueTest.testStore1)
         *           at org.apache.cassandra.db.Table.getColumnFamilyStore(Table.java:166)
         *           at org.apache.cassandra.db.Table.getRow(Table.java:354)
         *           at org.apache.cassandra.db.SliceFromReadCommand.getRow(SliceFromReadCommand.java:70)
         *           at org.apache.cassandra.service.StorageProxy$LocalReadRunnable.runMayThrow(StorageProxy.java:1052)
         *           at org.apache.cassandra.service.StorageProxy$DroppableRunnable.run(StorageProxy.java:1578)
         *           ... 3 more
         */
    retryDummyRead(keyspaceName, columnfamilyName);
}
Also used : ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) CompressionParameters(org.apache.cassandra.io.compress.CompressionParameters) CFMetaData(org.apache.cassandra.config.CFMetaData)

Example 2 with CompressionParameters

use of org.apache.cassandra.io.compress.CompressionParameters in project eiger by wlloyd.

the class CFMetaData method init.

private void init() {
    // Set a bunch of defaults
    readRepairChance = DEFAULT_READ_REPAIR_CHANCE;
    replicateOnWrite = DEFAULT_REPLICATE_ON_WRITE;
    gcGraceSeconds = DEFAULT_GC_GRACE_SECONDS;
    minCompactionThreshold = DEFAULT_MIN_COMPACTION_THRESHOLD;
    maxCompactionThreshold = DEFAULT_MAX_COMPACTION_THRESHOLD;
    mergeShardsChance = DEFAULT_MERGE_SHARDS_CHANCE;
    // Defaults strange or simple enough to not need a DEFAULT_T for
    defaultValidator = BytesType.instance;
    keyValidator = BytesType.instance;
    comment = "";
    // This qualifies as a 'strange default'.
    keyAlias = null;
    column_metadata = new HashMap<ByteBuffer, ColumnDefinition>();
    try {
        compactionStrategyClass = createCompactionStrategy(DEFAULT_COMPACTION_STRATEGY_CLASS);
    } catch (ConfigurationException e) {
        throw new AssertionError(e);
    }
    compactionStrategyOptions = new HashMap<String, String>();
    compressionParameters = new CompressionParameters(null);
}
Also used : CompressionParameters(org.apache.cassandra.io.compress.CompressionParameters) ByteBuffer(java.nio.ByteBuffer)

Example 3 with CompressionParameters

use of org.apache.cassandra.io.compress.CompressionParameters in project eiger by wlloyd.

the class CFMetaData method fromThrift.

public static CFMetaData fromThrift(org.apache.cassandra.thrift.CfDef cf_def) throws InvalidRequestException, ConfigurationException {
    ColumnFamilyType cfType = ColumnFamilyType.create(cf_def.column_type);
    if (cfType == null) {
        throw new InvalidRequestException("Invalid column type " + cf_def.column_type);
    }
    applyImplicitDefaults(cf_def);
    CFMetaData newCFMD = new CFMetaData(cf_def.keyspace, cf_def.name, cfType, TypeParser.parse(cf_def.comparator_type), cf_def.subcomparator_type == null ? null : TypeParser.parse(cf_def.subcomparator_type), cf_def.isSetId() ? cf_def.id : Schema.instance.nextCFId());
    if (cf_def.isSetGc_grace_seconds()) {
        newCFMD.gcGraceSeconds(cf_def.gc_grace_seconds);
    }
    if (cf_def.isSetMin_compaction_threshold()) {
        newCFMD.minCompactionThreshold(cf_def.min_compaction_threshold);
    }
    if (cf_def.isSetMax_compaction_threshold()) {
        newCFMD.maxCompactionThreshold(cf_def.max_compaction_threshold);
    }
    if (cf_def.isSetMerge_shards_chance()) {
        newCFMD.mergeShardsChance(cf_def.merge_shards_chance);
    }
    if (cf_def.isSetKey_alias()) {
        newCFMD.keyAlias(cf_def.key_alias);
    }
    if (cf_def.isSetKey_validation_class()) {
        newCFMD.keyValidator(TypeParser.parse(cf_def.key_validation_class));
    }
    if (cf_def.isSetCompaction_strategy())
        newCFMD.compactionStrategyClass = createCompactionStrategy(cf_def.compaction_strategy);
    if (cf_def.isSetCompaction_strategy_options())
        newCFMD.compactionStrategyOptions(new HashMap<String, String>(cf_def.compaction_strategy_options));
    if (cf_def.isSetBloom_filter_fp_chance())
        newCFMD.bloomFilterFpChance(cf_def.bloom_filter_fp_chance);
    if (cf_def.isSetCaching())
        newCFMD.caching(Caching.fromString(cf_def.caching));
    CompressionParameters cp = CompressionParameters.create(cf_def.compression_options);
    return newCFMD.comment(cf_def.comment).readRepairChance(cf_def.read_repair_chance).replicateOnWrite(cf_def.replicate_on_write).defaultValidator(TypeParser.parse(cf_def.default_validation_class)).keyValidator(TypeParser.parse(cf_def.key_validation_class)).columnMetadata(ColumnDefinition.fromThrift(cf_def.column_metadata)).compressionParameters(cp).validate();
}
Also used : CompressionParameters(org.apache.cassandra.io.compress.CompressionParameters) InvalidRequestException(org.apache.cassandra.thrift.InvalidRequestException)

Example 4 with CompressionParameters

use of org.apache.cassandra.io.compress.CompressionParameters in project eiger by wlloyd.

the class CFMetaData method fromAvro.

public static CFMetaData fromAvro(org.apache.cassandra.db.migration.avro.CfDef cf) {
    AbstractType comparator;
    AbstractType subcolumnComparator = null;
    AbstractType validator;
    AbstractType keyValidator;
    try {
        comparator = TypeParser.parse(cf.comparator_type.toString());
        if (cf.subcomparator_type != null)
            subcolumnComparator = TypeParser.parse(cf.subcomparator_type);
        validator = TypeParser.parse(cf.default_validation_class);
        keyValidator = TypeParser.parse(cf.key_validation_class);
    } catch (Exception ex) {
        throw new RuntimeException("Could not inflate CFMetaData for " + cf, ex);
    }
    Map<ByteBuffer, ColumnDefinition> column_metadata = new TreeMap<ByteBuffer, ColumnDefinition>(BytesType.instance);
    for (ColumnDef aColumn_metadata : cf.column_metadata) {
        ColumnDefinition cd = ColumnDefinition.fromAvro(aColumn_metadata);
        if (cd.getIndexType() != null && cd.getIndexName() == null)
            cd.setIndexName(getDefaultIndexName(cf.name.toString(), comparator, cd.name));
        column_metadata.put(cd.name, cd);
    }
    CFMetaData newCFMD = new CFMetaData(cf.keyspace.toString(), cf.name.toString(), ColumnFamilyType.create(cf.column_type.toString()), comparator, subcolumnComparator, cf.id);
    // Isn't AVRO supposed to handle stuff like this?
    if (cf.min_compaction_threshold != null) {
        newCFMD.minCompactionThreshold(cf.min_compaction_threshold);
    }
    if (cf.max_compaction_threshold != null) {
        newCFMD.maxCompactionThreshold(cf.max_compaction_threshold);
    }
    if (cf.merge_shards_chance != null) {
        newCFMD.mergeShardsChance(cf.merge_shards_chance);
    }
    if (cf.key_alias != null) {
        newCFMD.keyAlias(cf.key_alias);
    }
    if (cf.compaction_strategy != null) {
        try {
            newCFMD.compactionStrategyClass = createCompactionStrategy(cf.compaction_strategy.toString());
        } catch (ConfigurationException e) {
            throw new RuntimeException(e);
        }
    }
    if (cf.compaction_strategy_options != null) {
        for (Map.Entry<CharSequence, CharSequence> e : cf.compaction_strategy_options.entrySet()) newCFMD.compactionStrategyOptions.put(e.getKey().toString(), e.getValue().toString());
    }
    CompressionParameters cp;
    try {
        cp = CompressionParameters.create(cf.compression_options);
    } catch (ConfigurationException e) {
        throw new RuntimeException(e);
    }
    Caching caching;
    try {
        caching = cf.caching == null ? Caching.KEYS_ONLY : Caching.fromString(cf.caching.toString());
    } catch (ConfigurationException e) {
        throw new RuntimeException(e);
    }
    return newCFMD.comment(cf.comment.toString()).readRepairChance(cf.read_repair_chance).replicateOnWrite(cf.replicate_on_write).gcGraceSeconds(cf.gc_grace_seconds).defaultValidator(validator).keyValidator(keyValidator).columnMetadata(column_metadata).compressionParameters(cp).bloomFilterFpChance(cf.bloom_filter_fp_chance).caching(caching);
}
Also used : ColumnDef(org.apache.cassandra.db.migration.avro.ColumnDef) ByteBuffer(java.nio.ByteBuffer) InvalidRequestException(org.apache.cassandra.thrift.InvalidRequestException) InvocationTargetException(java.lang.reflect.InvocationTargetException) CompressionParameters(org.apache.cassandra.io.compress.CompressionParameters)

Example 5 with CompressionParameters

use of org.apache.cassandra.io.compress.CompressionParameters in project titan by thinkaurelius.

the class CassandraEmbeddedStoreManager method ensureColumnFamilyExists.

private void ensureColumnFamilyExists(String keyspaceName, String columnfamilyName, AbstractType comparator) throws StorageException {
    if (null != Schema.instance.getCFMetaData(keyspaceName, columnfamilyName))
        return;
    // Column Family not found; create it
    CFMetaData cfm = new CFMetaData(keyspaceName, columnfamilyName, ColumnFamilyType.Standard, comparator, null);
    // Hard-coded caching settings
    if (columnfamilyName.startsWith(Backend.EDGESTORE_NAME)) {
        cfm.caching(Caching.KEYS_ONLY);
    } else if (columnfamilyName.startsWith(Backend.VERTEXINDEX_STORE_NAME)) {
        cfm.caching(Caching.ROWS_ONLY);
    }
    // Configure sstable compression
    final CompressionParameters cp;
    if (compressionEnabled) {
        try {
            cp = new CompressionParameters(compressionClass, compressionChunkSizeKB * 1024, Collections.<String, String>emptyMap());
            // CompressionParameters doesn't override toString(), so be explicit
            log.debug("Creating CF {}: setting {}={} and {}={} on {}", new Object[] { columnfamilyName, CompressionParameters.SSTABLE_COMPRESSION, compressionClass, CompressionParameters.CHUNK_LENGTH_KB, compressionChunkSizeKB, cp });
        } catch (ConfigurationException ce) {
            throw new PermanentStorageException(ce);
        }
    } else {
        cp = new CompressionParameters(null);
        log.debug("Creating CF {}: setting {} to null to disable compression", columnfamilyName, CompressionParameters.SSTABLE_COMPRESSION);
    }
    cfm.compressionParameters(cp);
    try {
        cfm.addDefaultIndexNames();
    } catch (ConfigurationException e) {
        throw new PermanentStorageException("Failed to create column family metadata for " + keyspaceName + ":" + columnfamilyName, e);
    }
    try {
        MigrationManager.announceNewColumnFamily(cfm);
    } catch (ConfigurationException e) {
        throw new PermanentStorageException("Failed to create column family " + keyspaceName + ":" + columnfamilyName, e);
    }
}
Also used : ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) CompressionParameters(org.apache.cassandra.io.compress.CompressionParameters) CFMetaData(org.apache.cassandra.config.CFMetaData)

Aggregations

CompressionParameters (org.apache.cassandra.io.compress.CompressionParameters)6 CFMetaData (org.apache.cassandra.config.CFMetaData)3 ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)3 ByteBuffer (java.nio.ByteBuffer)2 InvalidRequestException (org.apache.cassandra.thrift.InvalidRequestException)2 PermanentStorageException (com.thinkaurelius.titan.diskstorage.PermanentStorageException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ColumnDef (org.apache.cassandra.db.migration.avro.ColumnDef)1