Search in sources :

Example 1 with RaftLogStorageOptions

use of io.dingodb.raft.option.RaftLogStorageOptions 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 RaftLogStorageOptions

use of io.dingodb.raft.option.RaftLogStorageOptions in project dingo by dingodb.

the class RegionEngine method init.

@Override
public synchronized boolean init(final RegionEngineOptions opts) {
    if (this.started) {
        LOG.info("[RegionEngine: {}] already started.", this.region);
        return true;
    }
    this.regionOpts = Requires.requireNonNull(opts, "opts");
    this.fsm = new KVStoreStateMachine(this.region, this.storeEngine);
    this.storeEngine.getStateListenerContainer().addStateListener(this.region.getId(), this);
    // node options
    NodeOptions nodeOpts = opts.getNodeOptions();
    if (nodeOpts == null) {
        nodeOpts = new NodeOptions();
    }
    final long metricsReportPeriod = opts.getMetricsReportPeriod();
    if (metricsReportPeriod > 0) {
        // metricsReportPeriod > 0 means enable metrics
        nodeOpts.setEnableMetrics(true);
    }
    final Configuration initialConf = new Configuration();
    if (!initialConf.parse(opts.getInitialServerList())) {
        LOG.error("Fail to parse initial configuration {}.", opts.getInitialServerList());
        return false;
    }
    nodeOpts.setInitialConf(initialConf);
    nodeOpts.setFsm(this.fsm);
    final String raftDataPath = opts.getRaftDataPath();
    try {
        FileUtils.forceMkdir(new File(raftDataPath));
    } catch (final Throwable t) {
        LOG.error("Fail to make dir for raftDataPath {}.", raftDataPath);
        return false;
    }
    if (Strings.isBlank(nodeOpts.getLogUri())) {
        final Path logUri = Paths.get(raftDataPath, "log");
        nodeOpts.setLogUri(logUri.toString());
    }
    if (Strings.isBlank(nodeOpts.getRaftMetaUri())) {
        final Path meteUri = Paths.get(raftDataPath, "meta");
        nodeOpts.setRaftMetaUri(meteUri.toString());
    }
    if (Strings.isBlank(nodeOpts.getSnapshotUri())) {
        final Path snapshotUri = Paths.get(raftDataPath, "snapshot");
        nodeOpts.setSnapshotUri(snapshotUri.toString());
    }
    String storeOptionStr = "Null";
    RaftStoreOptions raftStoreOptions = opts.getRaftStoreOptions();
    if (raftStoreOptions != null) {
        RaftLogStorageOptions raftLogStorageOptions = raftStoreOptions.getRaftLogStorageOptions();
        nodeOpts.setRaftLogStorageOptions(raftLogStorageOptions);
        storeOptionStr = raftStoreOptions.toString();
    }
    LOG.info("[RegionEngine: {}], log uri: {}, raft meta uri: {}, snapshot uri: {}. raftDBOptions:{}", this.region, nodeOpts.getLogUri(), nodeOpts.getRaftMetaUri(), nodeOpts.getSnapshotUri(), storeOptionStr);
    final Endpoint serverAddress = opts.getServerAddress();
    final PeerId serverId = new PeerId(serverAddress, 0);
    final RpcServer rpcServer = this.storeEngine.getRpcServer();
    this.raftGroupService = new RaftGroupService(opts.getRaftGroupId(), serverId, nodeOpts, rpcServer, true);
    this.node = this.raftGroupService.start(false);
    RouteTable.getInstance().updateConfiguration(this.raftGroupService.getGroupId(), nodeOpts.getInitialConf());
    if (this.node != null) {
        final RawKVStore rawKVStore = this.storeEngine.getRawKVStore();
        final Executor readIndexExecutor = this.storeEngine.getReadIndexExecutor();
        this.raftRawKVStore = new RaftRawKVStore(this.node, rawKVStore, readIndexExecutor);
        this.metricsRawKVStore = new MetricsRawKVStore(this.region.getId(), this.raftRawKVStore);
        // metrics config
        if (this.regionMetricsReporter == null && metricsReportPeriod > 0) {
            final MetricRegistry metricRegistry = this.node.getNodeMetrics().getMetricRegistry();
            if (metricRegistry != null) {
                final ScheduledExecutorService scheduler = this.storeEngine.getMetricsScheduler();
                // start raft node metrics reporter
                this.regionMetricsReporter = Slf4jReporter.forRegistry(metricRegistry).prefixedWith("region_" + this.region.getId()).withLoggingLevel(Slf4jReporter.LoggingLevel.INFO).outputTo(LOG).scheduleOn(scheduler).shutdownExecutorOnStop(scheduler != null).build();
                this.regionMetricsReporter.start(metricsReportPeriod, TimeUnit.SECONDS);
            }
        }
        if (this.storeEngine.getPlacementDriverClient() instanceof RemotePlacementDriverClient) {
            HeartbeatOptions heartbeatOpts = opts.getHeartbeatOptions();
            if (heartbeatOpts == null) {
                heartbeatOpts = new HeartbeatOptions();
            }
            this.heartbeatSender = new RegionHeartbeatSender(this);
            if (!this.heartbeatSender.init(heartbeatOpts)) {
                LOG.error("Fail to init [HeartbeatSender].");
                return false;
            }
        }
        this.started = true;
        LOG.info("[RegionEngine] start successfully: {}.", this);
    }
    return this.started;
}
Also used : Path(java.nio.file.Path) RaftStoreOptions(io.dingodb.store.row.options.RaftStoreOptions) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Configuration(io.dingodb.raft.conf.Configuration) RaftGroupService(io.dingodb.raft.RaftGroupService) MetricRegistry(com.codahale.metrics.MetricRegistry) NodeOptions(io.dingodb.raft.option.NodeOptions) KVStoreStateMachine(io.dingodb.store.row.storage.KVStoreStateMachine) MetricsRawKVStore(io.dingodb.store.row.storage.MetricsRawKVStore) RemotePlacementDriverClient(io.dingodb.store.row.client.pd.RemotePlacementDriverClient) RaftLogStorageOptions(io.dingodb.raft.option.RaftLogStorageOptions) RaftRawKVStore(io.dingodb.store.row.storage.RaftRawKVStore) MetricsRawKVStore(io.dingodb.store.row.storage.MetricsRawKVStore) RawKVStore(io.dingodb.store.row.storage.RawKVStore) RegionHeartbeatSender(io.dingodb.store.row.client.pd.RegionHeartbeatSender) Executor(java.util.concurrent.Executor) Endpoint(io.dingodb.raft.util.Endpoint) HeartbeatOptions(io.dingodb.store.row.options.HeartbeatOptions) RpcServer(io.dingodb.raft.rpc.RpcServer) File(java.io.File) RaftRawKVStore(io.dingodb.store.row.storage.RaftRawKVStore) PeerId(io.dingodb.raft.entity.PeerId)

