Search in sources :

Example 6 with CompressionParameters

use of org.apache.cassandra.io.compress.CompressionParameters in project janusgraph by JanusGraph.

the class CassandraEmbeddedStoreManager method ensureColumnFamilyExists.

private void ensureColumnFamilyExists(String keyspaceName, String columnFamilyName) throws BackendException {
    if (null != Schema.instance.getCFMetaData(keyspaceName, columnFamilyName))
        return;
    // Column Family not found; create it
    final CFMetaData cfm = new CFMetaData(keyspaceName, columnFamilyName, ColumnFamilyType.Standard, CellNames.fromAbstractType(BytesType.instance, true));
    try {
        if (storageConfig.has(COMPACTION_STRATEGY)) {
            cfm.compactionStrategyClass(CFMetaData.createCompactionStrategy(storageConfig.get(COMPACTION_STRATEGY)));
        }
        if (!compactionOptions.isEmpty()) {
            cfm.compactionStrategyOptions(compactionOptions);
        }
    } catch (ConfigurationException e) {
        throw new PermanentBackendException("Failed to create column family metadata for " + keyspaceName + ":" + columnFamilyName, e);
    }
    // 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.emptyMap());
            // CompressionParameters doesn't override toString(), so be explicit
            log.debug("Creating CF {}: setting {}={} and {}={} on {}", 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 nondeterministic 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)

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