use of com.alibaba.jstorm.cache.rocksdb.RocksDbOptionsFactory in project jstorm by alibaba.
the class RocksDbHdfsState method initRocksDb.
protected void initRocksDb() {
RocksDbOptionsFactory optionFactory = new RocksDbOptionsFactory.Defaults();
Options options = optionFactory.createOptions(null);
DBOptions dbOptions = optionFactory.createDbOptions(null);
ColumnFamilyOptions cfOptions = optionFactory.createColumnFamilyOptions(null);
String optionsFactoryClass = (String) conf.get(ConfigExtension.ROCKSDB_OPTIONS_FACTORY_CLASS);
if (optionsFactoryClass != null) {
RocksDbOptionsFactory udfOptionFactory = (RocksDbOptionsFactory) Utils.newInstance(optionsFactoryClass);
options = udfOptionFactory.createOptions(options);
dbOptions = udfOptionFactory.createDbOptions(dbOptions);
cfOptions = udfOptionFactory.createColumnFamilyOptions(cfOptions);
}
try {
ttlTimeSec = ConfigExtension.getStateTtlTime(conf);
if (ttlTimeSec > 0)
rocksDb = TtlDB.open(options, rocksDbDir, ttlTimeSec, false);
else
rocksDb = RocksDB.open(options, rocksDbDir);
// enable compaction
rocksDb.compactRange();
LOG.info("Finish the initialization of RocksDB");
} catch (RocksDBException e) {
LOG.error("Failed to open rocksdb located at " + rocksDbDir, e);
throw new RuntimeException(e.getMessage());
}
lastCheckpointFiles = new HashSet<String>();
lastCleanTime = System.currentTimeMillis();
lastSuccessBatchId = -1;
}
use of com.alibaba.jstorm.cache.rocksdb.RocksDbOptionsFactory in project jstorm by alibaba.
the class WindowedRocksDbHdfsState method initRocksDb.
@Override
protected void initRocksDb() {
windowToCFHandler = new HashMap<>();
RocksDbOptionsFactory optionFactory = new RocksDbOptionsFactory.Defaults();
Options options = optionFactory.createOptions(null);
DBOptions dbOptions = optionFactory.createDbOptions(null);
ColumnFamilyOptions cfOptions = optionFactory.createColumnFamilyOptions(null);
String optionsFactoryClass = (String) conf.get(ConfigExtension.ROCKSDB_OPTIONS_FACTORY_CLASS);
if (optionsFactoryClass != null) {
RocksDbOptionsFactory udfOptionFactory = (RocksDbOptionsFactory) Utils.newInstance(optionsFactoryClass);
options = udfOptionFactory.createOptions(options);
dbOptions = udfOptionFactory.createDbOptions(dbOptions);
cfOptions = udfOptionFactory.createColumnFamilyOptions(cfOptions);
}
try {
ttlTimeSec = ConfigExtension.getStateTtlTime(conf);
List<Integer> ttlValues = new ArrayList<>();
List<byte[]> families = RocksDB.listColumnFamilies(options, rocksDbDir);
List<ColumnFamilyHandle> columnFamilyHandles = new ArrayList<>();
List<ColumnFamilyDescriptor> columnFamilyDescriptors = new ArrayList<>();
if (families != null) {
for (byte[] bytes : families) {
columnFamilyDescriptors.add(new ColumnFamilyDescriptor(bytes, cfOptions));
LOG.debug("Load colum family of {}", new String(bytes));
if (ttlTimeSec > 0)
ttlValues.add(ttlTimeSec);
}
}
if (columnFamilyDescriptors.size() > 0) {
if (ttlTimeSec > 0)
rocksDb = TtlDB.open(dbOptions, rocksDbDir, columnFamilyDescriptors, columnFamilyHandles, ttlValues, false);
else
rocksDb = RocksDB.open(dbOptions, rocksDbDir, columnFamilyDescriptors, columnFamilyHandles);
int n = Math.min(columnFamilyDescriptors.size(), columnFamilyHandles.size());
LOG.info("Try to load RocksDB with column family, desc_num={}, handler_num={}", columnFamilyDescriptors.size(), columnFamilyHandles.size());
// skip default column
for (int i = 1; i < n; i++) {
windowToCFHandler.put((TimeWindow) serializer.deserialize(columnFamilyDescriptors.get(i).columnFamilyName()), columnFamilyHandles.get(i));
}
} else {
rocksDb = RocksDB.open(options, rocksDbDir);
}
rocksDb.compactRange();
LOG.info("Finish the initialization of RocksDB");
} catch (RocksDBException e) {
LOG.error("Failed to open rocksdb located at " + rocksDbDir, e);
throw new RuntimeException(e.getMessage());
}
lastCheckpointFiles = new HashSet<String>();
lastCleanTime = System.currentTimeMillis();
lastSuccessBatchId = -1;
}
Aggregations