Search in sources :

Example 11 with TcpDiscoveryNode

use of org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode in project ignite by apache.

the class ServerImpl method nodeAlive.

/**
 * Checks whether a node is alive or not.
 *
 * @param nodeId Node ID.
 * @return {@code True} if node is in the ring and is not being removed from.
 */
private boolean nodeAlive(UUID nodeId) {
    // Is node alive or about to be removed from the ring?
    TcpDiscoveryNode node = ring.node(nodeId);
    boolean nodeAlive = node != null && node.visible();
    if (nodeAlive) {
        synchronized (mux) {
            nodeAlive = !F.transform(failedNodes.keySet(), F.node2id()).contains(nodeId) && !F.transform(leavingNodes, F.node2id()).contains(nodeId);
        }
    }
    return nodeAlive;
}
Also used : TcpDiscoveryNode(org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode)

Example 12 with TcpDiscoveryNode

use of org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode in project ignite by apache.

the class ServerImpl method processMessageFailedNodes.

/**
 * Adds failed nodes specified in the received message to the local failed nodes list.
 *
 * @param msg Message.
 */
private void processMessageFailedNodes(TcpDiscoveryAbstractMessage msg) {
    Collection<UUID> msgFailedNodes = msg.failedNodes();
    if (msgFailedNodes != null) {
        UUID sndId = msg.senderNodeId();
        if (sndId != null) {
            if (ring.node(sndId) == null) {
                if (log.isDebugEnabled()) {
                    log.debug("Ignore message failed nodes, sender node is not alive [nodeId=" + sndId + ", failedNodes=" + msgFailedNodes + ']');
                }
                return;
            }
            synchronized (mux) {
                for (TcpDiscoveryNode failedNode : failedNodes.keySet()) {
                    if (failedNode.id().equals(sndId)) {
                        if (log.isDebugEnabled()) {
                            log.debug("Ignore message failed nodes, sender node is in fail list [nodeId=" + sndId + ", failedNodes=" + msgFailedNodes + ']');
                        }
                        return;
                    }
                }
            }
        }
        for (UUID nodeId : msgFailedNodes) {
            TcpDiscoveryNode failedNode = ring.node(nodeId);
            if (failedNode != null) {
                if (!failedNode.isLocal()) {
                    boolean added = false;
                    synchronized (mux) {
                        if (!failedNodes.containsKey(failedNode)) {
                            failedNodes.put(failedNode, msg.senderNodeId() != null ? msg.senderNodeId() : getLocalNodeId());
                            added = true;
                        }
                    }
                    if (added && log.isDebugEnabled())
                        log.debug("Added node to failed nodes list [node=" + failedNode + ", msg=" + msg + ']');
                }
            }
        }
    }
}
Also used : UUID(java.util.UUID) TcpDiscoveryNode(org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode)

Example 13 with TcpDiscoveryNode

use of org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode in project ignite by apache.

the class IgniteCacheClientNodeChangingTopologyTest method findKeys.

/**
 * Tries to find keys for two partitions: for one partition assignment should not change after node join,
 * for another primary node should change.
 *
 * @param ignite Ignite.
 * @param nodes Current nodes.
 * @return Found keys.
 */
