Search in sources :

Example 11 with BlockBasedTableConfig

use of org.rocksdb.BlockBasedTableConfig in project flink by apache.

the class RocksDBResourceContainer method getColumnOptions.

/**
 * Gets the RocksDB {@link ColumnFamilyOptions} to be used for all RocksDB instances.
 */
public ColumnFamilyOptions getColumnOptions() {
    // initial options from common profile
    ColumnFamilyOptions opt = createBaseCommonColumnOptions();
    handlesToClose.add(opt);
    // load configurable options on top of pre-defined profile
    setColumnFamilyOptionsFromConfigurableOptions(opt, handlesToClose);
    // add user-defined options, if specified
    if (optionsFactory != null) {
        opt = optionsFactory.createColumnOptions(opt, handlesToClose);
    }
    // set necessary options for performance consideration with memory control
    if (sharedResources != null) {
        final RocksDBSharedResources rocksResources = sharedResources.getResourceHandle();
        final Cache blockCache = rocksResources.getCache();
        TableFormatConfig tableFormatConfig = opt.tableFormatConfig();
        BlockBasedTableConfig blockBasedTableConfig;
        if (tableFormatConfig == null) {
            blockBasedTableConfig = new BlockBasedTableConfig();
        } else {
            Preconditions.checkArgument(tableFormatConfig instanceof BlockBasedTableConfig, "We currently only support BlockBasedTableConfig When bounding total memory.");
            blockBasedTableConfig = (BlockBasedTableConfig) tableFormatConfig;
        }
        if (rocksResources.isUsingPartitionedIndexFilters() && overwriteFilterIfExist(blockBasedTableConfig)) {
            blockBasedTableConfig.setIndexType(IndexType.kTwoLevelIndexSearch);
            blockBasedTableConfig.setPartitionFilters(true);
            blockBasedTableConfig.setPinTopLevelIndexAndFilter(true);
        }
        blockBasedTableConfig.setBlockCache(blockCache);
        blockBasedTableConfig.setCacheIndexAndFilterBlocks(true);
        blockBasedTableConfig.setCacheIndexAndFilterBlocksWithHighPriority(true);
        blockBasedTableConfig.setPinL0FilterAndIndexBlocksInCache(true);
        opt.setTableFormatConfig(blockBasedTableConfig);
    }
    return opt;
}
Also used : ColumnFamilyOptions(org.rocksdb.ColumnFamilyOptions) TableFormatConfig(org.rocksdb.TableFormatConfig) BlockBasedTableConfig(org.rocksdb.BlockBasedTableConfig) Cache(org.rocksdb.Cache)

Example 12 with BlockBasedTableConfig

use of org.rocksdb.BlockBasedTableConfig in project flink by apache.

the class RocksDBResourceContainer method setColumnFamilyOptionsFromConfigurableOptions.

