use of org.apache.ignite.raft.jraft.rpc.impl.IgniteRpcServer in project ignite-3 by apache.
the class JraftServerImpl method start.
/**
* {@inheritDoc}
*/
@Override
public void start() {
assert opts.isSharedPools() : "RAFT server is supposed to run in shared pools mode";
// Pre-create all pools in shared mode.
if (opts.getCommonExecutor() == null) {
opts.setCommonExecutor(JRaftUtils.createCommonExecutor(opts));
}
if (opts.getStripedExecutor() == null) {
opts.setStripedExecutor(JRaftUtils.createAppendEntriesExecutor(opts));
}
if (opts.getScheduler() == null) {
opts.setScheduler(JRaftUtils.createScheduler(opts));
}
if (opts.getClientExecutor() == null) {
opts.setClientExecutor(JRaftUtils.createClientExecutor(opts, opts.getServerName()));
}
if (opts.getVoteTimer() == null) {
opts.setVoteTimer(JRaftUtils.createTimer(opts, "JRaft-VoteTimer"));
}
if (opts.getElectionTimer() == null) {
opts.setElectionTimer(JRaftUtils.createTimer(opts, "JRaft-ElectionTimer"));
}
if (opts.getStepDownTimer() == null) {
opts.setStepDownTimer(JRaftUtils.createTimer(opts, "JRaft-StepDownTimer"));
}
if (opts.getSnapshotTimer() == null) {
opts.setSnapshotTimer(JRaftUtils.createTimer(opts, "JRaft-SnapshotTimer"));
}
requestExecutor = JRaftUtils.createRequestExecutor(opts);
rpcServer = new IgniteRpcServer(service, nodeManager, opts.getRaftMessagesFactory(), requestExecutor);
if (opts.getfSMCallerExecutorDisruptor() == null) {
opts.setfSMCallerExecutorDisruptor(new StripedDisruptor<FSMCallerImpl.ApplyTask>(NamedThreadFactory.threadPrefix(opts.getServerName(), "JRaft-FSMCaller-Disruptor"), opts.getRaftOptions().getDisruptorBufferSize(), () -> new FSMCallerImpl.ApplyTask(), opts.getStripes()));
}
if (opts.getNodeApplyDisruptor() == null) {
opts.setNodeApplyDisruptor(new StripedDisruptor<NodeImpl.LogEntryAndClosure>(NamedThreadFactory.threadPrefix(opts.getServerName(), "JRaft-NodeImpl-Disruptor"), opts.getRaftOptions().getDisruptorBufferSize(), () -> new NodeImpl.LogEntryAndClosure(), opts.getStripes()));
}
if (opts.getReadOnlyServiceDisruptor() == null) {
opts.setReadOnlyServiceDisruptor(new StripedDisruptor<ReadOnlyServiceImpl.ReadIndexEvent>(NamedThreadFactory.threadPrefix(opts.getServerName(), "JRaft-ReadOnlyService-Disruptor"), opts.getRaftOptions().getDisruptorBufferSize(), () -> new ReadOnlyServiceImpl.ReadIndexEvent(), opts.getStripes()));
}
if (opts.getLogManagerDisruptor() == null) {
opts.setLogManagerDisruptor(new StripedDisruptor<LogManagerImpl.StableClosureEvent>(NamedThreadFactory.threadPrefix(opts.getServerName(), "JRaft-LogManager-Disruptor"), opts.getRaftOptions().getDisruptorBufferSize(), () -> new LogManagerImpl.StableClosureEvent(), opts.getStripes()));
}
rpcServer.init(null);
}
use of org.apache.ignite.raft.jraft.rpc.impl.IgniteRpcServer in project ignite-3 by apache.
the class ItNodeTest method waitForTopology.
/**
* TODO asch get rid of waiting for topology IGNITE-14832
*
* @param cluster
* @param addr
* @param expected
* @param timeout
* @return
*/
private boolean waitForTopology(TestCluster cluster, Endpoint addr, int expected, long timeout) {
RaftGroupService grp = cluster.getServer(addr);
if (grp == null) {
LOG.warn("Node has not been found {}", addr);
return false;
}
RpcServer rpcServer = grp.getRpcServer();
if (!(rpcServer instanceof IgniteRpcServer))
return true;
ClusterService service = ((IgniteRpcServer) grp.getRpcServer()).clusterService();
long stop = System.currentTimeMillis() + timeout;
while (System.currentTimeMillis() < stop) {
if (service.topologyService().allMembers().size() >= expected)
return true;
try {
Thread.sleep(50);
} catch (InterruptedException e) {
return false;
}
}
return false;
}
use of org.apache.ignite.raft.jraft.rpc.impl.IgniteRpcServer 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;
}
Aggregations