Search in sources :

Example 1 with DebugStatistics

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();
    }
}
Also used : WriteOptions(org.rocksdb.WriteOptions) RaftLogStorageOptions(io.dingodb.raft.option.RaftLogStorageOptions) RocksDBException(org.rocksdb.RocksDBException) DebugStatistics(io.dingodb.raft.util.DebugStatistics) ReadOptions(org.rocksdb.ReadOptions)

Example 2 with DebugStatistics

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;
}
Also used : ColumnFamilyOptions(org.rocksdb.ColumnFamilyOptions) WriteOptions(org.rocksdb.WriteOptions) DebugStatistics(io.dingodb.raft.util.DebugStatistics) RocksStatisticsCollector(io.dingodb.store.row.rocks.support.RocksStatisticsCollector) ColumnFamilyDescriptor(org.rocksdb.ColumnFamilyDescriptor) RocksDBException(org.rocksdb.RocksDBException) StorageException(io.dingodb.store.row.errors.StorageException) IOException(java.io.IOException) DistributedLock(io.dingodb.store.row.util.concurrent.DistributedLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Lock(java.util.concurrent.locks.Lock)

Aggregations

DebugStatistics (io.dingodb.raft.util.DebugStatistics)2 RocksDBException (org.rocksdb.RocksDBException)2 WriteOptions (org.rocksdb.WriteOptions)2 RaftLogStorageOptions (io.dingodb.raft.option.RaftLogStorageOptions)1 StorageException (io.dingodb.store.row.errors.StorageException)1 RocksStatisticsCollector (io.dingodb.store.row.rocks.support.RocksStatisticsCollector)1 DistributedLock (io.dingodb.store.row.util.concurrent.DistributedLock)1 IOException (java.io.IOException)1 Lock (java.util.concurrent.locks.Lock)1 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)1 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)1 ColumnFamilyDescriptor (org.rocksdb.ColumnFamilyDescriptor)1 ColumnFamilyOptions (org.rocksdb.ColumnFamilyOptions)1 ReadOptions (org.rocksdb.ReadOptions)1