Search in sources :

Example 1 with IgniteRpcServer

use of org.apache.ignite.raft.jraft.rpc.impl.IgniteRpcServer in project ignite-3 by apache.

the class JraftServerImpl method start.

/**
 * {@inheritDoc}
 */
@Override
public void start() {
    assert opts.isSharedPools() : "RAFT server is supposed to run in shared pools mode";
    // Pre-create all pools in shared mode.
    if (opts.getCommonExecutor() == null) {
        opts.setCommonExecutor(JRaftUtils.createCommonExecutor(opts));
    }
    if (opts.getStripedExecutor() == null) {
        opts.setStripedExecutor(JRaftUtils.createAppendEntriesExecutor(opts));
    }
    if (opts.getScheduler() == null) {
        opts.setScheduler(JRaftUtils.createScheduler(opts));
    }
    if (opts.getClientExecutor() == null) {
        opts.setClientExecutor(JRaftUtils.createClientExecutor(opts, opts.getServerName()));
    }
    if (opts.getVoteTimer() == null) {
        opts.setVoteTimer(JRaftUtils.createTimer(opts, "JRaft-VoteTimer"));
    }
    if (opts.getElectionTimer() == null) {
        opts.setElectionTimer(JRaftUtils.createTimer(opts, "JRaft-ElectionTimer"));
    }
    if (opts.getStepDownTimer() == null) {
        opts.setStepDownTimer(JRaftUtils.createTimer(opts, "JRaft-StepDownTimer"));
    }
    if (opts.getSnapshotTimer() == null) {
        opts.setSnapshotTimer(JRaftUtils.createTimer(opts, "JRaft-SnapshotTimer"));
    }
    requestExecutor = JRaftUtils.createRequestExecutor(opts);
    rpcServer = new IgniteRpcServer(service, nodeManager, opts.getRaftMessagesFactory(), requestExecutor);
    if (opts.getfSMCallerExecutorDisruptor() == null) {
        opts.setfSMCallerExecutorDisruptor(new StripedDisruptor<FSMCallerImpl.ApplyTask>(NamedThreadFactory.threadPrefix(opts.getServerName(), "JRaft-FSMCaller-Disruptor"), opts.getRaftOptions().getDisruptorBufferSize(), () -> new FSMCallerImpl.ApplyTask(), opts.getStripes()));
    }
    if (opts.getNodeApplyDisruptor() == null) {
        opts.setNodeApplyDisruptor(new StripedDisruptor<NodeImpl.LogEntryAndClosure>(NamedThreadFactory.threadPrefix(opts.getServerName(), "JRaft-NodeImpl-Disruptor"), opts.getRaftOptions().getDisruptorBufferSize(), () -> new NodeImpl.LogEntryAndClosure(), opts.getStripes()));
    }
    if (opts.getReadOnlyServiceDisruptor() == null) {
        opts.setReadOnlyServiceDisruptor(new StripedDisruptor<ReadOnlyServiceImpl.ReadIndexEvent>(NamedThreadFactory.threadPrefix(opts.getServerName(), "JRaft-ReadOnlyService-Disruptor"), opts.getRaftOptions().getDisruptorBufferSize(), () -> new ReadOnlyServiceImpl.ReadIndexEvent(), opts.getStripes()));
    }
    if (opts.getLogManagerDisruptor() == null) {
        opts.setLogManagerDisruptor(new StripedDisruptor<LogManagerImpl.StableClosureEvent>(NamedThreadFactory.threadPrefix(opts.getServerName(), "JRaft-LogManager-Disruptor"), opts.getRaftOptions().getDisruptorBufferSize(), () -> new LogManagerImpl.StableClosureEvent(), opts.getStripes()));
    }
    rpcServer.init(null);
}
Also used : IgniteRpcServer(org.apache.ignite.raft.jraft.rpc.impl.IgniteRpcServer)

Example 2 with IgniteRpcServer

use of org.apache.ignite.raft.jraft.rpc.impl.IgniteRpcServer in project ignite-3 by apache.

the class ItNodeTest method waitForTopology.

/**
 * TODO asch get rid of waiting for topology IGNITE-14832
 *
 * @param cluster
 * @param addr
 * @param expected
 * @param timeout
 * @return
 */
