Search in sources :

Example 31 with NetworkAddress

use of org.apache.ignite.network.NetworkAddress in project ignite-3 by apache.

the class RaftGroupServiceTest method testSnapshotExecutionFailedResponse.

/**
 * @throws Exception If failed.
 */
@Test
public void testSnapshotExecutionFailedResponse() throws Exception {
    String groupId = "test";
    mockSnapshotRequest(0);
    RaftGroupService service = RaftGroupServiceImpl.start(groupId, cluster, FACTORY, TIMEOUT, NODES, false, DELAY, executor).get(3, TimeUnit.SECONDS);
    var addr = new NetworkAddress("localhost", 8082);
    CompletableFuture<Void> fut = service.snapshot(new Peer(addr));
    try {
        fut.get();
        fail();
    } catch (ExecutionException e) {
        assertTrue(e.getCause() instanceof RaftException);
    }
}
Also used : RaftException(org.apache.ignite.raft.jraft.rpc.impl.RaftException) NetworkAddress(org.apache.ignite.network.NetworkAddress) RaftGroupService(org.apache.ignite.raft.client.service.RaftGroupService) Peer(org.apache.ignite.raft.client.Peer) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test)

Example 32 with NetworkAddress

use of org.apache.ignite.network.NetworkAddress 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

NetworkAddress (org.apache.ignite.network.NetworkAddress)32 ClusterService (org.apache.ignite.network.ClusterService)18 RaftGroupService (org.apache.ignite.raft.client.service.RaftGroupService)12 StaticNodeFinder (org.apache.ignite.network.StaticNodeFinder)11 Peer (org.apache.ignite.raft.client.Peer)11 Test (org.junit.jupiter.api.Test)11 BeforeEach (org.junit.jupiter.api.BeforeEach)9 ClusterNode (org.apache.ignite.network.ClusterNode)8 List (java.util.List)7 ArrayList (java.util.ArrayList)6 ExecutionException (java.util.concurrent.ExecutionException)6 JraftServerImpl (org.apache.ignite.internal.raft.server.impl.JraftServerImpl)6 TestScaleCubeClusterServiceFactory (org.apache.ignite.network.scalecube.TestScaleCubeClusterServiceFactory)6 Path (java.nio.file.Path)5 CompletableFuture (java.util.concurrent.CompletableFuture)5 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)5 InternalTableImpl (org.apache.ignite.internal.table.distributed.storage.InternalTableImpl)5 NamedThreadFactory (org.apache.ignite.internal.thread.NamedThreadFactory)5 TxManager (org.apache.ignite.internal.tx.TxManager)5 PeerId (org.apache.ignite.raft.jraft.entity.PeerId)5