Search in sources :

Example 26 with ClusterNode

use of org.apache.ignite.cluster.ClusterNode in project ignite by apache.

the class GridDeploymentClassLoader method sendResourceRequest.

/**
     * Sends resource request to all remote nodes associated with this class loader.
     *
     * @param name Resource name.
     * @return InputStream for resource or {@code null} if resource could not be found.
     */
@Nullable
private InputStream sendResourceRequest(String name) {
    assert !Thread.holdsLock(mux);
    long endTime = computeEndTime(p2pTimeout);
    Collection<UUID> nodeListCp;
    Map<UUID, IgniteUuid> nodeLdrMapCp;
    synchronized (mux) {
        // Skip requests for the previously missed classes.
        if (missedRsrcs != null && missedRsrcs.contains(name))
            return null;
        // If single-node mode, then node cannot change and we simply reuse list and map.
        // Otherwise, make copies that can be used outside synchronization.
        nodeListCp = singleNode ? nodeList : new LinkedList<>(nodeList);
        nodeLdrMapCp = singleNode ? nodeLdrMap : new HashMap<>(nodeLdrMap);
    }
    for (UUID nodeId : nodeListCp) {
        if (nodeId.equals(ctx.discovery().localNode().id()))
            // Skip local node as it is already used as parent class loader.
            continue;
        IgniteUuid ldrId = nodeLdrMapCp.get(nodeId);
        ClusterNode node = ctx.discovery().node(nodeId);
        if (node == null) {
            if (log.isDebugEnabled())
                log.debug("Found inactive node in class loader (will skip): " + nodeId);
            continue;
        }
        try {
            // Request is sent with timeout that is why we can use synchronization here.
            GridDeploymentResponse res = comm.sendResourceRequest(name, ldrId, node, endTime);
            if (res == null) {
                U.warn(log, "Failed to get resource from node (is node alive?) [nodeId=" + node.id() + ", clsLdrId=" + ldrId + ", resName=" + name + ", parentClsLdr=" + getParent() + ']');
            } else if (!res.success()) {
                synchronized (mux) {
                    // Cache unsuccessfully loaded resource.
                    if (missedRsrcs != null)
                        missedRsrcs.add(name);
                }
                // resources. So we print out INFO level message.
                if (!quiet) {
                    if (log.isInfoEnabled())
                        log.info("Failed to get resource from node [nodeId=" + node.id() + ", clsLdrId=" + ldrId + ", resName=" + name + ", parentClsLdr=" + getParent() + ", msg=" + res.errorMessage() + ']');
                } else if (log.isDebugEnabled())
                    log.debug("Failed to get resource from node [nodeId=" + node.id() + ", clsLdrId=" + ldrId + ", resName=" + name + ", parentClsLdr=" + getParent() + ", msg=" + res.errorMessage() + ']');
                // Do not ask other nodes in case of shared mode all of them should have the resource.
                return null;
            } else {
                return new ByteArrayInputStream(res.byteSource().internalArray(), 0, res.byteSource().size());
            }
        } catch (IgniteCheckedException e) {
            // by processing cancellation request.
            if (Thread.currentThread().isInterrupted()) {
                if (!quiet)
                    U.error(log, "Failed to get resource probably due to task/job cancellation: " + name, e);
                else if (log.isDebugEnabled())
                    log.debug("Failed to get resource probably due to task/job cancellation: " + name);
            } else {
                if (!quiet)
                    U.warn(log, "Failed to get resource from node (is node alive?) [nodeId=" + node.id() + ", clsLdrId=" + ldrId + ", resName=" + name + ", parentClsLdr=" + getParent() + ", err=" + e + ']');
                else if (log.isDebugEnabled())
                    log.debug("Failed to get resource from node (is node alive?) [nodeId=" + node.id() + ", clsLdrId=" + ldrId + ", resName=" + name + ", parentClsLdr=" + getParent() + ", err=" + e + ']');
            }
        }
    }
    return null;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) IgniteUuid(org.apache.ignite.lang.IgniteUuid) UUID(java.util.UUID) LinkedList(java.util.LinkedList) Nullable(org.jetbrains.annotations.Nullable)