Example 3 with RaftLogStorageOptions

use of io.dingodb.raft.option.RaftLogStorageOptions in project dingo by dingodb.

the class RocksDBLogStorage method initAndLoad.

private boolean initAndLoad(final LogStorageOptions lopts) throws RocksDBException {
    this.hasLoadFirstLogIndex = false;
    this.firstLogIndex = 1;
    final List<ColumnFamilyDescriptor> columnFamilyDescriptors = new ArrayList<>();
    final ColumnFamilyOptions cfOption = createColumnFamilyOptions();
    ConfigurationManager confManager = lopts.getConfigurationManager();
    BlockBasedTableConfig tableConfig = new BlockBasedTableConfig();
    tableConfig.setBlockSize(128 * 1024);
    RaftLogStorageOptions raftLogStorageOptions = lopts.getRaftLogStorageOptions();
    if (raftLogStorageOptions.getCfBlockSize() != 0) {
        tableConfig.setBlockSize(raftLogStorageOptions.getCfBlockSize());
    }
    tableConfig.setBlockCacheSize(200 / 4 * 1024 * 1024 * 1024L);
    if (raftLogStorageOptions.getCfBlockCacheSize() != 0) {
        tableConfig.setBlockSize(raftLogStorageOptions.getCfBlockCacheSize());
    }
    cfOption.setTableFormatConfig(tableConfig);
    cfOption.setArenaBlockSize(128 * 1024 * 1024);
    if (raftLogStorageOptions.getCfArenaBlockSize() != 0) {
        cfOption.setArenaBlockSize(raftLogStorageOptions.getCfArenaBlockSize());
    }
    cfOption.setMinWriteBufferNumberToMerge(4);
    if (raftLogStorageOptions.getCfMinWriteBufferNumberToMerge() != 0) {
        cfOption.setMinWriteBufferNumberToMerge(raftLogStorageOptions.getCfMinWriteBufferNumberToMerge());
    }
    cfOption.setMaxWriteBufferNumber(5);
    if (raftLogStorageOptions.getCfMaxWriteBufferNumber() != 0) {
        cfOption.setMaxWriteBufferNumber(raftLogStorageOptions.getCfMaxWriteBufferNumber());
    }
    cfOption.setMaxCompactionBytes(512 * 1024 * 1024);
    if (raftLogStorageOptions.getCfMaxCompactionBytes() != 0) {
        cfOption.setMaxCompactionBytes(raftLogStorageOptions.getCfMaxCompactionBytes());
    }
    cfOption.setWriteBufferSize(1 * 1024 * 1024 * 1024);
    if (raftLogStorageOptions.getCfWriteBufferSize() != 0) {
        cfOption.setWriteBufferSize(raftLogStorageOptions.getCfWriteBufferSize());
    }
    this.cfOptions.add(cfOption);
    // Column family to store configuration log entry.
    columnFamilyDescriptors.add(new ColumnFamilyDescriptor("Configuration".getBytes(), cfOption));
    // Default column family to store user data log entry.
    columnFamilyDescriptors.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY, cfOption));
    openDB(columnFamilyDescriptors);
    load(confManager);
    return onInitLoaded();
}
Also used : ColumnFamilyOptions(org.rocksdb.ColumnFamilyOptions) RaftLogStorageOptions(io.dingodb.raft.option.RaftLogStorageOptions) ArrayList(java.util.ArrayList) BlockBasedTableConfig(org.rocksdb.BlockBasedTableConfig) ColumnFamilyDescriptor(org.rocksdb.ColumnFamilyDescriptor) ConfigurationManager(io.dingodb.raft.conf.ConfigurationManager)