private IgniteBiTuple<Integer, Integer> findKeys(Ignite ignite, ClusterNode... nodes) {
    ClusterNode newNode = new TcpDiscoveryNode();
    GridTestUtils.setFieldValue(newNode, "consistentId", getTestIgniteInstanceName(4));
    GridTestUtils.setFieldValue(newNode, "id", UUID.randomUUID());
    List<ClusterNode> topNodes = new ArrayList<>();
    Collections.addAll(topNodes, nodes);
    topNodes.add(newNode);
    DiscoveryEvent discoEvt = new DiscoveryEvent(newNode, "", EventType.EVT_NODE_JOINED, newNode);
    final long topVer = ignite.cluster().topologyVersion();
    GridAffinityFunctionContextImpl ctx = new GridAffinityFunctionContextImpl(topNodes, null, discoEvt, new AffinityTopologyVersion(topVer + 1), 1);
    AffinityFunction affFunc = ignite.cache(DEFAULT_CACHE_NAME).getConfiguration(CacheConfiguration.class).getAffinity();
    List<List<ClusterNode>> newAff = affFunc.assignPartitions(ctx);
    List<List<ClusterNode>> curAff = ((IgniteKernal) ignite).context().cache().internalCache(DEFAULT_CACHE_NAME).context().affinity().assignments(new AffinityTopologyVersion(topVer));
    Integer key1 = null;
    Integer key2 = null;
    Affinity<Integer> aff = ignite.affinity(DEFAULT_CACHE_NAME);
    for (int i = 0; i < curAff.size(); i++) {
        if (key1 == null) {
            List<ClusterNode> oldNodes = curAff.get(i);
            List<ClusterNode> newNodes = newAff.get(i);
            if (oldNodes.equals(newNodes))
                key1 = findKey(aff, i);
        }
        if (key2 == null) {
            ClusterNode oldPrimary = F.first(curAff.get(i));
            ClusterNode newPrimary = F.first(newAff.get(i));
            if (!oldPrimary.equals(newPrimary))
                key2 = findKey(aff, i);
        }
        if (key1 != null && key2 != null)
            break;
    }
    if (key1 == null || key2 == null)
        fail("Failed to find nodes required for test.");
    return new IgniteBiTuple<>(key1, key2);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) ArrayList(java.util.ArrayList) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridAffinityFunctionContextImpl(org.apache.ignite.internal.processors.affinity.GridAffinityFunctionContextImpl) List(java.util.List) ArrayList(java.util.ArrayList) AffinityFunction(org.apache.ignite.cache.affinity.AffinityFunction) TcpDiscoveryNode(org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 14 with TcpDiscoveryNode

use of org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode in project ignite by apache.

the class IgniteClientReconnectAbstractTest method clientRouter.

/**
 * @param client Client.
 * @return Server node client connected to.
 */
protected Ignite clientRouter(Ignite client) {
    TcpDiscoveryNode node = (TcpDiscoveryNode) client.cluster().localNode();
    assertTrue(node.isClient());
    assertNotNull(node.clientRouterNodeId());
    Ignite srv = G.ignite(node.clientRouterNodeId());
    assertNotNull(srv);
    return srv;
}
Also used : Ignite(org.apache.ignite.Ignite) TcpDiscoveryNode(org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode)

Example 15 with TcpDiscoveryNode

use of org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode in project ignite by apache.

the class AffinityFunctionExcludeNeighborsAbstractSelfTest method testAffinityMultiNode.

/**
 * @throws Exception If failed.
 */
public void testAffinityMultiNode() throws Exception {
    int grids = 9;
    startGrids(grids);
    try {
        Object key = 12345;
        int copies = backups + 1;
        for (int i = 0; i < grids; i++) {
            final Ignite g = grid(i);
            Affinity<Object> aff = g.affinity(DEFAULT_CACHE_NAME);
            List<TcpDiscoveryNode> top = new ArrayList<>();
            for (ClusterNode node : g.cluster().nodes()) top.add((TcpDiscoveryNode) node);
            Collections.sort(top);
            assertEquals(grids, top.size());
            int idx = 1;
            for (ClusterNode n : top) {
                assertEquals(idx, n.order());
                idx++;
            }
            Collection<? extends ClusterNode> affNodes = nodes(aff, key);
            info("Affinity picture for grid [i=" + i + ", aff=" + U.toShortString(affNodes));
            assertEquals(copies, affNodes.size());
            Set<String> macs = new HashSet<>();
            for (ClusterNode node : affNodes) macs.add((String) node.attribute(IgniteNodeAttributes.ATTR_MACS));
            assertEquals(copies, macs.size());
        }
    } finally {
        stopAllGrids();
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) ArrayList(java.util.ArrayList) Ignite(org.apache.ignite.Ignite) TcpDiscoveryNode(org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode) HashSet(java.util.HashSet)

Aggregations

TcpDiscoveryNode (org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode)36 Ignite (org.apache.ignite.Ignite)12 ClusterNode (org.apache.ignite.cluster.ClusterNode)11 UUID (java.util.UUID)10 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)8 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)7 IOException (java.io.IOException)6 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)6 TcpDiscoveryVmIpFinder (org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder)6 ArrayList (java.util.ArrayList)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 Event (org.apache.ignite.events.Event)5 IgniteException (org.apache.ignite.IgniteException)4 Nullable (org.jetbrains.annotations.Nullable)4 Socket (java.net.Socket)3 SocketTimeoutException (java.net.SocketTimeoutException)3 Collection (java.util.Collection)3 IgniteClientDisconnectedException (org.apache.ignite.IgniteClientDisconnectedException)3 StreamCorruptedException (java.io.StreamCorruptedException)2 InetSocketAddress (java.net.InetSocketAddress)2