Search in sources :

Example 1 with MetaStorageListener

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);
}
Also used : RocksDbKeyValueStorage(org.apache.ignite.internal.metastorage.server.persistence.RocksDbKeyValueStorage) MetaStorageListener(org.apache.ignite.internal.metastorage.server.raft.MetaStorageListener)

Example 2 with MetaStorageListener

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);
}
Also used : RaftServerImpl(org.apache.ignite.internal.raft.server.impl.RaftServerImpl) Peer(org.apache.ignite.raft.client.Peer) MetaStorageListener(org.apache.ignite.internal.metastorage.server.raft.MetaStorageListener)

Example 3 with MetaStorageListener

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;
}
Also used : Peer(org.apache.ignite.raft.client.Peer) ArrayList(java.util.ArrayList) NodeOptions(org.apache.ignite.raft.jraft.option.NodeOptions) JraftServerImpl(org.apache.ignite.internal.raft.server.impl.JraftServerImpl) MetaStorageListener(org.apache.ignite.internal.metastorage.server.raft.MetaStorageListener)

Example 4 with MetaStorageListener

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) -> {});
}
Also used : ClusterNode(org.apache.ignite.network.ClusterNode) OperationTimeoutException(org.apache.ignite.internal.metastorage.client.OperationTimeoutException) Arrays(java.util.Arrays) WatchListener(org.apache.ignite.internal.metastorage.client.WatchListener) IgniteLogger(org.apache.ignite.lang.IgniteLogger) CompactedException(org.apache.ignite.internal.metastorage.client.CompactedException) ByteUtils.bytesToLong(org.apache.ignite.internal.util.ByteUtils.bytesToLong) RaftGroupService(org.apache.ignite.raft.client.service.RaftGroupService) Map(java.util.Map) KeyCriterion(org.apache.ignite.internal.metastorage.watch.KeyCriterion) NodeConfiguration(org.apache.ignite.configuration.schemas.runner.NodeConfiguration) IgniteComponent(org.apache.ignite.internal.manager.IgniteComponent) KeyValueStorage(org.apache.ignite.internal.metastorage.server.KeyValueStorage) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) Cursor(org.apache.ignite.internal.util.Cursor) ConfigurationManager(org.apache.ignite.internal.configuration.ConfigurationManager) Collectors(java.util.stream.Collectors) If(org.apache.ignite.internal.metastorage.client.If) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) ClusterNode(org.apache.ignite.network.ClusterNode) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) MetaStorageListener(org.apache.ignite.internal.metastorage.server.raft.MetaStorageListener) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) Optional(java.util.Optional) NotNull(org.jetbrains.annotations.NotNull) Operation(org.apache.ignite.internal.metastorage.client.Operation) StatementResult(org.apache.ignite.internal.metastorage.client.StatementResult) IgniteException(org.apache.ignite.lang.IgniteException) VaultManager(org.apache.ignite.internal.vault.VaultManager) Loza(org.apache.ignite.internal.raft.Loza) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) ByteUtils.longToBytes(org.apache.ignite.internal.util.ByteUtils.longToBytes) MetaStorageServiceImpl(org.apache.ignite.internal.metastorage.client.MetaStorageServiceImpl) TopologyEventHandler(org.apache.ignite.network.TopologyEventHandler) AggregatedWatch(org.apache.ignite.internal.metastorage.watch.AggregatedWatch) IgniteUtils(org.apache.ignite.internal.util.IgniteUtils) WatchAggregator(org.apache.ignite.internal.metastorage.watch.WatchAggregator) IgniteSpinBusyLock(org.apache.ignite.internal.util.IgniteSpinBusyLock) NoSuchElementException(java.util.NoSuchElementException) Entry(org.apache.ignite.internal.metastorage.client.Entry) Iterator(java.util.Iterator) NodeStoppingException(org.apache.ignite.lang.NodeStoppingException) ByteArray(org.apache.ignite.lang.ByteArray) MetaStorageService(org.apache.ignite.internal.metastorage.client.MetaStorageService) ExecutionException(java.util.concurrent.ExecutionException) ClusterService(org.apache.ignite.network.ClusterService) Condition(org.apache.ignite.internal.metastorage.client.Condition) IgniteUuid(org.apache.ignite.lang.IgniteUuid) NodeStoppingException(org.apache.ignite.lang.NodeStoppingException) MetaStorageServiceImpl(org.apache.ignite.internal.metastorage.client.MetaStorageServiceImpl) MetaStorageListener(org.apache.ignite.internal.metastorage.server.raft.MetaStorageListener) IgniteException(org.apache.ignite.lang.IgniteException) TopologyEventHandler(org.apache.ignite.network.TopologyEventHandler)

Aggregations

MetaStorageListener (org.apache.ignite.internal.metastorage.server.raft.MetaStorageListener)4 Peer (org.apache.ignite.raft.client.Peer)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 NoSuchElementException (java.util.NoSuchElementException)1 Optional (java.util.Optional)1 Set (java.util.Set)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 NodeConfiguration (org.apache.ignite.configuration.schemas.runner.NodeConfiguration)1 ConfigurationManager (org.apache.ignite.internal.configuration.ConfigurationManager)1 IgniteComponent (org.apache.ignite.internal.manager.IgniteComponent)1 CompactedException (org.apache.ignite.internal.metastorage.client.CompactedException)1