@SuppressWarnings("ConstantConditions")
private ColumnFamilyOptions setColumnFamilyOptionsFromConfigurableOptions(ColumnFamilyOptions currentOptions, Collection<AutoCloseable> handlesToClose) {
    currentOptions.setCompactionStyle(internalGetOption(RocksDBConfigurableOptions.COMPACTION_STYLE));
    currentOptions.setLevelCompactionDynamicLevelBytes(internalGetOption(RocksDBConfigurableOptions.USE_DYNAMIC_LEVEL_SIZE));
    currentOptions.setTargetFileSizeBase(internalGetOption(RocksDBConfigurableOptions.TARGET_FILE_SIZE_BASE).getBytes());
    currentOptions.setMaxBytesForLevelBase(internalGetOption(RocksDBConfigurableOptions.MAX_SIZE_LEVEL_BASE).getBytes());
    currentOptions.setWriteBufferSize(internalGetOption(RocksDBConfigurableOptions.WRITE_BUFFER_SIZE).getBytes());
    currentOptions.setMaxWriteBufferNumber(internalGetOption(RocksDBConfigurableOptions.MAX_WRITE_BUFFER_NUMBER));
    currentOptions.setMinWriteBufferNumberToMerge(internalGetOption(RocksDBConfigurableOptions.MIN_WRITE_BUFFER_NUMBER_TO_MERGE));
    TableFormatConfig tableFormatConfig = currentOptions.tableFormatConfig();
    BlockBasedTableConfig blockBasedTableConfig;
    if (tableFormatConfig == null) {
        blockBasedTableConfig = new BlockBasedTableConfig();
    } else {
        if (tableFormatConfig instanceof PlainTableConfig) {
            // column-family options
            return currentOptions;
        } else {
            blockBasedTableConfig = (BlockBasedTableConfig) tableFormatConfig;
        }
    }
    blockBasedTableConfig.setBlockSize(internalGetOption(RocksDBConfigurableOptions.BLOCK_SIZE).getBytes());
    blockBasedTableConfig.setMetadataBlockSize(internalGetOption(RocksDBConfigurableOptions.METADATA_BLOCK_SIZE).getBytes());
    blockBasedTableConfig.setBlockCacheSize(internalGetOption(RocksDBConfigurableOptions.BLOCK_CACHE_SIZE).getBytes());
    if (internalGetOption(RocksDBConfigurableOptions.USE_BLOOM_FILTER)) {
        final double bitsPerKey = internalGetOption(RocksDBConfigurableOptions.BLOOM_FILTER_BITS_PER_KEY);
        final boolean blockBasedMode = internalGetOption(RocksDBConfigurableOptions.BLOOM_FILTER_BLOCK_BASED_MODE);
        BloomFilter bloomFilter = new BloomFilter(bitsPerKey, blockBasedMode);
        handlesToClose.add(bloomFilter);
        blockBasedTableConfig.setFilterPolicy(bloomFilter);
    }
    return currentOptions.setTableFormatConfig(blockBasedTableConfig);
}
Also used : TableFormatConfig(org.rocksdb.TableFormatConfig) BlockBasedTableConfig(org.rocksdb.BlockBasedTableConfig) PlainTableConfig(org.rocksdb.PlainTableConfig) BloomFilter(org.rocksdb.BloomFilter)

Example 13 with BlockBasedTableConfig

use of org.rocksdb.BlockBasedTableConfig in project flink by apache.

the class RocksDBResourceContainerTest method getBlockCache.

private Cache getBlockCache(ColumnFamilyOptions columnOptions) {
    BlockBasedTableConfig blockBasedTableConfig = null;
    try {
        blockBasedTableConfig = (BlockBasedTableConfig) columnOptions.tableFormatConfig();
    } catch (ClassCastException e) {
        fail("Table config got from ColumnFamilyOptions is not BlockBasedTableConfig");
    }
    Field cacheField = null;
    try {
        cacheField = BlockBasedTableConfig.class.getDeclaredField("blockCache");
    } catch (NoSuchFieldException e) {
        fail("blockCache is not defined");
    }
    cacheField.setAccessible(true);
    try {
        return (Cache) cacheField.get(blockBasedTableConfig);
    } catch (IllegalAccessException e) {
        fail("Cannot access blockCache field.");
        return null;
    }
}
Also used : Field(java.lang.reflect.Field) BlockBasedTableConfig(org.rocksdb.BlockBasedTableConfig) LRUCache(org.rocksdb.LRUCache) Cache(org.rocksdb.Cache)

Aggregations

BlockBasedTableConfig (org.rocksdb.BlockBasedTableConfig)13 Options (org.rocksdb.Options)5 TableFormatConfig (org.rocksdb.TableFormatConfig)5 Cache (org.rocksdb.Cache)4 LRUCache (org.rocksdb.LRUCache)4 WriteOptions (org.rocksdb.WriteOptions)4 IOException (java.io.IOException)3 BloomFilter (org.rocksdb.BloomFilter)3 ColumnFamilyOptions (org.rocksdb.ColumnFamilyOptions)3 FlushOptions (org.rocksdb.FlushOptions)3 File (java.io.File)2 ProcessorStateException (org.apache.kafka.streams.errors.ProcessorStateException)2 RocksDBConfigSetter (org.apache.kafka.streams.state.RocksDBConfigSetter)2 Test (org.junit.Test)2 CompressionType (org.rocksdb.CompressionType)2 DBOptions (org.rocksdb.DBOptions)2 PlainTableConfig (org.rocksdb.PlainTableConfig)2 Field (java.lang.reflect.Field)1 Collection (java.util.Collection)1 List (java.util.List)1