Search in sources :

Example 16 with Options

use of org.rocksdb.Options in project jstorm by alibaba.

the class RocksDbUnitTest method main.

public static void main(String[] args) {
    Map conf = JStormHelper.LoadConf(args[0]);
    putNum = JStormUtils.parseInt(conf.get("put.number"), 100);
    isFlush = JStormUtils.parseBoolean(conf.get("is.flush"), true);
    isCheckpoint = JStormUtils.parseBoolean(conf.get("is.checkpoint"), true);
    sleepTime = JStormUtils.parseInt(conf.get("sleep.time"), 5000);
    compactionInterval = JStormUtils.parseInt(conf.get("compaction.interval"), 30000);
    flushInterval = JStormUtils.parseInt(conf.get("flush.interval"), 3000);
    isCompaction = JStormUtils.parseBoolean(conf.get("is.compaction"), true);
    fileSizeBase = JStormUtils.parseLong(conf.get("file.size.base"), 10 * SizeUnit.KB);
    levelNum = JStormUtils.parseInt(conf.get("db.level.num"), 1);
    compactionTriggerNum = JStormUtils.parseInt(conf.get("db.compaction.trigger.num"), 4);
    LOG.info("Conf={}", conf);
    RocksDB db;
    File file = new File(cpPath);
    file.mkdirs();
    List<ColumnFamilyHandle> columnFamilyHandles = new ArrayList<>();
    try {
        Options options = new Options();
        options.setCreateMissingColumnFamilies(true);
        options.setCreateIfMissing(true);
        options.setTargetFileSizeBase(fileSizeBase);
        options.setMaxBackgroundFlushes(2);
        options.setMaxBackgroundCompactions(2);
        options.setCompactionStyle(CompactionStyle.LEVEL);
        options.setNumLevels(levelNum);
        options.setLevelZeroFileNumCompactionTrigger(compactionTriggerNum);
        DBOptions dbOptions = new DBOptions();
        dbOptions.setCreateMissingColumnFamilies(true);
        dbOptions.setCreateIfMissing(true);
        dbOptions.setMaxBackgroundFlushes(2);
        dbOptions.setMaxBackgroundCompactions(2);
        ColumnFamilyOptions familyOptions = new ColumnFamilyOptions();
        familyOptions.setTargetFileSizeBase(fileSizeBase);
        familyOptions.setCompactionStyle(CompactionStyle.LEVEL);
        familyOptions.setNumLevels(levelNum);
        familyOptions.setLevelZeroFileNumCompactionTrigger(compactionTriggerNum);
        List<byte[]> families = RocksDB.listColumnFamilies(options, dbPath);
        List<ColumnFamilyDescriptor> columnFamilyDescriptors = new ArrayList<>();
        if (families != null) {
            for (byte[] bytes : families) {
                columnFamilyDescriptors.add(new ColumnFamilyDescriptor(bytes, familyOptions));
                LOG.info("Load colum family of {}", new String(bytes));
            }
        }
        if (columnFamilyDescriptors.size() > 0) {
            db = RocksDB.open(dbOptions, dbPath, columnFamilyDescriptors, columnFamilyHandles);
        } else {
            db = RocksDB.open(options, dbPath);
        }
    } catch (RocksDBException e) {
        LOG.error("Failed to open db", e);
        return;
    }
    rocksDbTest(db, columnFamilyHandles);
    db.close();
}
Also used : FlushOptions(org.rocksdb.FlushOptions) ColumnFamilyOptions(org.rocksdb.ColumnFamilyOptions) DBOptions(org.rocksdb.DBOptions) Options(org.rocksdb.Options) RocksDBException(org.rocksdb.RocksDBException) RocksDB(org.rocksdb.RocksDB) ArrayList(java.util.ArrayList) ColumnFamilyDescriptor(org.rocksdb.ColumnFamilyDescriptor) ColumnFamilyHandle(org.rocksdb.ColumnFamilyHandle) ColumnFamilyOptions(org.rocksdb.ColumnFamilyOptions) DBOptions(org.rocksdb.DBOptions) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) File(java.io.File)

Example 17 with Options

use of org.rocksdb.Options in project alluxio by Alluxio.

the class RocksPageStore method open.

/**
 * @param pageStoreOptions options for the rocks page store
 * @return a new instance of {@link PageStore} backed by RocksDB
 * @throws IOException if I/O error happens
 */
