Search in sources :

Example 1 with ClusterNode

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

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

the class ItScaleCubeNetworkMessagingTest method testSendMessageToSelf.

/**
 * Sends a message from a node to itself and verifies that it gets delivered successfully.
 *
 * @throws Exception in case of errors.
 */
@Test
public void testSendMessageToSelf(TestInfo testInfo) throws Exception {
    testCluster = new Cluster(1, testInfo);
    testCluster.startAwait();
    ClusterService member = testCluster.members.get(0);
    ClusterNode self = member.topologyService().localMember();
    class Data {

        private final TestMessage message;

        private final NetworkAddress sender;

        private final Long correlationId;

        private Data(TestMessage message, NetworkAddress sender, Long correlationId) {
            this.message = message;
            this.sender = sender;
            this.correlationId = correlationId;
        }
    }
    var dataFuture = new CompletableFuture<Data>();
    member.messagingService().addMessageHandler(TestMessageTypes.class, (message, senderAddr, correlationId) -> dataFuture.complete(new Data((TestMessage) message, senderAddr, correlationId)));
    var requestMessage = messageFactory.testMessage().msg("request").build();
    member.messagingService().send(self, requestMessage);
    Data actualData = dataFuture.get(3, TimeUnit.SECONDS);
    assertThat(actualData.message.msg(), is(requestMessage.msg()));
    assertThat(actualData.sender.consistentId(), is(self.name()));
    assertNull(actualData.correlationId);
}
Also used : ClusterNode(org.apache.ignite.network.ClusterNode) CompletableFuture(java.util.concurrent.CompletableFuture) ClusterService(org.apache.ignite.network.ClusterService) NetworkAddress(org.apache.ignite.network.NetworkAddress) TestMessage(org.apache.ignite.network.TestMessage) Test(org.junit.jupiter.api.Test)

Example 3 with ClusterNode

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

Example 4 with ClusterNode

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

the class MessageServiceImpl method onMessage.

private void onMessage(NetworkMessage msg, NetworkAddress addr, @Nullable Long correlationId) {
    assert msg.groupType() == GROUP_TYPE : "unexpected message group grpType=" + msg.groupType();
    ClusterNode node = topSrvc.getByAddress(addr);
    if (node == null) {
        LOG.warn("Received a message from a node that has not yet" + " joined the cluster: addr={}, msg={}", addr, msg);
        return;
    }
    onMessage(node.id(), msg);
}
Also used : ClusterNode(org.apache.ignite.network.ClusterNode)

Example 5 with ClusterNode

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

the class MockedStructuresTest method mockManagers.

// todo copy-paste from TableManagerTest will be removed after https://issues.apache.org/jira/browse/IGNITE-16050
/**
 * Instantiates a table and prepares Table manager.
 *
 * @return Table manager.
 */
private TableManager mockManagers() throws NodeStoppingException {
    when(rm.prepareRaftGroup(any(), any(), any())).thenAnswer(mock -> {
        RaftGroupService raftGrpSrvcMock = mock(RaftGroupService.class);
        when(raftGrpSrvcMock.leader()).thenReturn(new Peer(new NetworkAddress("localhost", 47500)));
        return completedFuture(raftGrpSrvcMock);
    });
    when(ts.getByAddress(any(NetworkAddress.class))).thenReturn(new ClusterNode(UUID.randomUUID().toString(), "node0", new NetworkAddress("localhost", 47500)));
    try (MockedStatic<SchemaUtils> schemaServiceMock = mockStatic(SchemaUtils.class)) {
        schemaServiceMock.when(() -> SchemaUtils.prepareSchemaDescriptor(anyInt(), any())).thenReturn(mock(SchemaDescriptor.class));
    }
    when(cs.messagingService()).thenAnswer(invocation -> {
        MessagingService ret = mock(MessagingService.class);
        return ret;
    });
    when(cs.localConfiguration()).thenAnswer(invocation -> {
        ClusterLocalConfiguration ret = mock(ClusterLocalConfiguration.class);
        when(ret.getName()).thenReturn("node1");
        return ret;
    });
    when(cs.topologyService()).thenAnswer(invocation -> {
        TopologyService ret = mock(TopologyService.class);
        when(ret.localMember()).thenReturn(new ClusterNode("1", "node1", null));
        return ret;
    });
    TableManager tableManager = createTableManager();
    return tableManager;
}
Also used : ClusterNode(org.apache.ignite.network.ClusterNode) SchemaUtils(org.apache.ignite.internal.schema.SchemaUtils) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) NetworkAddress(org.apache.ignite.network.NetworkAddress) RaftGroupService(org.apache.ignite.raft.client.service.RaftGroupService) Peer(org.apache.ignite.raft.client.Peer) TableManager(org.apache.ignite.internal.table.distributed.TableManager) ClusterLocalConfiguration(org.apache.ignite.network.ClusterLocalConfiguration) MessagingService(org.apache.ignite.network.MessagingService) TopologyService(org.apache.ignite.network.TopologyService)

Aggregations

ClusterNode (org.apache.ignite.network.ClusterNode)25 NetworkAddress (org.apache.ignite.network.NetworkAddress)11 List (java.util.List)10 ClusterService (org.apache.ignite.network.ClusterService)9 Loza (org.apache.ignite.internal.raft.Loza)8 TopologyService (org.apache.ignite.network.TopologyService)8 RaftGroupService (org.apache.ignite.raft.client.service.RaftGroupService)8 Test (org.junit.jupiter.api.Test)8 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 Int2ObjectOpenHashMap (it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap)6 Map (java.util.Map)6 UUID (java.util.UUID)6 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)6 IgniteLogger (org.apache.ignite.lang.IgniteLogger)6 HashSet (java.util.HashSet)5 Set (java.util.Set)5 CompletableFuture (java.util.concurrent.CompletableFuture)5 Consumer (java.util.function.Consumer)5 Collectors (java.util.stream.Collectors)5