Example 27 with ClusterNode

use of org.apache.ignite.cluster.ClusterNode in project ignite by apache.

the class GridDiscoveryManager method topologyHash.

/**
     * Gets topology hash for given set of nodes.
     *
     * @param nodes Subset of grid nodes for hashing.
     * @return Hash for given topology.
     */
public long topologyHash(Iterable<? extends ClusterNode> nodes) {
    assert nodes != null;
    Iterator<? extends ClusterNode> iter = nodes.iterator();
    if (!iter.hasNext())
        // Special case.
        return 0;
    List<String> uids = new ArrayList<>();
    for (ClusterNode node : nodes) uids.add(node.id().toString());
    Collections.sort(uids);
    CRC32 hash = new CRC32();
    for (String uuid : uids) hash.update(uuid.getBytes());
    return hash.getValue();
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) CRC32(java.util.zip.CRC32) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList)

Example 28 with ClusterNode

use of org.apache.ignite.cluster.ClusterNode in project ignite by apache.

the class GridDiscoveryManager method checkAttributes.

/**
     * Checks whether attributes of the local node are consistent with remote nodes.
     *
     * @param nodes List of remote nodes to check attributes on.
     * @throws IgniteCheckedException In case of error.
     */
private void checkAttributes(Iterable<ClusterNode> nodes) throws IgniteCheckedException {
    ClusterNode locNode = getSpi().getLocalNode();
    assert locNode != null;
    // Fetch local node attributes once.
    String locPreferIpV4 = locNode.attribute("java.net.preferIPv4Stack");
    Object locMode = locNode.attribute(ATTR_DEPLOYMENT_MODE);
    int locJvmMajVer = nodeJavaMajorVersion(locNode);
    boolean locP2pEnabled = locNode.attribute(ATTR_PEER_CLASSLOADING);
    boolean ipV4Warned = false;
    boolean jvmMajVerWarned = false;
    Boolean locMarshUseDfltSuid = locNode.attribute(ATTR_MARSHALLER_USE_DFLT_SUID);
    boolean locMarshUseDfltSuidBool = locMarshUseDfltSuid == null ? true : locMarshUseDfltSuid;
    Boolean locMarshStrSerVer2 = locNode.attribute(ATTR_MARSHALLER_USE_BINARY_STRING_SER_VER_2);
    boolean locMarshStrSerVer2Bool = locMarshStrSerVer2 == null ? false : /* turned on and added to the attributes list by default only when BinaryMarshaller is used. */
    locMarshStrSerVer2;
    boolean locDelayAssign = locNode.attribute(ATTR_LATE_AFFINITY_ASSIGNMENT);
    boolean locActiveOnStart = locNode.attribute(ATTR_ACTIVE_ON_START);
    Boolean locSrvcCompatibilityEnabled = locNode.attribute(ATTR_SERVICES_COMPATIBILITY_MODE);
    Boolean locSecurityCompatibilityEnabled = locNode.attribute(ATTR_SECURITY_COMPATIBILITY_MODE);
    for (ClusterNode n : nodes) {
        int rmtJvmMajVer = nodeJavaMajorVersion(n);
        if (locJvmMajVer != rmtJvmMajVer && !jvmMajVerWarned) {
            U.warn(log, "Local java version is different from remote [loc=" + locJvmMajVer + ", rmt=" + rmtJvmMajVer + "]");
            jvmMajVerWarned = true;
        }
        String rmtPreferIpV4 = n.attribute("java.net.preferIPv4Stack");
        if (!F.eq(rmtPreferIpV4, locPreferIpV4)) {
            if (!ipV4Warned)
                U.warn(log, "Local node's value of 'java.net.preferIPv4Stack' " + "system property differs from remote node's " + "(all nodes in topology should have identical value) " + "[locPreferIpV4=" + locPreferIpV4 + ", rmtPreferIpV4=" + rmtPreferIpV4 + ", locId8=" + U.id8(locNode.id()) + ", rmtId8=" + U.id8(n.id()) + ", rmtAddrs=" + U.addressesAsString(n) + ']', "Local and remote 'java.net.preferIPv4Stack' system properties do not match.");
            ipV4Warned = true;
        }
        // Skip data center ID check for daemon nodes.
        if (!isLocDaemon && !n.isDaemon()) {
            Object rmtMode = n.attribute(ATTR_DEPLOYMENT_MODE);
            if (!locMode.equals(rmtMode))
                throw new IgniteCheckedException("Remote node has deployment mode different from local " + "[locId8=" + U.id8(locNode.id()) + ", locMode=" + locMode + ", rmtId8=" + U.id8(n.id()) + ", rmtMode=" + rmtMode + ", rmtAddrs=" + U.addressesAsString(n) + ']');
            boolean rmtP2pEnabled = n.attribute(ATTR_PEER_CLASSLOADING);
            if (locP2pEnabled != rmtP2pEnabled)
                throw new IgniteCheckedException("Remote node has peer class loading enabled flag different from" + " local [locId8=" + U.id8(locNode.id()) + ", locPeerClassLoading=" + locP2pEnabled + ", rmtId8=" + U.id8(n.id()) + ", rmtPeerClassLoading=" + rmtP2pEnabled + ", rmtAddrs=" + U.addressesAsString(n) + ']');
        }
        Boolean rmtMarshUseDfltSuid = n.attribute(ATTR_MARSHALLER_USE_DFLT_SUID);
        boolean rmtMarshUseDfltSuidBool = rmtMarshUseDfltSuid == null ? true : rmtMarshUseDfltSuid;
        if (locMarshUseDfltSuidBool != rmtMarshUseDfltSuidBool) {
            throw new IgniteCheckedException("Local node's " + IGNITE_OPTIMIZED_MARSHALLER_USE_DEFAULT_SUID + " property value differs from remote node's value " + "(to make sure all nodes in topology have identical marshaller settings, " + "configure system property explicitly) " + "[locMarshUseDfltSuid=" + locMarshUseDfltSuid + ", rmtMarshUseDfltSuid=" + rmtMarshUseDfltSuid + ", locNodeAddrs=" + U.addressesAsString(locNode) + ", rmtNodeAddrs=" + U.addressesAsString(n) + ", locNodeId=" + locNode.id() + ", rmtNodeId=" + n.id() + ']');
        }
        Boolean rmtMarshStrSerVer2 = n.attribute(ATTR_MARSHALLER_USE_BINARY_STRING_SER_VER_2);
        boolean rmtMarshStrSerVer2Bool = rmtMarshStrSerVer2 == null ? false : rmtMarshStrSerVer2;
        if (locMarshStrSerVer2Bool != rmtMarshStrSerVer2Bool) {
            throw new IgniteCheckedException("Local node's " + IGNITE_BINARY_MARSHALLER_USE_STRING_SERIALIZATION_VER_2 + " property value differs from remote node's value " + "(to make sure all nodes in topology have identical marshaller settings, " + "configure system property explicitly) " + "[locMarshStrSerVer2=" + locMarshStrSerVer2 + ", rmtMarshStrSerVer2=" + rmtMarshStrSerVer2 + ", locNodeAddrs=" + U.addressesAsString(locNode) + ", rmtNodeAddrs=" + U.addressesAsString(n) + ", locNodeId=" + locNode.id() + ", rmtNodeId=" + n.id() + ']');
        }
        boolean rmtLateAssign = n.attribute(ATTR_LATE_AFFINITY_ASSIGNMENT);
        if (locDelayAssign != rmtLateAssign) {
            throw new IgniteCheckedException("Remote node has cache affinity assignment mode different from local " + "[locId8=" + U.id8(locNode.id()) + ", locDelayAssign=" + locDelayAssign + ", rmtId8=" + U.id8(n.id()) + ", rmtLateAssign=" + rmtLateAssign + ", rmtAddrs=" + U.addressesAsString(n) + ']');
        }
        boolean rmtActiveOnStart = n.attribute(ATTR_ACTIVE_ON_START);
        if (locActiveOnStart != rmtActiveOnStart) {
            throw new IgniteCheckedException("Remote node has active on start flag different from local " + "[locId8=" + U.id8(locNode.id()) + ", locActiveOnStart=" + locActiveOnStart + ", rmtId8=" + U.id8(n.id()) + ", rmtActiveOnStart=" + rmtActiveOnStart + ", rmtAddrs=" + U.addressesAsString(n) + ']');
        }
        Boolean rmtSrvcCompatibilityEnabled = n.attribute(ATTR_SERVICES_COMPATIBILITY_MODE);
        if (!F.eq(locSrvcCompatibilityEnabled, rmtSrvcCompatibilityEnabled)) {
            throw new IgniteCheckedException("Local node's " + IGNITE_SERVICES_COMPATIBILITY_MODE + " property value differs from remote node's value " + "(to make sure all nodes in topology have identical IgniteServices compatibility mode enabled, " + "configure system property explicitly) " + "[locSrvcCompatibilityEnabled=" + locSrvcCompatibilityEnabled + ", rmtSrvcCompatibilityEnabled=" + rmtSrvcCompatibilityEnabled + ", locNodeAddrs=" + U.addressesAsString(locNode) + ", rmtNodeAddrs=" + U.addressesAsString(n) + ", locNodeId=" + locNode.id() + ", rmtNodeId=" + n.id() + ']');
        }
        if (n.version().compareToIgnoreTimestamp(SERVICE_PERMISSIONS_SINCE) >= 0 && // Matters only if security enabled.
        ctx.security().enabled()) {
            Boolean rmtSecurityCompatibilityEnabled = n.attribute(ATTR_SECURITY_COMPATIBILITY_MODE);
            if (!F.eq(locSecurityCompatibilityEnabled, rmtSecurityCompatibilityEnabled)) {
                throw new IgniteCheckedException("Local node's " + IGNITE_SECURITY_COMPATIBILITY_MODE + " property value differs from remote node's value " + "(to make sure all nodes in topology have identical Ignite security compatibility mode enabled, " + "configure system property explicitly) " + "[locSecurityCompatibilityEnabled=" + locSecurityCompatibilityEnabled + ", rmtSecurityCompatibilityEnabled=" + rmtSecurityCompatibilityEnabled + ", locNodeAddrs=" + U.addressesAsString(locNode) + ", rmtNodeAddrs=" + U.addressesAsString(n) + ", locNodeId=" + locNode.id() + ", rmtNodeId=" + n.id() + ']');
            }
        }
        if (n.version().compareToIgnoreTimestamp(SERVICE_PERMISSIONS_SINCE) < 0 && // Matters only if security enabled.
        ctx.security().enabled() && (locSecurityCompatibilityEnabled == null || !locSecurityCompatibilityEnabled)) {
            throw new IgniteCheckedException("Remote node does not support service security permissions. " + "To be able to join to it, local node must be started with " + IGNITE_SECURITY_COMPATIBILITY_MODE + " system property set to \"true\". " + "[locSecurityCompatibilityEnabled=" + locSecurityCompatibilityEnabled + ", locNodeAddrs=" + U.addressesAsString(locNode) + ", rmtNodeAddrs=" + U.addressesAsString(n) + ", locNodeId=" + locNode.id() + ", rmtNodeId=" + n.id() + ", " + ", rmtNodeVer" + n.version() + ']');
        }
    }
    if (log.isDebugEnabled())
        log.debug("Finished node attributes consistency check.");
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Example 29 with ClusterNode

use of org.apache.ignite.cluster.ClusterNode in project ignite by apache.

the class CacheAffinitySharedManager method initAffinityOnNodeJoin.

/**
     * @param fut Exchange future.
     * @param aff Affinity.
     * @param rebalanceInfo Rebalance information.
     * @param latePrimary If {@code true} delays primary assignment if it is not owner.
     * @param affCache Already calculated assignments (to reduce data stored in history).
     * @throws IgniteCheckedException If failed.
     */
private void initAffinityOnNodeJoin(GridDhtPartitionsExchangeFuture fut, GridAffinityAssignmentCache aff, WaitRebalanceInfo rebalanceInfo, boolean latePrimary, Map<Object, List<List<ClusterNode>>> affCache) throws IgniteCheckedException {
    assert lateAffAssign;
    AffinityTopologyVersion topVer = fut.topologyVersion();
    AffinityTopologyVersion affTopVer = aff.lastVersion();
    assert affTopVer.topologyVersion() > 0 : "Affinity is not initialized [cache=" + aff.cacheName() + ", topVer=" + affTopVer + ", node=" + cctx.localNodeId() + ']';
    List<List<ClusterNode>> curAff = aff.assignments(affTopVer);
    assert aff.idealAssignment() != null : "Previous assignment is not available.";
    List<List<ClusterNode>> idealAssignment = aff.calculate(topVer, fut.discoveryEvent(), fut.discoCache());
    List<List<ClusterNode>> newAssignment = null;
    if (latePrimary) {
        for (int p = 0; p < idealAssignment.size(); p++) {
            List<ClusterNode> newNodes = idealAssignment.get(p);
            List<ClusterNode> curNodes = curAff.get(p);
            ClusterNode curPrimary = curNodes.size() > 0 ? curNodes.get(0) : null;
            ClusterNode newPrimary = newNodes.size() > 0 ? newNodes.get(0) : null;
            if (curPrimary != null && newPrimary != null && !curPrimary.equals(newPrimary)) {
                assert cctx.discovery().node(topVer, curPrimary.id()) != null : curPrimary;
                List<ClusterNode> nodes0 = latePrimaryAssignment(aff, p, curPrimary, newNodes, rebalanceInfo);
                if (newAssignment == null)
                    newAssignment = new ArrayList<>(idealAssignment);
                newAssignment.set(p, nodes0);
            }
        }
    }
    if (newAssignment == null)
        newAssignment = idealAssignment;
    aff.initialize(fut.topologyVersion(), cachedAssignment(aff, newAssignment, affCache));
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 30 with ClusterNode

use of org.apache.ignite.cluster.ClusterNode in project ignite by apache.

the class CacheAffinitySharedManager method toNodes.

/**
     * @param topVer Topology version.
     * @param ids IDs.
     * @return Nodes.
     */
private List<ClusterNode> toNodes(AffinityTopologyVersion topVer, List<UUID> ids) {
    List<ClusterNode> nodes = new ArrayList<>(ids.size());
    for (int i = 0; i < ids.size(); i++) {
        UUID id = ids.get(i);
        ClusterNode node = cctx.discovery().node(topVer, id);
        assert node != null : "Failed to get node [id=" + id + ", topVer=" + topVer + ", locNode=" + cctx.localNode() + ", allNodes=" + cctx.discovery().nodes(topVer) + ']';
        nodes.add(node);
    }
    return nodes;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) ArrayList(java.util.ArrayList) UUID(java.util.UUID)

Aggregations

ClusterNode (org.apache.ignite.cluster.ClusterNode)621 UUID (java.util.UUID)154 ArrayList (java.util.ArrayList)141 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)124 Ignite (org.apache.ignite.Ignite)121 HashMap (java.util.HashMap)80 Map (java.util.Map)72 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)72 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)66 IgniteException (org.apache.ignite.IgniteException)60 List (java.util.List)59 Collection (java.util.Collection)54 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)39 HashSet (java.util.HashSet)36 Event (org.apache.ignite.events.Event)35 CountDownLatch (java.util.concurrent.CountDownLatch)34 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)31 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)30 IgniteKernal (org.apache.ignite.internal.IgniteKernal)30 GridTestTaskSession (org.apache.ignite.GridTestTaskSession)29