use of io.dingodb.raft.util.DebugStatistics in project dingo by dingodb.
the class RocksDBLogStorage method init.
@Override
public boolean init(final LogStorageOptions opts) {
Requires.requireNonNull(opts.getConfigurationManager(), "Null conf manager");
Requires.requireNonNull(opts.getLogEntryCodecFactory(), "Null log entry codec factory");
this.writeLock.lock();
boolean isInputRaftLogEmpty = false;
try {
if (this.db != null) {
LOG.warn("RocksDBLogStorage init() already.");
return true;
}
this.logEntryDecoder = opts.getLogEntryCodecFactory().decoder();
this.logEntryEncoder = opts.getLogEntryCodecFactory().encoder();
Requires.requireNonNull(this.logEntryDecoder, "Null log entry decoder");
Requires.requireNonNull(this.logEntryEncoder, "Null log entry encoder");
this.dbOptions = createDBOptions();
if (this.openStatistics) {
this.statistics = new DebugStatistics();
this.dbOptions.setStatistics(this.statistics);
}
this.writeOptions = new WriteOptions();
this.writeOptions.setSync(this.sync);
this.totalOrderReadOptions = new ReadOptions();
this.totalOrderReadOptions.setTotalOrderSeek(true);
this.dbOptions.setMaxTotalWalSize(4 << 30L);
RaftLogStorageOptions raftLogStorageOptions = opts.getRaftLogStorageOptions();
if (raftLogStorageOptions == null) {
raftLogStorageOptions = new RaftLogStorageOptions();
isInputRaftLogEmpty = true;
}
if (raftLogStorageOptions.getDbMaxTotalWalSize() != 0) {
this.dbOptions.setMaxTotalWalSize(raftLogStorageOptions.getDbMaxTotalWalSize());
}
this.dbOptions.setMaxSubcompactions(4);
if (raftLogStorageOptions.getDbMaxSubCompactions() != 0) {
this.dbOptions.setMaxSubcompactions(raftLogStorageOptions.getDbMaxSubCompactions());
}
this.dbOptions.setRecycleLogFileNum(4);
if (raftLogStorageOptions.getDbRecycleLogFileNum() != 0) {
this.dbOptions.setRecycleLogFileNum(raftLogStorageOptions.getDbRecycleLogFileNum());
}
this.dbOptions.setKeepLogFileNum(4);
if (raftLogStorageOptions.getDbKeepLogFileNum() != 0) {
this.dbOptions.setKeepLogFileNum(raftLogStorageOptions.getDbKeepLogFileNum());
}
this.dbOptions.setDbWriteBufferSize(20 << 30L);
if (raftLogStorageOptions.getDbWriteBufferSize() != 0) {
this.dbOptions.setDbWriteBufferSize(raftLogStorageOptions.getDbWriteBufferSize());
}
this.dbOptions.setMaxBackgroundJobs(16);
if (raftLogStorageOptions.getDbMaxBackGroupJobs() != 0) {
this.dbOptions.setMaxBackgroundJobs(raftLogStorageOptions.getDbMaxBackGroupJobs());
}
this.dbOptions.setMaxBackgroundCompactions(8);
if (raftLogStorageOptions.getDbMaxBackGroupCompactions() != 0) {
this.dbOptions.setMaxBackgroundCompactions(raftLogStorageOptions.getDbMaxBackGroupCompactions());
}
this.dbOptions.setMaxBackgroundFlushes(8);
if (raftLogStorageOptions.getDbMaxBackGroupFlushes() != 0) {
this.dbOptions.setMaxBackgroundFlushes(raftLogStorageOptions.getDbMaxBackGroupFlushes());
}
this.dbOptions.setMaxManifestFileSize(256 * 1024 * 1024L);
if (raftLogStorageOptions.getDbMaxManifestFileSize() != 0) {
this.dbOptions.setMaxManifestFileSize(raftLogStorageOptions.getDbMaxManifestFileSize());
}
LOG.info("Init raft log dbPath:{}, raft log options:{}, default options:{}", this.path, raftLogStorageOptions.toString(), isInputRaftLogEmpty);
return initAndLoad(opts);
} catch (final RocksDBException e) {
LOG.error("Fail to init RocksDBLogStorage, path={}.", this.path, e);
return false;
} finally {
this.writeLock.unlock();
}
}
use of io.dingodb.raft.util.DebugStatistics in project dingo by dingodb.
the class RocksRawKVStore method init.
@Override
public boolean init(final StoreDBOptions opts) {
final Lock writeLock = this.readWriteLock.writeLock();
writeLock.lock();
try {
if (this.db != null) {
LOG.info("[RocksRawKVStore] already started.");
return true;
}
this.opts = opts;
this.options = createDBOptions();
if (opts.isOpenStatisticsCollector()) {
this.statistics = new DebugStatistics();
this.options.setStatistics(this.statistics);
final long intervalSeconds = opts.getStatisticsCallbackIntervalSeconds();
if (intervalSeconds > 0) {
this.statisticsCollector = new RocksStatisticsCollector(TimeUnit.SECONDS.toMillis(intervalSeconds));
this.statisticsCollector.start();
}
}
final ColumnFamilyOptions cfOptions = createColumnFamilyOptions();
this.cfOptionsList.add(cfOptions);
// default column family
this.cfDescriptors.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY, cfOptions));
// sequence column family
this.cfDescriptors.add(new ColumnFamilyDescriptor(BytesUtil.writeUtf8("DINGO_SEQUENCE"), cfOptions));
// locking column family
this.cfDescriptors.add(new ColumnFamilyDescriptor(BytesUtil.writeUtf8("DINGO_LOCKING"), cfOptions));
// fencing column family
this.cfDescriptors.add(new ColumnFamilyDescriptor(BytesUtil.writeUtf8("DINGO_FENCING"), cfOptions));
this.writeOptions = new WriteOptions();
this.writeOptions.setSync(opts.isSync());
// If `sync` is true, `disableWAL` must be set false.
this.writeOptions.setDisableWAL(!opts.isSync() && opts.isDisableWAL());
// Delete existing data, relying on raft's snapshot and log playback
// to reply to the data is the correct behavior.
destroyRocksDB(opts);
openRocksDB(opts);
this.shutdownLock.setMaxPermits(1);
LOG.info("[RocksRawKVStore] start successfully, options: {}.", opts);
return true;
} catch (final Exception e) {
LOG.error("Fail to open rocksDB at path {}, {}.", opts.getDataPath(), StackTraceUtil.stackTrace(e));
} finally {
writeLock.unlock();
}
return false;
}
Aggregations