Search in sources :

Example 21 with NodeOptions

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

the class ItJraftCounterServerTest method startServer.

/**
 * Starts server.
 *
 * @param idx The index.
 * @param clo Init closure.
 * @param cons Node options updater.
 *
 * @return Raft server instance.
 */
private JraftServerImpl startServer(int idx, Consumer<RaftServer> clo, Consumer<NodeOptions> cons) {
    var addr = new NetworkAddress(getLocalAddress(), PORT);
    ClusterService service = clusterService(PORT + idx, List.of(addr), true);
    NodeOptions opts = new NodeOptions();
    cons.accept(opts);
    JraftServerImpl server = new JraftServerImpl(service, dataPath, opts) {

        @Override
        public void stop() {
            servers.remove(this);
            super.stop();
            service.stop();
        }
    };
    server.start();
    clo.accept(server);
    servers.add(server);
    assertTrue(waitForTopology(service, servers.size(), 15_000));
    return server;
}
Also used : ClusterService(org.apache.ignite.network.ClusterService) NetworkAddress(org.apache.ignite.network.NetworkAddress) NodeOptions(org.apache.ignite.raft.jraft.option.NodeOptions) JraftServerImpl(org.apache.ignite.internal.raft.server.impl.JraftServerImpl)

Example 22 with NodeOptions

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

the class JraftServerImpl method startRaftGroup.

/**
 * {@inheritDoc}
 */
@Override
public synchronized boolean startRaftGroup(String groupId, RaftGroupListener lsnr, @Nullable List<Peer> initialConf) {
    if (groups.containsKey(groupId)) {
        return false;
    }
    // Thread pools are shared by all raft groups.
    NodeOptions nodeOptions = opts.copy();
    Path serverDataPath = getServerDataPath(groupId);
    try {
        Files.createDirectories(serverDataPath);
    } catch (IOException e) {
        throw new IgniteInternalException(e);
    }
    nodeOptions.setLogUri(serverDataPath.resolve("logs").toString());
    nodeOptions.setRaftMetaUri(serverDataPath.resolve("meta").toString());
    nodeOptions.setSnapshotUri(serverDataPath.resolve("snapshot").toString());
    nodeOptions.setFsm(new DelegatingStateMachine(lsnr));
    if (initialConf != null) {
        List<PeerId> mapped = initialConf.stream().map(PeerId::fromPeer).collect(Collectors.toList());
        nodeOptions.setInitialConf(new Configuration(mapped, null));
    }
    IgniteRpcClient client = new IgniteRpcClient(service);
    nodeOptions.setRpcClient(client);
    NetworkAddress addr = service.topologyService().localMember().address();
    var peerId = new PeerId(addr.host(), addr.port(), 0, ElectionPriority.DISABLED);
    var server = new RaftGroupService(groupId, peerId, nodeOptions, rpcServer, nodeManager);
    server.start();
    groups.put(groupId, server);
    return true;
}
Also used : Path(java.nio.file.Path) Configuration(org.apache.ignite.raft.jraft.conf.Configuration) NetworkAddress(org.apache.ignite.network.NetworkAddress) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) IgniteRpcClient(org.apache.ignite.raft.jraft.rpc.impl.IgniteRpcClient) RaftGroupService(org.apache.ignite.raft.jraft.RaftGroupService) NodeOptions(org.apache.ignite.raft.jraft.option.NodeOptions) IOException(java.io.IOException) PeerId(org.apache.ignite.raft.jraft.entity.PeerId)

Example 23 with NodeOptions

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

the class SnapshotExecutorTest method testNotDoSnapshotWithIntervalDist.

@Test
public void testNotDoSnapshotWithIntervalDist() throws Exception {
    final NodeOptions nodeOptions = new NodeOptions();
    nodeOptions.setSnapshotLogIndexMargin(10);
    ExecutorService testExecutor = JRaftUtils.createExecutor("test-executor", Utils.cpus());
    executorService = testExecutor;
    nodeOptions.setCommonExecutor(testExecutor);
    Mockito.when(node.getOptions()).thenReturn(nodeOptions);
    Mockito.when(fSMCaller.getLastAppliedIndex()).thenReturn(1L);
    executor.doSnapshot(null);
    executor.join();
    assertEquals(0, executor.getLastSnapshotTerm());
    assertEquals(0, executor.getLastSnapshotIndex());
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) NodeOptions(org.apache.ignite.raft.jraft.option.NodeOptions) Test(org.junit.jupiter.api.Test)

Example 24 with NodeOptions

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

the class LogManagerTest method setup.

@BeforeEach
public void setup() throws Exception {
    this.confManager = new ConfigurationManager();
    this.raftOptions = new RaftOptions();
    this.logStorage = newLogStorage(raftOptions);
    this.logManager = new LogManagerImpl();
    final LogManagerOptions opts = new LogManagerOptions();
    NodeOptions nodeOptions = new NodeOptions();
    executor = JRaftUtils.createExecutor("test-executor", Utils.cpus());
    nodeOptions.setCommonExecutor(executor);
    Mockito.when(node.getOptions()).thenReturn(nodeOptions);
    opts.setConfigurationManager(this.confManager);
    opts.setLogEntryCodecFactory(LogEntryV1CodecFactory.getInstance());
    opts.setFsmCaller(this.fsmCaller);
    opts.setNode(node);
    opts.setNodeMetrics(new NodeMetrics(false));
    opts.setLogStorage(this.logStorage);
    opts.setRaftOptions(raftOptions);
    opts.setGroupId("TestSrv");
    opts.setLogManagerDisruptor(disruptor = new StripedDisruptor<>("TestLogManagerDisruptor", 1024, () -> new LogManagerImpl.StableClosureEvent(), 1));
    assertTrue(this.logManager.init(opts));
}
Also used : RaftOptions(org.apache.ignite.raft.jraft.option.RaftOptions) NodeMetrics(org.apache.ignite.raft.jraft.core.NodeMetrics) LogManagerOptions(org.apache.ignite.raft.jraft.option.LogManagerOptions) NodeOptions(org.apache.ignite.raft.jraft.option.NodeOptions) ConfigurationManager(org.apache.ignite.raft.jraft.conf.ConfigurationManager) StripedDisruptor(org.apache.ignite.raft.jraft.disruptor.StripedDisruptor) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 25 with NodeOptions

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

the class CopySessionTest method setup.

@BeforeEach
public void setup() {
    this.timerManager = new TimerManager(5);
    this.copyOpts = new CopyOptions();
    this.raftOpts = new RaftOptions();
    this.rb = raftOpts.getRaftMessagesFactory().getFileRequest().readerId(99).filename("data");
    this.nodeOptions = new NodeOptions();
    this.nodeOptions.setCommonExecutor(Executors.newSingleThreadExecutor());
    this.session = new CopySession(rpcService, timerManager, null, raftOpts, this.nodeOptions, rb, address);
    this.session.setCopyOptions(copyOpts);
}
Also used : RaftOptions(org.apache.ignite.raft.jraft.option.RaftOptions) CopyOptions(org.apache.ignite.raft.jraft.option.CopyOptions) NodeOptions(org.apache.ignite.raft.jraft.option.NodeOptions) TimerManager(org.apache.ignite.raft.jraft.core.TimerManager) 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