use of org.rocksdb.DBOptions in project voldemort by voldemort.
the class RocksDbStorageConfiguration method getStore.
@Override
public StorageEngine<ByteArray, byte[], byte[]> getStore(StoreDefinition storeDef, RoutingStrategy strategy) {
String storeName = storeDef.getName();
if (!stores.containsKey(storeName)) {
String dataDir = this.voldemortconfig.getRdbDataDirectory() + "/" + storeName;
new File(dataDir).mkdirs();
Properties dbProperties = parseProperties(VoldemortConfig.ROCKSDB_DB_OPTIONS);
DBOptions dbOptions = (dbProperties.size() > 0) ? DBOptions.getDBOptionsFromProps(dbProperties) : new DBOptions();
if (dbOptions == null) {
throw new StorageInitializationException("Unable to parse Data Base Options.");
}
dbOptions.setCreateIfMissing(true);
dbOptions.setCreateMissingColumnFamilies(true);
dbOptions.createStatistics();
Properties cfProperties = parseProperties(VoldemortConfig.ROCKSDB_CF_OPTIONS);
if (this.voldemortconfig.getRocksdbPrefixKeysWithPartitionId()) {
cfProperties.setProperty("prefix_extractor", "fixed:" + StoreBinaryFormat.PARTITIONID_PREFIX_SIZE);
}
ColumnFamilyOptions cfOptions = (cfProperties.size() > 0) ? ColumnFamilyOptions.getColumnFamilyOptionsFromProps(cfProperties) : new ColumnFamilyOptions();
if (cfOptions == null) {
throw new StorageInitializationException("Unable to parse Column Family Options.");
}
// Create a non default Column Family tp hold the store data.
List<ColumnFamilyDescriptor> descriptors = new ArrayList<ColumnFamilyDescriptor>();
descriptors.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY, cfOptions));
descriptors.add(new ColumnFamilyDescriptor(storeName.getBytes(), cfOptions));
List<ColumnFamilyHandle> handles = new ArrayList<ColumnFamilyHandle>();
try {
RocksDB rdbStore = RocksDB.open(dbOptions, dataDir, descriptors, handles);
// Dispose of the default Column Family immediately. We don't use it and if it has not been disposed
// by the time the DB is closed then the RocksDB code can terminate abnormally (if the RocksDB code is
// built with assertions enabled). The handle will go out of scope on its own and the Java finalizer
// will (eventually) do this for us, but, that is not fast enough for the unit tests.
handles.get(0).dispose();
ColumnFamilyHandle storeHandle = handles.get(1);
RocksDbStorageEngine rdbStorageEngine;
if (this.voldemortconfig.getRocksdbPrefixKeysWithPartitionId()) {
rdbStorageEngine = new PartitionPrefixedRocksDbStorageEngine(storeName, rdbStore, storeHandle, cfOptions, lockStripes, strategy, voldemortconfig.isRocksdbEnableReadLocks());
} else {
rdbStorageEngine = new RocksDbStorageEngine(storeName, rdbStore, storeHandle, cfOptions, lockStripes, voldemortconfig.isRocksdbEnableReadLocks());
}
stores.put(storeName, rdbStorageEngine);
} catch (Exception e) {
throw new StorageInitializationException(e);
}
}
return stores.get(storeName);
}
use of org.rocksdb.DBOptions in project flink by apache.
the class RocksDBStateBackendConfigTest method testPredefinedOptions.
// ------------------------------------------------------------------------
// RocksDB Options
// ------------------------------------------------------------------------
@Test
public void testPredefinedOptions() throws Exception {
String checkpointPath = tempFolder.newFolder().toURI().toString();
RocksDBStateBackend rocksDbBackend = new RocksDBStateBackend(checkpointPath);
assertEquals(PredefinedOptions.DEFAULT, rocksDbBackend.getPredefinedOptions());
rocksDbBackend.setPredefinedOptions(PredefinedOptions.SPINNING_DISK_OPTIMIZED);
assertEquals(PredefinedOptions.SPINNING_DISK_OPTIMIZED, rocksDbBackend.getPredefinedOptions());
try (DBOptions optCreated = rocksDbBackend.getDbOptions();
DBOptions optReference = new DBOptions();
ColumnFamilyOptions colCreated = rocksDbBackend.getColumnOptions()) {
// check that our instance uses something that we configured
assertEquals(true, optCreated.disableDataSync());
// just ensure that we pickend an option that actually differs from the reference.
assertEquals(false, optReference.disableDataSync());
assertEquals(CompactionStyle.LEVEL, colCreated.compactionStyle());
}
}
use of org.rocksdb.DBOptions in project flink by apache.
the class RocksDBStateBackendConfigTest method testPredefinedAndOptionsFactory.
@Test
public void testPredefinedAndOptionsFactory() throws Exception {
String checkpointPath = tempFolder.newFolder().toURI().toString();
RocksDBStateBackend rocksDbBackend = new RocksDBStateBackend(checkpointPath);
assertEquals(PredefinedOptions.DEFAULT, rocksDbBackend.getPredefinedOptions());
rocksDbBackend.setPredefinedOptions(PredefinedOptions.SPINNING_DISK_OPTIMIZED);
rocksDbBackend.setOptions(new OptionsFactory() {
@Override
public DBOptions createDBOptions(DBOptions currentOptions) {
return currentOptions;
}
@Override
public ColumnFamilyOptions createColumnOptions(ColumnFamilyOptions currentOptions) {
return currentOptions.setCompactionStyle(CompactionStyle.UNIVERSAL);
}
});
assertEquals(PredefinedOptions.SPINNING_DISK_OPTIMIZED, rocksDbBackend.getPredefinedOptions());
assertNotNull(rocksDbBackend.getOptions());
assertEquals(CompactionStyle.UNIVERSAL, rocksDbBackend.getColumnOptions().compactionStyle());
}
use of org.rocksdb.DBOptions in project jstorm by alibaba.
the class RocksDBTest method visitorAccross.
public void visitorAccross() throws RocksDBException, InterruptedException {
DBOptions dbOptions = null;
TtlDB ttlDB = null;
List<ColumnFamilyDescriptor> cfNames = new ArrayList<ColumnFamilyDescriptor>();
List<ColumnFamilyHandle> columnFamilyHandleList = new ArrayList<ColumnFamilyHandle>();
cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
cfNames.add(new ColumnFamilyDescriptor("new_cf".getBytes()));
List<Integer> ttlValues = new ArrayList<Integer>();
// new column family with 1 second ttl
ttlValues.add(1);
// Default column family with infinite lifetime
ttlValues.add(0);
try {
System.out.println("Begin to open db");
dbOptions = new DBOptions().setCreateMissingColumnFamilies(true).setCreateIfMissing(true);
ttlDB = TtlDB.open(dbOptions, rootDir, cfNames, columnFamilyHandleList, ttlValues, false);
System.out.println("Successfully open db " + rootDir);
List<String> keys = new ArrayList<String>();
keys.add("key");
ttlDB.put("key".getBytes(), "key".getBytes());
for (int i = 0; i < 2; i++) {
String key = "key" + i;
keys.add(key);
ttlDB.put(columnFamilyHandleList.get(i), key.getBytes(), key.getBytes());
}
try {
byte[] value = ttlDB.get("others".getBytes());
if (value != null) {
System.out.println("Raw get :" + new String(value));
} else {
System.out.println("No value of other");
}
} catch (Exception e) {
System.out.println("Occur exception other");
}
for (String key : keys) {
try {
byte[] value = ttlDB.get(key.getBytes());
if (value != null) {
System.out.println("Raw get :" + new String(value));
} else {
System.out.println("No value of " + key);
}
} catch (Exception e) {
System.out.println("Occur exception " + key + ", Raw");
}
for (int i = 0; i < 2; i++) {
try {
byte[] value = ttlDB.get(columnFamilyHandleList.get(i), key.getBytes());
if (value != null) {
System.out.println("handler index" + i + " get :" + new String(value));
} else {
System.out.println("No value of index" + i + " get :" + key);
}
} catch (Exception e) {
System.out.println("Occur exception " + key + ", handler index:" + i);
}
}
}
} finally {
for (ColumnFamilyHandle columnFamilyHandle : columnFamilyHandleList) {
columnFamilyHandle.dispose();
}
if (ttlDB != null) {
ttlDB.close();
}
if (dbOptions != null) {
dbOptions.dispose();
}
}
}
use of org.rocksdb.DBOptions in project flink by apache.
the class KVStateRequestSerializerRocksDBTest method testMapSerialization.
/**
* Tests map serialization and deserialization match.
*
* @see KvStateRequestSerializerTest#testMapSerialization()
* KvStateRequestSerializerTest#testMapSerialization() using the heap state back-end
* test
*/
@Test
public void testMapSerialization() throws Exception {
final long key = 0L;
// objects for RocksDB state list serialisation
DBOptions dbOptions = PredefinedOptions.DEFAULT.createDBOptions();
dbOptions.setCreateIfMissing(true);
ColumnFamilyOptions columnFamilyOptions = PredefinedOptions.DEFAULT.createColumnOptions();
final RocksDBKeyedStateBackend<Long> longHeapKeyedStateBackend = new RocksDBKeyedStateBackend<>(new JobID(), "no-op", ClassLoader.getSystemClassLoader(), temporaryFolder.getRoot(), dbOptions, columnFamilyOptions, mock(TaskKvStateRegistry.class), LongSerializer.INSTANCE, 1, new KeyGroupRange(0, 0), new ExecutionConfig());
longHeapKeyedStateBackend.setCurrentKey(key);
final InternalMapState<VoidNamespace, Long, String> mapState = (InternalMapState<VoidNamespace, Long, String>) longHeapKeyedStateBackend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, new MapStateDescriptor<>("test", LongSerializer.INSTANCE, StringSerializer.INSTANCE));
KvStateRequestSerializerTest.testMapSerialization(key, mapState);
}
Aggregations