Search in sources :

Example 26 with NodeOptions

use of org.apache.ignite.raft.jraft.option.NodeOptions in project ignite-3 by apache.

the class RemoteFileCopierTest method testInitFail.

@Test
public void testInitFail() {
    Mockito.when(rpcService.connect(new Endpoint("localhost", 8081))).thenReturn(false);
    assertFalse(copier.init("remote://localhost:8081/999", null, new SnapshotCopierOptions(rpcService, timerManager, new RaftOptions(), new NodeOptions())));
}
Also used : RaftOptions(org.apache.ignite.raft.jraft.option.RaftOptions) SnapshotCopierOptions(org.apache.ignite.raft.jraft.option.SnapshotCopierOptions) Endpoint(org.apache.ignite.raft.jraft.util.Endpoint) NodeOptions(org.apache.ignite.raft.jraft.option.NodeOptions) Test(org.junit.jupiter.api.Test)

Example 27 with NodeOptions

use of org.apache.ignite.raft.jraft.option.NodeOptions in project ignite-3 by apache.

the class ReplicatorTest method setup.

@BeforeEach
public void setup() {
    this.timerManager = new TimerManager(5);
    this.opts = new ReplicatorOptions();
    this.opts.setRaftRpcService(this.rpcService);
    this.opts.setPeerId(this.peerId);
    this.opts.setBallotBox(this.ballotBox);
    this.opts.setGroupId("test");
    this.opts.setTerm(1);
    this.opts.setServerId(new PeerId("localhost", 8082));
    this.opts.setNode(this.node);
    this.opts.setSnapshotStorage(this.snapshotStorage);
    this.opts.setTimerManager(this.timerManager);
    this.opts.setLogManager(this.logManager);
    this.opts.setDynamicHeartBeatTimeoutMs(100);
    this.opts.setElectionTimeoutMs(1000);
    NodeOptions options = new NodeOptions();
    executor = JRaftUtils.createExecutor("test-executor-", Utils.cpus());
    options.setCommonExecutor(executor);
    Mockito.when(this.logManager.getLastLogIndex()).thenReturn(10L);
    Mockito.when(this.logManager.getTerm(10)).thenReturn(1L);
    Mockito.when(this.rpcService.connect(this.peerId.getEndpoint())).thenReturn(true);
    Mockito.when(this.node.getNodeMetrics()).thenReturn(new NodeMetrics(true));
    Mockito.when(this.node.getOptions()).thenReturn(options);
    // mock send empty entries
    mockSendEmptyEntries();
    this.id = Replicator.start(this.opts, this.raftOptions);
}
Also used : ReplicatorOptions(org.apache.ignite.raft.jraft.option.ReplicatorOptions) NodeOptions(org.apache.ignite.raft.jraft.option.NodeOptions) PeerId(org.apache.ignite.raft.jraft.entity.PeerId) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 28 with NodeOptions

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

Example 29 with NodeOptions

use of org.apache.ignite.raft.jraft.option.NodeOptions in project ignite-3 by apache.

the class FSMCallerTest method setup.

@BeforeEach
public void setup() {
    this.fsmCaller = new FSMCallerImpl();
    NodeOptions options = new NodeOptions();
    executor = JRaftUtils.createExecutor("test-executor-", Utils.cpus());
    options.setCommonExecutor(executor);
    this.closureQueue = new ClosureQueueImpl(options);
    opts = new FSMCallerOptions();
    Mockito.when(this.node.getNodeMetrics()).thenReturn(new NodeMetrics(false));
    Mockito.when(this.node.getOptions()).thenReturn(options);
    opts.setNode(this.node);
    opts.setFsm(this.fsm);
    opts.setLogManager(this.logManager);
    opts.setBootstrapId(new LogId(10, 1));
    opts.setClosureQueue(this.closureQueue);
    opts.setRaftMessagesFactory(new RaftMessagesFactory());
    opts.setGroupId("TestSrv");
    opts.setfSMCallerExecutorDisruptor(disruptor = new StripedDisruptor<>("TestFSMDisruptor", 1024, () -> new FSMCallerImpl.ApplyTask(), 1));
    assertTrue(this.fsmCaller.init(opts));
}
Also used : FSMCallerOptions(org.apache.ignite.raft.jraft.option.FSMCallerOptions) ClosureQueueImpl(org.apache.ignite.raft.jraft.closure.ClosureQueueImpl) RaftMessagesFactory(org.apache.ignite.raft.jraft.RaftMessagesFactory) NodeOptions(org.apache.ignite.raft.jraft.option.NodeOptions) LogId(org.apache.ignite.raft.jraft.entity.LogId) StripedDisruptor(org.apache.ignite.raft.jraft.disruptor.StripedDisruptor) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 30 with NodeOptions

use of org.apache.ignite.raft.jraft.option.NodeOptions in project ignite-3 by apache.

the class IteratorTest method setup.

@BeforeEach
public void setup() {
    this.applyingIndex = new AtomicLong(0);
    this.closures = new ArrayList<>();
    for (int i = 0; i < 11; i++) {
        this.closures.add(new MockClosure());
        final LogEntry log = new LogEntry(EnumOutter.EntryType.ENTRY_TYPE_DATA);
        log.getId().setIndex(i);
        log.getId().setTerm(1);
        log.setData(ByteBuffer.allocate(i));
        Mockito.when(this.logManager.getEntry(i)).thenReturn(log);
    }
    this.iterImpl = new IteratorImpl(fsm, logManager, closures, 0L, 0L, 10L, applyingIndex, new NodeOptions());
    this.iter = new IteratorWrapper(iterImpl);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) NodeOptions(org.apache.ignite.raft.jraft.option.NodeOptions) LogEntry(org.apache.ignite.raft.jraft.entity.LogEntry) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

NodeOptions (org.apache.ignite.raft.jraft.option.NodeOptions)34 PeerId (org.apache.ignite.raft.jraft.entity.PeerId)17 Test (org.junit.jupiter.api.Test)14 Endpoint (org.apache.ignite.raft.jraft.util.Endpoint)13 RaftGroupService (org.apache.ignite.raft.jraft.RaftGroupService)11 BeforeEach (org.junit.jupiter.api.BeforeEach)11 Node (org.apache.ignite.raft.jraft.Node)10 Configuration (org.apache.ignite.raft.jraft.conf.Configuration)8 RaftOptions (org.apache.ignite.raft.jraft.option.RaftOptions)8 ExecutorService (java.util.concurrent.ExecutorService)5 NodeId (org.apache.ignite.raft.jraft.entity.NodeId)4 ByteBuffer (java.nio.ByteBuffer)3 ArrayList (java.util.ArrayList)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 ClusterService (org.apache.ignite.network.ClusterService)3 NetworkAddress (org.apache.ignite.network.NetworkAddress)3 SynchronizedClosure (org.apache.ignite.raft.jraft.closure.SynchronizedClosure)3 BootstrapOptions (org.apache.ignite.raft.jraft.option.BootstrapOptions)3 File (java.io.File)2 Path (java.nio.file.Path)2