private boolean waitForTopology(TestCluster cluster, Endpoint addr, int expected, long timeout) {
    RaftGroupService grp = cluster.getServer(addr);
    if (grp == null) {
        LOG.warn("Node has not been found {}", addr);
        return false;
    }
    RpcServer rpcServer = grp.getRpcServer();
    if (!(rpcServer instanceof IgniteRpcServer))
        return true;
    ClusterService service = ((IgniteRpcServer) grp.getRpcServer()).clusterService();
    long stop = System.currentTimeMillis() + timeout;
    while (System.currentTimeMillis() < stop) {
        if (service.topologyService().allMembers().size() >= expected)
            return true;
        try {
            Thread.sleep(50);
        } catch (InterruptedException e) {
            return false;
        }
    }
    return false;
}
Also used : ClusterService(org.apache.ignite.network.ClusterService) RaftGroupService(org.apache.ignite.raft.jraft.RaftGroupService) RpcServer(org.apache.ignite.raft.jraft.rpc.RpcServer) IgniteRpcServer(org.apache.ignite.raft.jraft.rpc.impl.IgniteRpcServer) TestIgniteRpcServer(org.apache.ignite.raft.jraft.rpc.TestIgniteRpcServer) IgniteRpcServer(org.apache.ignite.raft.jraft.rpc.impl.IgniteRpcServer) TestIgniteRpcServer(org.apache.ignite.raft.jraft.rpc.TestIgniteRpcServer)

Example 3 with IgniteRpcServer

use of org.apache.ignite.raft.jraft.rpc.impl.IgniteRpcServer in project ignite-3 by apache.

the class ItNodeTest method createService.

/**
 * @param groupId Group id.
 * @param peerId Peer id.
 * @param nodeOptions Node options.
 * @return Raft group service.
 */
private RaftGroupService createService(String groupId, PeerId peerId, NodeOptions nodeOptions) {
    Configuration initialConf = nodeOptions.getInitialConf();
    nodeOptions.setStripes(1);
    Stream<PeerId> peers = initialConf == null ? Stream.empty() : Stream.concat(initialConf.getPeers().stream(), initialConf.getLearners().stream());
    List<NetworkAddress> addressList = peers.map(PeerId::getEndpoint).map(JRaftUtils::addressFromEndpoint).collect(toList());
    var nodeManager = new NodeManager();
    ClusterService clusterService = ClusterServiceTestUtils.clusterService(testInfo, peerId.getEndpoint().getPort(), new StaticNodeFinder(addressList), new TestScaleCubeClusterServiceFactory());
    ExecutorService requestExecutor = JRaftUtils.createRequestExecutor(nodeOptions);
    executors.add(requestExecutor);
    IgniteRpcServer rpcServer = new TestIgniteRpcServer(clusterService, nodeManager, nodeOptions, requestExecutor);
    nodeOptions.setRpcClient(new IgniteRpcClient(clusterService));
    clusterService.start();
    var service = new RaftGroupService(groupId, peerId, nodeOptions, rpcServer, nodeManager) {

        @Override
        public synchronized void shutdown() {
            rpcServer.shutdown();
            super.shutdown();
            clusterService.stop();
        }
    };
    services.add(service);
    return service;
}
Also used : TestIgniteRpcServer(org.apache.ignite.raft.jraft.rpc.TestIgniteRpcServer) Configuration(org.apache.ignite.raft.jraft.conf.Configuration) StaticNodeFinder(org.apache.ignite.network.StaticNodeFinder) IgniteRpcClient(org.apache.ignite.raft.jraft.rpc.impl.IgniteRpcClient) RaftGroupService(org.apache.ignite.raft.jraft.RaftGroupService) IgniteRpcServer(org.apache.ignite.raft.jraft.rpc.impl.IgniteRpcServer) TestIgniteRpcServer(org.apache.ignite.raft.jraft.rpc.TestIgniteRpcServer) NodeManager(org.apache.ignite.raft.jraft.NodeManager) ClusterService(org.apache.ignite.network.ClusterService) TestScaleCubeClusterServiceFactory(org.apache.ignite.network.scalecube.TestScaleCubeClusterServiceFactory) NetworkAddress(org.apache.ignite.network.NetworkAddress) ExecutorService(java.util.concurrent.ExecutorService) PeerId(org.apache.ignite.raft.jraft.entity.PeerId)

Aggregations

IgniteRpcServer (org.apache.ignite.raft.jraft.rpc.impl.IgniteRpcServer)3 ClusterService (org.apache.ignite.network.ClusterService)2 RaftGroupService (org.apache.ignite.raft.jraft.RaftGroupService)2 TestIgniteRpcServer (org.apache.ignite.raft.jraft.rpc.TestIgniteRpcServer)2 ExecutorService (java.util.concurrent.ExecutorService)1 NetworkAddress (org.apache.ignite.network.NetworkAddress)1 StaticNodeFinder (org.apache.ignite.network.StaticNodeFinder)1 TestScaleCubeClusterServiceFactory (org.apache.ignite.network.scalecube.TestScaleCubeClusterServiceFactory)1 NodeManager (org.apache.ignite.raft.jraft.NodeManager)1 Configuration (org.apache.ignite.raft.jraft.conf.Configuration)1 PeerId (org.apache.ignite.raft.jraft.entity.PeerId)1 RpcServer (org.apache.ignite.raft.jraft.rpc.RpcServer)1 IgniteRpcClient (org.apache.ignite.raft.jraft.rpc.impl.IgniteRpcClient)1