Search in sources :

Example 1 with TestIgniteRpcServer

use of org.apache.ignite.raft.jraft.rpc.TestIgniteRpcServer 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)

Example 2 with TestIgniteRpcServer

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

the class TestCluster method start.

public boolean start(Endpoint listenAddr, boolean emptyPeers, int snapshotIntervalSecs, boolean enableMetrics, SnapshotThrottle snapshotThrottle, RaftOptions raftOptions, int priority) throws IOException {
    this.lock.lock();
    try {
        if (this.serverMap.get(listenAddr) != null) {
            return true;
        }
        // Start node in non shared pools mode. Pools will be managed by node itself.
        NodeOptions nodeOptions = new NodeOptions();
        nodeOptions.setServerName(listenAddr.toString());
        nodeOptions.setElectionTimeoutMs(this.electionTimeoutMs);
        nodeOptions.setEnableMetrics(enableMetrics);
        nodeOptions.setSnapshotThrottle(snapshotThrottle);
        nodeOptions.setSnapshotIntervalSecs(snapshotIntervalSecs);
        nodeOptions.setServiceFactory(this.raftServiceFactory);
        if (raftOptions != null) {
            nodeOptions.setRaftOptions(raftOptions);
        }
        String serverDataPath = this.dataPath + File.separator + listenAddr.toString().replace(':', '_');
        new File(serverDataPath).mkdirs();
        nodeOptions.setLogUri(serverDataPath + File.separator + "logs");
        nodeOptions.setRaftMetaUri(serverDataPath + File.separator + "meta");
        nodeOptions.setSnapshotUri(serverDataPath + File.separator + "snapshot");
        nodeOptions.setElectionPriority(priority);
        // Align rpc options with election timeout.
        nodeOptions.setRpcConnectTimeoutMs(this.electionTimeoutMs / 3);
        nodeOptions.setRpcDefaultTimeout(this.electionTimeoutMs / 2);
        // Reduce default threads count per test node.
        nodeOptions.setRaftRpcThreadPoolSize(Utils.cpus());
        nodeOptions.setTimerPoolSize(Utils.cpus() * 2);
        nodeOptions.setRpcProcessorThreadPoolSize(Utils.cpus() * 3);
        nodeOptions.setElectionTimeoutStrategy(new ExponentialBackoffTimeoutStrategy());
        MockStateMachine fsm = new MockStateMachine(listenAddr);
        nodeOptions.setFsm(fsm);
        if (!emptyPeers)
            nodeOptions.setInitialConf(new Configuration(this.peers, this.learners));
        List<NetworkAddress> addressList = (emptyPeers ? Stream.<PeerId>empty() : peers.stream()).map(PeerId::getEndpoint).map(JRaftUtils::addressFromEndpoint).collect(toList());
        NodeManager nodeManager = new NodeManager();
        ClusterService clusterService = ClusterServiceTestUtils.clusterService(testInfo, listenAddr.getPort(), new StaticNodeFinder(addressList), new TestScaleCubeClusterServiceFactory());
        var rpcClient = new IgniteRpcClient(clusterService);
        nodeOptions.setRpcClient(rpcClient);
        ExecutorService requestExecutor = JRaftUtils.createRequestExecutor(nodeOptions);
        var rpcServer = new TestIgniteRpcServer(clusterService, nodeManager, nodeOptions, requestExecutor);
        clusterService.start();
        if (optsClo != null)
            optsClo.accept(nodeOptions);
        RaftGroupService server = new RaftGroupService(this.name, new PeerId(listenAddr, 0, priority), nodeOptions, rpcServer, nodeManager) {

            @Override
            public synchronized void shutdown() {
                // This stop order is consistent with JRaftServerImpl
                rpcServer.shutdown();
                ExecutorServiceHelper.shutdownAndAwaitTermination(requestExecutor);
                super.shutdown();
                // Network service must be stopped after a node because raft initiates timeoutnowrequest on stop for faster
                // leader election.
                clusterService.stop();
            }
        };
        this.serverMap.put(listenAddr, server);
        Node node = server.start();
        this.fsms.put(new PeerId(listenAddr, 0), fsm);
        this.nodes.add((NodeImpl) node);
        return true;
    } finally {
        this.lock.unlock();
    }
}
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) Node(org.apache.ignite.raft.jraft.Node) NodeOptions(org.apache.ignite.raft.jraft.option.NodeOptions) 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) File(java.io.File) ExponentialBackoffTimeoutStrategy(org.apache.ignite.raft.jraft.util.ExponentialBackoffTimeoutStrategy) PeerId(org.apache.ignite.raft.jraft.entity.PeerId)

Aggregations

ExecutorService (java.util.concurrent.ExecutorService)2 ClusterService (org.apache.ignite.network.ClusterService)2 NetworkAddress (org.apache.ignite.network.NetworkAddress)2 StaticNodeFinder (org.apache.ignite.network.StaticNodeFinder)2 TestScaleCubeClusterServiceFactory (org.apache.ignite.network.scalecube.TestScaleCubeClusterServiceFactory)2 NodeManager (org.apache.ignite.raft.jraft.NodeManager)2 RaftGroupService (org.apache.ignite.raft.jraft.RaftGroupService)2 Configuration (org.apache.ignite.raft.jraft.conf.Configuration)2 PeerId (org.apache.ignite.raft.jraft.entity.PeerId)2 TestIgniteRpcServer (org.apache.ignite.raft.jraft.rpc.TestIgniteRpcServer)2 IgniteRpcClient (org.apache.ignite.raft.jraft.rpc.impl.IgniteRpcClient)2 File (java.io.File)1 Node (org.apache.ignite.raft.jraft.Node)1 NodeOptions (org.apache.ignite.raft.jraft.option.NodeOptions)1 IgniteRpcServer (org.apache.ignite.raft.jraft.rpc.impl.IgniteRpcServer)1 ExponentialBackoffTimeoutStrategy (org.apache.ignite.raft.jraft.util.ExponentialBackoffTimeoutStrategy)1