Search in sources :

Example 1 with TopologyEventHandler

use of org.apache.ignite.network.TopologyEventHandler 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)

Example 2 with TopologyEventHandler

use of org.apache.ignite.network.TopologyEventHandler in project ignite-3 by apache.

the class ItScaleCubeNetworkMessagingTest method testShutdown0.

/**
 * Tests shutdown.
 *
 * @param testInfo Test info.
 * @param forceful Whether shutdown should be forceful.
 * @throws Exception If failed.
 */
private void testShutdown0(TestInfo testInfo, boolean forceful) throws Exception {
    testCluster = new Cluster(2, testInfo);
    testCluster.startAwait();
    ClusterService alice = testCluster.members.get(0);
    ClusterService bob = testCluster.members.get(1);
    String aliceName = alice.localConfiguration().getName();
    var aliceShutdownLatch = new CountDownLatch(1);
    bob.topologyService().addEventHandler(new TopologyEventHandler() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void onAppeared(ClusterNode member) {
        // No-op.
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public void onDisappeared(ClusterNode member) {
            if (aliceName.equals(member.name())) {
                aliceShutdownLatch.countDown();
            }
        }
    });
    if (forceful) {
        stopForcefully(alice);
    } else {
        alice.stop();
    }
    boolean aliceShutdownReceived = aliceShutdownLatch.await(forceful ? 10 : 3, TimeUnit.SECONDS);
    assertTrue(aliceShutdownReceived);
    Collection<ClusterNode> networkMembers = bob.topologyService().allMembers();
    assertEquals(1, networkMembers.size());
}
Also used : ClusterNode(org.apache.ignite.network.ClusterNode) ClusterService(org.apache.ignite.network.ClusterService) TopologyEventHandler(org.apache.ignite.network.TopologyEventHandler) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

ClusterNode (org.apache.ignite.network.ClusterNode)2 ClusterService (org.apache.ignite.network.ClusterService)2 TopologyEventHandler (org.apache.ignite.network.TopologyEventHandler)2 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 CountDownLatch (java.util.concurrent.CountDownLatch)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