Search in sources :

Example 1 with RpcServer

use of io.dingodb.raft.rpc.RpcServer 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 2 with RpcServer

use of io.dingodb.raft.rpc.RpcServer in project dingo by dingodb.

the class CoordinatorStateMachine method initRpcServer.

private RpcServer initRpcServer() {
    ExtSerializerSupports.init();
    boolean isAutoBalanceSplit = context.coordOpts().getSchedule().isAutoBalanceSplit();
    log.info("coordOpt, isAutoBalanceSplit: {}", isAutoBalanceSplit);
    RpcServer rpcServer = createRaftRpcServer(context.endpoint(), raftExecutor(), cliExecutor());
    rpcServer.registerProcessor(new GetLocationHandler());
    rpcServer.registerProcessor(new GetClusterInfoHandler(context.rowStoreMetaAdaptor()));
    rpcServer.registerProcessor(new GetStoreInfoHandler(context.rowStoreMetaAdaptor()));
    rpcServer.registerProcessor(new GetStoreIdHandler(context.rowStoreMetaAdaptor()));
    rpcServer.registerProcessor(new RegionHeartbeatHandler(context.rowStoreMetaAdaptor(), isAutoBalanceSplit));
    rpcServer.registerProcessor(new SetStoreHandler(context.rowStoreMetaAdaptor()));
    rpcServer.registerProcessor(new StoreHeartbeatHandler(context.rowStoreMetaAdaptor()));
    log.info("Start coordinator raft rpc server, result: {}.", rpcServer.init(null));
    context.rpcServer(rpcServer);
    return rpcServer;
}
Also used : GetClusterInfoHandler(io.dingodb.server.coordinator.handler.GetClusterInfoHandler) GetLocationHandler(io.dingodb.server.coordinator.handler.GetLocationHandler) SetStoreHandler(io.dingodb.server.coordinator.handler.SetStoreHandler) GetStoreIdHandler(io.dingodb.server.coordinator.handler.GetStoreIdHandler) RpcServer(io.dingodb.raft.rpc.RpcServer) RaftRpcServerFactory.createRaftRpcServer(io.dingodb.raft.rpc.RaftRpcServerFactory.createRaftRpcServer) RegionHeartbeatHandler(io.dingodb.server.coordinator.handler.RegionHeartbeatHandler) GetStoreInfoHandler(io.dingodb.server.coordinator.handler.GetStoreInfoHandler) StoreHeartbeatHandler(io.dingodb.server.coordinator.handler.StoreHeartbeatHandler)

Example 3 with RpcServer

use of io.dingodb.raft.rpc.RpcServer in project dingo by dingodb.

the class BoltRaftRpcFactory method createRpcServer.

@Override
public RpcServer createRpcServer(final Endpoint endpoint, final ConfigHelper<RpcServer> helper) {
    final int port = Requires.requireNonNull(endpoint, "endpoint").getPort();
    Requires.requireTrue(port > 0 && port < 0xFFFF, "port out of range:" + port);
    final com.alipay.remoting.rpc.RpcServer boltImpl = new com.alipay.remoting.rpc.RpcServer(port, true, false);
    final RpcServer rpcServer = new BoltRpcServer(boltImpl);
    if (helper != null) {
        helper.config(rpcServer);
    }
    return rpcServer;
}
Also used : RpcServer(io.dingodb.raft.rpc.RpcServer) Endpoint(io.dingodb.raft.util.Endpoint)

Aggregations

RpcServer (io.dingodb.raft.rpc.RpcServer)3 Endpoint (io.dingodb.raft.util.Endpoint)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 RaftGroupService (io.dingodb.raft.RaftGroupService)1 Configuration (io.dingodb.raft.conf.Configuration)1 PeerId (io.dingodb.raft.entity.PeerId)1 NodeOptions (io.dingodb.raft.option.NodeOptions)1 RaftLogStorageOptions (io.dingodb.raft.option.RaftLogStorageOptions)1 RaftRpcServerFactory.createRaftRpcServer (io.dingodb.raft.rpc.RaftRpcServerFactory.createRaftRpcServer)1 GetClusterInfoHandler (io.dingodb.server.coordinator.handler.GetClusterInfoHandler)1 GetLocationHandler (io.dingodb.server.coordinator.handler.GetLocationHandler)1 GetStoreIdHandler (io.dingodb.server.coordinator.handler.GetStoreIdHandler)1 GetStoreInfoHandler (io.dingodb.server.coordinator.handler.GetStoreInfoHandler)1 RegionHeartbeatHandler (io.dingodb.server.coordinator.handler.RegionHeartbeatHandler)1 SetStoreHandler (io.dingodb.server.coordinator.handler.SetStoreHandler)1 StoreHeartbeatHandler (io.dingodb.server.coordinator.handler.StoreHeartbeatHandler)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