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();
}
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);
}
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()));
}
Aggregations