Search in sources :

Example 26 with TableMetadata

use of com.palantir.atlasdb.table.description.TableMetadata in project atlasdb by palantir.

the class ColumnFamilyDefinitions method getCfDef.

/**
 *  Provides a default column family definition given raw metadata, which is generally obtained from the _metadata
 *  table.
 *
 *  Warning to developers: you must update CKVS.isMatchingCf if you update this method
 */
@SuppressWarnings("CyclomaticComplexity")
static CfDef getCfDef(String keyspace, TableReference tableRef, int gcGraceSeconds, byte[] rawMetadata) {
    Map<String, String> compressionOptions = Maps.newHashMap();
    CfDef cf = getStandardCfDef(keyspace, AbstractKeyValueService.internalTableName(tableRef));
    boolean negativeLookups = false;
    double falsePositiveChance = CassandraConstants.DEFAULT_LEVELED_COMPACTION_BLOOM_FILTER_FP_CHANCE;
    int explicitCompressionBlockSizeKb = 0;
    boolean appendHeavyAndReadLight = false;
    TableMetadataPersistence.CachePriority cachePriority = TableMetadataPersistence.CachePriority.WARM;
    if (!CassandraKeyValueServices.isEmptyOrInvalidMetadata(rawMetadata)) {
        TableMetadata tableMetadata = TableMetadata.BYTES_HYDRATOR.hydrateFromBytes(rawMetadata);
        negativeLookups = tableMetadata.hasNegativeLookups();
        explicitCompressionBlockSizeKb = tableMetadata.getExplicitCompressionBlockSizeKB();
        appendHeavyAndReadLight = tableMetadata.isAppendHeavyAndReadLight();
        cachePriority = tableMetadata.getCachePriority();
    }
    if (explicitCompressionBlockSizeKb != 0) {
        compressionOptions.put(CassandraConstants.CFDEF_COMPRESSION_TYPE_KEY, CassandraConstants.DEFAULT_COMPRESSION_TYPE);
        compressionOptions.put(CassandraConstants.CFDEF_COMPRESSION_CHUNK_LENGTH_KEY, Integer.toString(explicitCompressionBlockSizeKb));
    } else {
        // We don't really need compression here nor anticipate it will garner us any gains
        // (which is why we're doing such a small chunk size), but this is how we can get "free" CRC checking.
        compressionOptions.put(CassandraConstants.CFDEF_COMPRESSION_TYPE_KEY, CassandraConstants.DEFAULT_COMPRESSION_TYPE);
        compressionOptions.put(CassandraConstants.CFDEF_COMPRESSION_CHUNK_LENGTH_KEY, Integer.toString(AtlasDbConstants.MINIMUM_COMPRESSION_BLOCK_SIZE_KB));
    }
    if (negativeLookups) {
        falsePositiveChance = CassandraConstants.NEGATIVE_LOOKUPS_BLOOM_FILTER_FP_CHANCE;
    }
    if (appendHeavyAndReadLight) {
        cf.setCompaction_strategy(CassandraConstants.SIZE_TIERED_COMPACTION_STRATEGY);
        // clear out the now nonsensical "keep it at 80MB per sstable" option from LCS
        cf.setCompaction_strategy_optionsIsSet(false);
        if (!negativeLookups) {
            falsePositiveChance = CassandraConstants.DEFAULT_SIZE_TIERED_COMPACTION_BLOOM_FILTER_FP_CHANCE;
        } else {
            falsePositiveChance = CassandraConstants.NEGATIVE_LOOKUPS_SIZE_TIERED_BLOOM_FILTER_FP_CHANCE;
        }
    }
    switch(cachePriority) {
        case COLDEST:
            break;
        case COLD:
            break;
        case WARM:
            break;
        case HOT:
            break;
        case HOTTEST:
            cf.setPopulate_io_cache_on_flushIsSet(true);
            break;
        default:
            throw new PalantirRuntimeException("Unknown cache priority: " + cachePriority);
    }
    cf.setGc_grace_seconds(gcGraceSeconds);
    cf.setBloom_filter_fp_chance(falsePositiveChance);
    cf.setCompression_options(compressionOptions);
    return cf;
}
Also used : TableMetadata(com.palantir.atlasdb.table.description.TableMetadata) PalantirRuntimeException(com.palantir.common.exception.PalantirRuntimeException) TableMetadataPersistence(com.palantir.atlasdb.protos.generated.TableMetadataPersistence) CfDef(org.apache.cassandra.thrift.CfDef)

Aggregations

TableMetadata (com.palantir.atlasdb.table.description.TableMetadata)26 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 ColumnMetadataDescription (com.palantir.atlasdb.table.description.ColumnMetadataDescription)6 NameMetadataDescription (com.palantir.atlasdb.table.description.NameMetadataDescription)5 Test (org.junit.Test)5 Cell (com.palantir.atlasdb.keyvalue.api.Cell)4 BoundStatement (com.datastax.driver.core.BoundStatement)2 TableCell (com.palantir.atlasdb.api.TableCell)2 NamedColumnDescription (com.palantir.atlasdb.table.description.NamedColumnDescription)2 ResultSet (com.datastax.driver.core.ResultSet)1 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 TableCellVal (com.palantir.atlasdb.api.TableCellVal)1 TableRange (com.palantir.atlasdb.api.TableRange)1 TableRowResult (com.palantir.atlasdb.api.TableRowResult)1 TableRowSelection (com.palantir.atlasdb.api.TableRowSelection)1 RowResult (com.palantir.atlasdb.keyvalue.api.RowResult)1 TableReference (com.palantir.atlasdb.keyvalue.api.TableReference)1 TableMetadataPersistence (com.palantir.atlasdb.protos.generated.TableMetadataPersistence)1 DynamicColumnDescription (com.palantir.atlasdb.table.description.DynamicColumnDescription)1 TableDefinition (com.palantir.atlasdb.table.description.TableDefinition)1