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;
}
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;
}
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());
}
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));
}
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);
}
Aggregations