public static RocksPageStore open(RocksPageStoreOptions pageStoreOptions) throws IOException {
    Preconditions.checkArgument(pageStoreOptions.getMaxPageSize() > 0);
    RocksDB.loadLibrary();
    // The RocksObject will be closed together with the RocksPageStore
    Options rocksOptions = new Options().setCreateIfMissing(true).setWriteBufferSize(pageStoreOptions.getWriteBufferSize()).setCompressionType(pageStoreOptions.getCompressionType());
    RocksDB db = null;
    try {
        // TODO(maobaolong): rocksdb support only one root for now.
        db = RocksDB.open(rocksOptions, pageStoreOptions.getRootDirs().get(0).toString());
        byte[] confData = db.get(CONF_KEY);
        Cache.PRocksPageStoreOptions pOptions = pageStoreOptions.toProto();
        if (confData != null) {
            Cache.PRocksPageStoreOptions persistedOptions = Cache.PRocksPageStoreOptions.parseFrom(confData);
            if (!persistedOptions.equals(pOptions)) {
                db.close();
                throw new IOException("Inconsistent configuration for RocksPageStore");
            }
        }
        db.put(CONF_KEY, pOptions.toByteArray());
    } catch (RocksDBException e) {
        if (db != null) {
            db.close();
        }
        rocksOptions.close();
        throw new IOException("Couldn't open rocksDB database", e);
    }
    return new RocksPageStore(pageStoreOptions, db, rocksOptions);
}
Also used : Options(org.rocksdb.Options) RocksDBException(org.rocksdb.RocksDBException) RocksDB(org.rocksdb.RocksDB) IOException(java.io.IOException) Cache(alluxio.proto.client.Cache)

Example 18 with Options

use of org.rocksdb.Options in project beam by apache.

the class SamzaTimerInternalsFactoryTest method createStore.

private KeyValueStore<ByteArray, StateValue<?>> createStore() {
    final Options options = new Options();
    options.setCreateIfMissing(true);
    RocksDbKeyValueStore rocksStore = new RocksDbKeyValueStore(temporaryFolder.getRoot(), options, new MapConfig(), false, "beamStore", new WriteOptions(), new FlushOptions(), new KeyValueStoreMetrics("beamStore", new MetricsRegistryMap()));
    return new SerializedKeyValueStore<>(rocksStore, new ByteArraySerdeFactory.ByteArraySerde(), new StateValueSerdeFactory.StateValueSerde(), new SerializedKeyValueStoreMetrics("beamStore", new MetricsRegistryMap()));
}
Also used : FlushOptions(org.rocksdb.FlushOptions) WriteOptions(org.rocksdb.WriteOptions) SamzaPipelineOptions(org.apache.beam.runners.samza.SamzaPipelineOptions) Options(org.rocksdb.Options) SerializedKeyValueStoreMetrics(org.apache.samza.storage.kv.SerializedKeyValueStoreMetrics) KeyValueStoreMetrics(org.apache.samza.storage.kv.KeyValueStoreMetrics) ByteArraySerdeFactory(org.apache.beam.runners.samza.runtime.SamzaStoreStateInternals.ByteArraySerdeFactory) FlushOptions(org.rocksdb.FlushOptions) SerializedKeyValueStoreMetrics(org.apache.samza.storage.kv.SerializedKeyValueStoreMetrics) WriteOptions(org.rocksdb.WriteOptions) SerializedKeyValueStore(org.apache.samza.storage.kv.SerializedKeyValueStore) MapConfig(org.apache.samza.config.MapConfig) StateValueSerdeFactory(org.apache.beam.runners.samza.runtime.SamzaStoreStateInternals.StateValueSerdeFactory) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap) RocksDbKeyValueStore(org.apache.samza.storage.kv.RocksDbKeyValueStore)

Aggregations

Options (org.rocksdb.Options)18 WriteOptions (org.rocksdb.WriteOptions)13 File (java.io.File)9 FlushOptions (org.rocksdb.FlushOptions)8 RocksDBException (org.rocksdb.RocksDBException)6 BlockBasedTableConfig (org.rocksdb.BlockBasedTableConfig)5 MapConfig (org.apache.samza.config.MapConfig)4 MetricsRegistryMap (org.apache.samza.metrics.MetricsRegistryMap)4 RocksDB (org.rocksdb.RocksDB)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Config (org.apache.samza.config.Config)3 ColumnFamilyOptions (org.rocksdb.ColumnFamilyOptions)3 DBOptions (org.rocksdb.DBOptions)3 ReadOptions (org.rocksdb.ReadOptions)3 RocksDbOptionsFactory (com.alibaba.jstorm.cache.rocksdb.RocksDbOptionsFactory)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 RocksDBConfigSetter (org.apache.kafka.streams.state.RocksDBConfigSetter)2 Test (org.junit.Test)2 ColumnFamilyDescriptor (org.rocksdb.ColumnFamilyDescriptor)2