use of org.apache.ignite.internal.metastorage.server.raft.MetaStorageListener in project ignite-3 by apache.
the class ItMetaStorageServicePersistenceTest method createListener.
/**
* {@inheritDoc}
*/
@Override
public RaftGroupListener createListener(ClusterService service, Path listenerPersistencePath) {
storage = new RocksDbKeyValueStorage(listenerPersistencePath);
storage.start();
return new MetaStorageListener(storage);
}
use of org.apache.ignite.internal.metastorage.server.raft.MetaStorageListener 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.internal.metastorage.server.raft.MetaStorageListener 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.internal.metastorage.server.raft.MetaStorageListener in project ignite-3 by apache.
the class MetaStorageManager method start.
/**
* {@inheritDoc}
*/
@Override
public void start() {
String[] metastorageNodes = this.locCfgMgr.configurationRegistry().getConfiguration(NodeConfiguration.KEY).metastorageNodes().value();
Predicate<ClusterNode> metaStorageNodesContainsLocPred = clusterNode -> Arrays.asList(metastorageNodes).contains(clusterNode.name());
if (metastorageNodes.length > 0) {
metaStorageNodesOnStart = true;
List<ClusterNode> metaStorageMembers = clusterNetSvc.topologyService().allMembers().stream().filter(metaStorageNodesContainsLocPred).collect(Collectors.toList());
// without hosting metastorage, this will be rewritten in init phase https://issues.apache.org/jira/browse/IGNITE-15114
if (metaStorageMembers.isEmpty()) {
throw new IgniteException("Cannot start meta storage manager because there is no node in the cluster that hosts meta storage.");
}
// This will be rewritten in init phase https://issues.apache.org/jira/browse/IGNITE-15114
if (metastorageNodes.length > 1) {
throw new IgniteException("Cannot start meta storage manager because it is not allowed to start several metastorage nodes.");
}
storage.start();
try {
raftGroupServiceFut = raftMgr.prepareRaftGroup(METASTORAGE_RAFT_GROUP_NAME, metaStorageMembers, () -> new MetaStorageListener(storage));
} catch (NodeStoppingException e) {
throw new AssertionError("Loza was stopped before Meta Storage manager", e);
}
this.metaStorageSvcFut = raftGroupServiceFut.thenApply(service -> new MetaStorageServiceImpl(service, clusterNetSvc.topologyService().localMember().id()));
if (hasMetastorageLocally(locCfgMgr)) {
clusterNetSvc.topologyService().addEventHandler(new TopologyEventHandler() {
@Override
public void onAppeared(ClusterNode member) {
// No-op.
}
@Override
public void onDisappeared(ClusterNode member) {
metaStorageSvcFut.thenCompose(svc -> svc.closeCursors(member.id()));
}
});
}
} else {
this.metaStorageSvcFut = new CompletableFuture<>();
}
// TODO: IGNITE-15114 Cluster initialization flow. Here we should complete metaStorageServiceFuture.
// clusterNetSvc.messagingService().addMessageHandler((message, senderAddr, correlationId) -> {});
}
Aggregations