use of org.apache.ignite.raft.jraft.rpc.impl.IgniteRpcClient in project ignite-3 by apache.
the class ItCliServiceTest method setup.
/**
* Executes before each test.
*/
@BeforeEach
public void setup(TestInfo testInfo, @WorkDirectory Path dataPath) throws Exception {
LOG.info(">>>>>>>>>>>>>>> Start test method: " + testInfo.getDisplayName());
List<PeerId> peers = TestUtils.generatePeers(3);
LinkedHashSet<PeerId> learners = new LinkedHashSet<>();
// 2 learners
for (int i = 0; i < 2; i++) {
learners.add(new PeerId(TestUtils.getLocalAddress(), TestUtils.INIT_PORT + LEARNER_PORT_STEP + i));
}
cluster = new TestCluster(groupId, dataPath.toString(), peers, learners, ELECTION_TIMEOUT_MILLIS, testInfo);
for (PeerId peer : peers) {
cluster.start(peer.getEndpoint());
}
for (PeerId peer : learners) {
cluster.startLearner(peer);
}
cluster.waitLeader();
cluster.ensureLeader(cluster.getLeader());
cliService = new CliServiceImpl();
conf = new Configuration(peers, learners);
CliOptions opts = new CliOptions();
clientExecutor = JRaftUtils.createClientExecutor(opts, "client");
opts.setClientExecutor(clientExecutor);
List<NetworkAddress> addressList = peers.stream().map(PeerId::getEndpoint).map(JRaftUtils::addressFromEndpoint).collect(toList());
ClusterService clientSvc = ClusterServiceTestUtils.clusterService(testInfo, TestUtils.INIT_PORT - 1, new StaticNodeFinder(addressList), new TestScaleCubeClusterServiceFactory());
clientSvc.start();
IgniteRpcClient rpcClient = new IgniteRpcClient(clientSvc) {
@Override
public void shutdown() {
super.shutdown();
clientSvc.stop();
}
};
opts.setRpcClient(rpcClient);
assertTrue(cliService.init(opts));
}
use of org.apache.ignite.raft.jraft.rpc.impl.IgniteRpcClient 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;
}
use of org.apache.ignite.raft.jraft.rpc.impl.IgniteRpcClient 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.rpc.impl.IgniteRpcClient 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();
}
}
use of org.apache.ignite.raft.jraft.rpc.impl.IgniteRpcClient in project ignite-3 by apache.
the class IgniteRpcTest method waitForTopology.
/**
* {@inheritDoc}
*/
@Override
protected boolean waitForTopology(RpcClient client, int expected, long timeout) {
IgniteRpcClient client0 = (IgniteRpcClient) client;
ClusterService service = client0.clusterService();
return waitForTopology(service, expected, timeout);
}
Aggregations