Aggregations

RaftLogStorageOptions (io.dingodb.raft.option.RaftLogStorageOptions)3 MetricRegistry (com.codahale.metrics.MetricRegistry)1 RaftGroupService (io.dingodb.raft.RaftGroupService)1 Configuration (io.dingodb.raft.conf.Configuration)1 ConfigurationManager (io.dingodb.raft.conf.ConfigurationManager)1 PeerId (io.dingodb.raft.entity.PeerId)1 NodeOptions (io.dingodb.raft.option.NodeOptions)1 RpcServer (io.dingodb.raft.rpc.RpcServer)1 DebugStatistics (io.dingodb.raft.util.DebugStatistics)1 Endpoint (io.dingodb.raft.util.Endpoint)1 RegionHeartbeatSender (io.dingodb.store.row.client.pd.RegionHeartbeatSender)1 RemotePlacementDriverClient (io.dingodb.store.row.client.pd.RemotePlacementDriverClient)1 HeartbeatOptions (io.dingodb.store.row.options.HeartbeatOptions)1 RaftStoreOptions (io.dingodb.store.row.options.RaftStoreOptions)1 KVStoreStateMachine (io.dingodb.store.row.storage.KVStoreStateMachine)1 MetricsRawKVStore (io.dingodb.store.row.storage.MetricsRawKVStore)1 RaftRawKVStore (io.dingodb.store.row.storage.RaftRawKVStore)1 RawKVStore (io.dingodb.store.row.storage.RawKVStore)1 File (java.io.File)1 Path (java.nio.file.Path)1