use of org.apache.ignite.raft.client.Peer in project ignite-3 by apache.
the class ItMetaStorageServiceTest method prepareMetaStorage.
/**
* Prepares meta storage by instantiating corresponding raft server with {@link MetaStorageListener} and {@link
* MetaStorageServiceImpl}.
*
* @return {@link MetaStorageService} instance.
*/
private MetaStorageService prepareMetaStorage() throws Exception {
List<Peer> peers = List.of(new Peer(cluster.get(0).topologyService().localMember().address()));
metaStorageRaftSrv = new RaftServerImpl(cluster.get(0), FACTORY);
metaStorageRaftSrv.start();
metaStorageRaftSrv.startRaftGroup(METASTORAGE_RAFT_GROUP_NAME, new MetaStorageListener(mockStorage), peers);
metaStorageRaftGrpSvc = RaftGroupServiceImpl.start(METASTORAGE_RAFT_GROUP_NAME, cluster.get(1), FACTORY, 10_000, peers, true, 200, executor).get(3, TimeUnit.SECONDS);
return new MetaStorageServiceImpl(metaStorageRaftGrpSvc, NODE_ID_0);
}
use of org.apache.ignite.raft.client.Peer in project ignite-3 by apache.
the class ItMetaStorageRaftGroupTest method prepareJraftMetaStorages.
private List<Pair<RaftServer, RaftGroupService>> prepareJraftMetaStorages(AtomicInteger replicatorStartedCounter, AtomicInteger replicatorStoppedCounter) throws InterruptedException, ExecutionException {
List<Peer> peers = new ArrayList<>();
cluster.forEach(c -> peers.add(new Peer(c.topologyService().localMember().address())));
assertTrue(cluster.size() > 1);
NodeOptions opt1 = new NodeOptions();
opt1.setReplicationStateListeners(List.of(new UserReplicatorStateListener(replicatorStartedCounter, replicatorStoppedCounter)));
NodeOptions opt2 = new NodeOptions();
opt2.setReplicationStateListeners(List.of(new UserReplicatorStateListener(replicatorStartedCounter, replicatorStoppedCounter)));
NodeOptions opt3 = new NodeOptions();
opt3.setReplicationStateListeners(List.of(new UserReplicatorStateListener(replicatorStartedCounter, replicatorStoppedCounter)));
metaStorageRaftSrv1 = new JraftServerImpl(cluster.get(0), dataPath, opt1);
metaStorageRaftSrv2 = new JraftServerImpl(cluster.get(1), dataPath, opt2);
metaStorageRaftSrv3 = new JraftServerImpl(cluster.get(2), dataPath, opt3);
metaStorageRaftSrv1.start();
metaStorageRaftSrv2.start();
metaStorageRaftSrv3.start();
metaStorageRaftSrv1.startRaftGroup(METASTORAGE_RAFT_GROUP_NAME, new MetaStorageListener(mockStorage), peers);
metaStorageRaftSrv2.startRaftGroup(METASTORAGE_RAFT_GROUP_NAME, new MetaStorageListener(mockStorage), peers);
metaStorageRaftSrv3.startRaftGroup(METASTORAGE_RAFT_GROUP_NAME, new MetaStorageListener(mockStorage), peers);
metaStorageRaftGrpSvc1 = RaftGroupServiceImpl.start(METASTORAGE_RAFT_GROUP_NAME, cluster.get(0), FACTORY, 10_000, peers, true, 200, executor).get();
metaStorageRaftGrpSvc2 = RaftGroupServiceImpl.start(METASTORAGE_RAFT_GROUP_NAME, cluster.get(1), FACTORY, 10_000, peers, true, 200, executor).get();
metaStorageRaftGrpSvc3 = RaftGroupServiceImpl.start(METASTORAGE_RAFT_GROUP_NAME, cluster.get(2), FACTORY, 10_000, peers, true, 200, executor).get();
assertTrue(TestUtils.waitForCondition(() -> sameLeaders(metaStorageRaftGrpSvc1, metaStorageRaftGrpSvc2, metaStorageRaftGrpSvc3), 10_000), "Leaders: " + metaStorageRaftGrpSvc1.leader() + " " + metaStorageRaftGrpSvc2.leader() + " " + metaStorageRaftGrpSvc3.leader());
List<Pair<RaftServer, RaftGroupService>> raftServersRaftGroups = new ArrayList<>();
raftServersRaftGroups.add(new Pair<>(metaStorageRaftSrv1, metaStorageRaftGrpSvc1));
raftServersRaftGroups.add(new Pair<>(metaStorageRaftSrv2, metaStorageRaftGrpSvc2));
raftServersRaftGroups.add(new Pair<>(metaStorageRaftSrv3, metaStorageRaftGrpSvc3));
return raftServersRaftGroups;
}
use of org.apache.ignite.raft.client.Peer in project ignite-3 by apache.
the class ItInternalTableScanTest method setUp.
/**
* Prepare test environment.
* <ol>
* <li>Start network node.</li>
* <li>Start raft server.</li>
* <li>Prepare partitioned raft group.</li>
* <li>Prepare partitioned raft group service.</li>
* <li>Prepare internal table as a test object.</li>
* </ol>
*
* @throws Exception If any.
*/
@BeforeEach
public void setUp(TestInfo testInfo) throws Exception {
NetworkAddress nodeNetworkAddress = new NetworkAddress("localhost", 20_000);
network = ClusterServiceTestUtils.clusterService(testInfo, 20_000, new StaticNodeFinder(List.of(nodeNetworkAddress)), NETWORK_FACTORY);
network.start();
raftSrv = new RaftServerImpl(network, FACTORY);
raftSrv.start();
String grpName = "test_part_grp";
List<Peer> conf = List.of(new Peer(nodeNetworkAddress));
mockStorage = mock(PartitionStorage.class);
txManager = new TxManagerImpl(network, new HeapLockManager());
txManager.start();
UUID tblId = UUID.randomUUID();
raftSrv.startRaftGroup(grpName, new PartitionListener(tblId, new VersionedRowStore(mockStorage, txManager) {
@Override
protected Pair<BinaryRow, BinaryRow> versionedRow(@Nullable DataRow row, Timestamp timestamp) {
// Return as is.
return new Pair<>(new ByteBufferRow(row.valueBytes()), null);
}
}), conf);
executor = new ScheduledThreadPoolExecutor(20, new NamedThreadFactory(Loza.CLIENT_POOL_NAME));
RaftGroupService raftGrpSvc = RaftGroupServiceImpl.start(RAFT_GRP_ID, network, FACTORY, 10_000, conf, true, 200, executor).get(3, TimeUnit.SECONDS);
internalTbl = new InternalTableImpl(TEST_TABLE_NAME, tblId, Int2ObjectMaps.singleton(0, raftGrpSvc), 1, NetworkAddress::toString, txManager, mock(TableStorage.class));
}
use of org.apache.ignite.raft.client.Peer in project ignite-3 by apache.
the class ItTxDistributedTestSingleNode method getLeader.
/**
* Returns a raft manager for a group.
*
* @param svc The service.
* @return Raft manager hosting a leader for group.
*/
protected Loza getLeader(RaftGroupService svc) {
Peer leader = svc.leader();
assertNotNull(leader);
return raftServers.get(svc.clusterService().topologyService().getByAddress(leader.address()));
}
use of org.apache.ignite.raft.client.Peer in project ignite-3 by apache.
the class RaftGroupServiceImpl method addLearners.
/**
* {@inheritDoc}
*/
@Override
public CompletableFuture<Void> addLearners(List<Peer> learners) {
Peer leader = this.leader;
if (leader == null)
return refreshLeader().thenCompose(res -> addLearners(learners));
List<String> lrns = learners.stream().map(p -> PeerId.fromPeer(p).toString()).collect(Collectors.toList());
AddLearnersRequest req = factory.addLearnersRequest().groupId(groupId).learnersList(lrns).build();
CompletableFuture<LearnersOpResponse> fut = new CompletableFuture<>();
sendWithRetry(leader, req, currentTimeMillis() + timeout, fut);
return fut.thenApply(resp -> {
this.learners = parsePeerList(resp.newLearnersList());
return null;
});
}
Aggregations