use of org.rocksdb.ColumnFamilyOptions in project bookkeeper by apache.
the class RocksdbKVStore method openRocksdb.
protected void openRocksdb(StateStoreSpec spec) throws StateStoreException {
// initialize the db options
final BlockBasedTableConfig tableConfig = new BlockBasedTableConfig();
tableConfig.setBlockCacheSize(BLOCK_CACHE_SIZE);
tableConfig.setBlockSize(BLOCK_SIZE);
tableConfig.setChecksumType(DEFAULT_CHECKSUM_TYPE);
dbOpts = new DBOptions();
dbOpts.setCreateIfMissing(true);
dbOpts.setErrorIfExists(false);
dbOpts.setInfoLogLevel(DEFAULT_LOG_LEVEL);
dbOpts.setIncreaseParallelism(DEFAULT_PARALLELISM);
dbOpts.setCreateMissingColumnFamilies(true);
cfOpts = new ColumnFamilyOptions();
cfOpts.setTableFormatConfig(tableConfig);
cfOpts.setWriteBufferSize(WRITE_BUFFER_SIZE);
cfOpts.setCompressionType(DEFAULT_COMPRESSION_TYPE);
cfOpts.setCompactionStyle(DEFAULT_COMPACTION_STYLE);
cfOpts.setMaxWriteBufferNumber(MAX_WRITE_BUFFERS);
// initialize the write options
writeOpts = new WriteOptions();
// disable wal, since the source of truth will be on distributedlog
writeOpts.setDisableWAL(false);
// initialize the flush options
flushOpts = new FlushOptions();
flushOpts.setWaitForFlush(true);
// open the rocksdb
this.dbDir = spec.getLocalStateStoreDir();
Pair<RocksDB, List<ColumnFamilyHandle>> dbPair = openLocalDB(dbDir, dbOpts, cfOpts);
this.db = dbPair.getLeft();
this.metaCfHandle = dbPair.getRight().get(0);
this.dataCfHandle = dbPair.getRight().get(1);
}
use of org.rocksdb.ColumnFamilyOptions 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.ColumnFamilyOptions in project kafka by apache.
the class RocksDBGenericOptionsToDbOptionsColumnFamilyOptionsAdapterTest method shouldLogWarningWhenSettingWalOptions.
@Test
public void shouldLogWarningWhenSettingWalOptions() throws Exception {
try (final LogCaptureAppender appender = LogCaptureAppender.createAndRegister(RocksDBGenericOptionsToDbOptionsColumnFamilyOptionsAdapter.class)) {
final RocksDBGenericOptionsToDbOptionsColumnFamilyOptionsAdapter adapter = new RocksDBGenericOptionsToDbOptionsColumnFamilyOptionsAdapter(new DBOptions(), new ColumnFamilyOptions());
for (final Method method : RocksDBGenericOptionsToDbOptionsColumnFamilyOptionsAdapter.class.getDeclaredMethods()) {
if (walRelatedMethods.contains(method.getName())) {
method.invoke(adapter, getDBOptionsParameters(method.getParameterTypes()));
}
}
final List<String> walOptions = Arrays.asList("walDir", "walFilter", "walRecoveryMode", "walBytesPerSync", "walSizeLimitMB", "manualWalFlush", "maxTotalWalSize", "walTtlSeconds");
final Set<String> logMessages = appender.getEvents().stream().filter(e -> e.getLevel().equals("WARN")).map(LogCaptureAppender.Event::getMessage).collect(Collectors.toSet());
walOptions.forEach(option -> assertThat(logMessages, hasItem(String.format("WAL is explicitly disabled by Streams in RocksDB. Setting option '%s' will be ignored", option))));
}
}
use of org.rocksdb.ColumnFamilyOptions in project kafka by apache.
the class RocksDBGenericOptionsToDbOptionsColumnFamilyOptionsAdapterTest method verifyColumnFamilyOptionsMethodCall.
private void verifyColumnFamilyOptionsMethodCall(final Method method) throws Exception {
final ColumnFamilyOptions mockedColumnFamilyOptions = mock(ColumnFamilyOptions.class);
final RocksDBGenericOptionsToDbOptionsColumnFamilyOptionsAdapter optionsFacadeColumnFamilyOptions = new RocksDBGenericOptionsToDbOptionsColumnFamilyOptionsAdapter(new DBOptions(), mockedColumnFamilyOptions);
final Object[] parameters = getColumnFamilyOptionsParameters(method.getParameterTypes());
try {
reset(mockedColumnFamilyOptions);
replay(mockedColumnFamilyOptions);
method.invoke(optionsFacadeColumnFamilyOptions, parameters);
verify();
fail("Should have called ColumnFamilyOptions." + method.getName() + "()");
} catch (final InvocationTargetException undeclaredMockMethodCall) {
assertThat(undeclaredMockMethodCall.getCause(), instanceOf(AssertionError.class));
assertThat(undeclaredMockMethodCall.getCause().getMessage().trim(), matchesPattern("Unexpected method call ColumnFamilyOptions\\." + method.getName() + "(.*)"));
}
}
use of org.rocksdb.ColumnFamilyOptions in project kafka by apache.
the class RocksDBTimestampedStoreTest method shouldOpenExistingStoreInRegularMode.
@Test
public void shouldOpenExistingStoreInRegularMode() throws Exception {
// prepare store
rocksDBStore.init((StateStoreContext) context, rocksDBStore);
rocksDBStore.put(new Bytes("key".getBytes()), "timestamped".getBytes());
rocksDBStore.close();
// re-open store
try (final LogCaptureAppender appender = LogCaptureAppender.createAndRegister(RocksDBTimestampedStore.class)) {
rocksDBStore.init((StateStoreContext) context, rocksDBStore);
assertThat(appender.getMessages(), hasItem("Opening store " + DB_NAME + " in regular mode"));
} finally {
rocksDBStore.close();
}
// verify store
final DBOptions dbOptions = new DBOptions();
final ColumnFamilyOptions columnFamilyOptions = new ColumnFamilyOptions();
final List<ColumnFamilyDescriptor> columnFamilyDescriptors = asList(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY, columnFamilyOptions), new ColumnFamilyDescriptor("keyValueWithTimestamp".getBytes(StandardCharsets.UTF_8), columnFamilyOptions));
final List<ColumnFamilyHandle> columnFamilies = new ArrayList<>(columnFamilyDescriptors.size());
RocksDB db = null;
ColumnFamilyHandle noTimestampColumnFamily = null, withTimestampColumnFamily = null;
try {
db = RocksDB.open(dbOptions, new File(new File(context.stateDir(), "rocksdb"), DB_NAME).getAbsolutePath(), columnFamilyDescriptors, columnFamilies);
noTimestampColumnFamily = columnFamilies.get(0);
withTimestampColumnFamily = columnFamilies.get(1);
assertThat(db.get(noTimestampColumnFamily, "key".getBytes()), new IsNull<>());
assertThat(db.getLongProperty(noTimestampColumnFamily, "rocksdb.estimate-num-keys"), is(0L));
assertThat(db.get(withTimestampColumnFamily, "key".getBytes()).length, is(11));
assertThat(db.getLongProperty(withTimestampColumnFamily, "rocksdb.estimate-num-keys"), is(1L));
} finally {
// Order of closing must follow: ColumnFamilyHandle > RocksDB > DBOptions > ColumnFamilyOptions
if (noTimestampColumnFamily != null) {
noTimestampColumnFamily.close();
}
if (withTimestampColumnFamily != null) {
withTimestampColumnFamily.close();
}
if (db != null) {
db.close();
}
dbOptions.close();
columnFamilyOptions.close();
}
}
Aggregations