Search in sources :

Example 1 with BaselineNode

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

the class IgniteClusterImpl method setBaselineTopology.

/**
 * {@inheritDoc}
 */
@Override
public void setBaselineTopology(long topVer) {
    guard();
    try {
        if (isInMemoryMode())
            return;
        Collection<ClusterNode> top = topology(topVer);
        if (top == null)
            throw new IgniteException("Topology version does not exist: " + topVer);
        Collection<BaselineNode> target = new ArrayList<>(top.size());
        for (ClusterNode node : top) {
            if (!node.isClient())
                target.add(node);
        }
        validateBeforeBaselineChange(target);
        ctx.state().changeGlobalState(true, target, true).get();
    } catch (IgniteCheckedException e) {
        throw U.convertException(e);
    } finally {
        unguard();
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) ArrayList(java.util.ArrayList) BaselineNode(org.apache.ignite.cluster.BaselineNode)

Example 2 with BaselineNode

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

the class GridClusterStateProcessor method calculateNewBaselineTopology.

/**
 */
private BaselineTopology calculateNewBaselineTopology(final boolean activate, Collection<? extends BaselineNode> baselineNodes, boolean forceChangeBaselineTopology) {
    BaselineTopology newBlt;
    BaselineTopology currentBlt = globalState.baselineTopology();
    int newBltId = 0;
    if (currentBlt != null)
        newBltId = activate ? currentBlt.id() + 1 : currentBlt.id();
    if (baselineNodes != null && !baselineNodes.isEmpty()) {
        List<BaselineNode> baselineNodes0 = new ArrayList<>();
        for (BaselineNode node : baselineNodes) {
            if (node instanceof ClusterNode) {
                ClusterNode clusterNode = (ClusterNode) node;
                if (!clusterNode.isClient() && !clusterNode.isDaemon())
                    baselineNodes0.add(node);
            } else
                baselineNodes0.add(node);
        }
        baselineNodes = baselineNodes0;
    }
    if (forceChangeBaselineTopology)
        newBlt = BaselineTopology.build(baselineNodes, newBltId);
    else if (activate) {
        if (baselineNodes == null)
            baselineNodes = baselineNodes();
        if (currentBlt == null)
            newBlt = BaselineTopology.build(baselineNodes, newBltId);
        else {
            newBlt = currentBlt;
            newBlt.updateHistory(baselineNodes);
        }
    } else
        newBlt = null;
    return newBlt;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) ArrayList(java.util.ArrayList) BaselineNode(org.apache.ignite.cluster.BaselineNode)

Example 3 with BaselineNode

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

the class VisorBaselineTaskResult method toMap.

/**
 * @param nodes Nodes to process.
 * @return Map of DTO objects.
 */
private static Map<String, VisorBaselineNode> toMap(Collection<? extends BaselineNode> nodes) {
    if (F.isEmpty(nodes))
        return null;
    Map<String, VisorBaselineNode> map = new TreeMap<>();
    for (BaselineNode node : nodes) {
        VisorBaselineNode dto = new VisorBaselineNode(node);
        map.put(dto.getConsistentId(), dto);
    }
    return map;
}
Also used : TreeMap(java.util.TreeMap) BaselineNode(org.apache.ignite.cluster.BaselineNode)

Example 4 with BaselineNode

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

the class GridClusterStateProcessor method baselineNodes.

/**
 */
private Collection<BaselineNode> baselineNodes() {
    List<ClusterNode> clNodes = ctx.discovery().serverNodes(AffinityTopologyVersion.NONE);
    ArrayList<BaselineNode> bltNodes = new ArrayList<>(clNodes.size());
    for (ClusterNode clNode : clNodes) bltNodes.add(clNode);
    return bltNodes;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) ArrayList(java.util.ArrayList) BaselineNode(org.apache.ignite.cluster.BaselineNode)

Example 5 with BaselineNode

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

the class GridDiscoveryManager method createDiscoCache.

/**
 * Called from discovery thread.
 *
 * @param topVer Topology version.
 * @param state Current state.
 * @param loc Local node.
 * @param topSnapshot Topology snapshot.
 * @return Newly created discovery cache.
 */
@NotNull
private DiscoCache createDiscoCache(AffinityTopologyVersion topVer, DiscoveryDataClusterState state, ClusterNode loc, Collection<ClusterNode> topSnapshot) {
    assert topSnapshot.contains(loc);
    HashSet<UUID> alives = U.newHashSet(topSnapshot.size());
    HashMap<UUID, ClusterNode> nodeMap = U.newHashMap(topSnapshot.size());
    ArrayList<ClusterNode> daemonNodes = new ArrayList<>(topSnapshot.size());
    ArrayList<ClusterNode> srvNodes = new ArrayList<>(topSnapshot.size());
    ArrayList<ClusterNode> rmtNodes = new ArrayList<>(topSnapshot.size());
    ArrayList<ClusterNode> allNodes = new ArrayList<>(topSnapshot.size());
    Map<UUID, Short> nodeIdToConsIdx;
    Map<Short, UUID> consIdxToNodeId;
    List<? extends BaselineNode> baselineNodes;
    IgniteProductVersion minVer = null;
    IgniteProductVersion minSrvVer = null;
    for (ClusterNode node : topSnapshot) {
        if (alive(node))
            alives.add(node.id());
        if (node.isDaemon())
            daemonNodes.add(node);
        else {
            allNodes.add(node);
            if (!node.isLocal())
                rmtNodes.add(node);
            if (!CU.clientNode(node)) {
                srvNodes.add(node);
                if (minSrvVer == null)
                    minSrvVer = node.version();
                else if (node.version().compareTo(minSrvVer) < 0)
                    minSrvVer = node.version();
            }
        }
        nodeMap.put(node.id(), node);
        if (minVer == null)
            minVer = node.version();
        else if (node.version().compareTo(minVer) < 0)
            minVer = node.version();
    }
    assert !rmtNodes.contains(loc) : "Remote nodes collection shouldn't contain local node" + " [rmtNodes=" + rmtNodes + ", loc=" + loc + ']';
    Map<Integer, List<ClusterNode>> allCacheNodes = U.newHashMap(allNodes.size());
    Map<Integer, List<ClusterNode>> cacheGrpAffNodes = U.newHashMap(allNodes.size());
    Set<ClusterNode> rmtNodesWithCaches = new TreeSet<>(NodeOrderComparator.getInstance());
    fillAffinityNodeCaches(allNodes, allCacheNodes, cacheGrpAffNodes, rmtNodesWithCaches);
    BaselineTopology blt = state.baselineTopology();
    if (blt != null) {
        nodeIdToConsIdx = U.newHashMap(srvNodes.size());
        consIdxToNodeId = U.newHashMap(srvNodes.size());
        Map<Object, Short> m = blt.consistentIdMapping();
        Map<Object, ClusterNode> aliveNodesByConsId = U.newHashMap(srvNodes.size());
        for (ClusterNode node : srvNodes) {
            Short compactedId = m.get(node.consistentId());
            if (compactedId != null) {
                nodeIdToConsIdx.put(node.id(), compactedId);
                consIdxToNodeId.put(compactedId, node.id());
            }
            aliveNodesByConsId.put(node.consistentId(), node);
        }
        List<BaselineNode> baselineNodes0 = new ArrayList<>(blt.size());
        for (Object consId : blt.consistentIds()) {
            ClusterNode srvNode = aliveNodesByConsId.get(consId);
            if (srvNode != null)
                baselineNodes0.add(srvNode);
            else
                baselineNodes0.add(blt.baselineNode(consId));
        }
        baselineNodes = baselineNodes0;
    } else {
        nodeIdToConsIdx = null;
        consIdxToNodeId = null;
        baselineNodes = null;
    }
    return new DiscoCache(topVer, state, loc, Collections.unmodifiableList(rmtNodes), Collections.unmodifiableList(allNodes), Collections.unmodifiableList(srvNodes), Collections.unmodifiableList(daemonNodes), U.sealList(rmtNodesWithCaches), baselineNodes == null ? null : Collections.unmodifiableList(baselineNodes), Collections.unmodifiableMap(allCacheNodes), Collections.unmodifiableMap(cacheGrpAffNodes), Collections.unmodifiableMap(nodeMap), alives, nodeIdToConsIdx == null ? null : Collections.unmodifiableMap(nodeIdToConsIdx), consIdxToNodeId == null ? null : Collections.unmodifiableMap(consIdxToNodeId), minVer, minSrvVer);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) IgniteProductVersion(org.apache.ignite.lang.IgniteProductVersion) BaselineNode(org.apache.ignite.cluster.BaselineNode) IgniteSystemProperties.getInteger(org.apache.ignite.IgniteSystemProperties.getInteger) TreeSet(java.util.TreeSet) BaselineTopology(org.apache.ignite.internal.processors.cluster.BaselineTopology) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) List(java.util.List) UUID(java.util.UUID) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

BaselineNode (org.apache.ignite.cluster.BaselineNode)8 ArrayList (java.util.ArrayList)4 ClusterNode (org.apache.ignite.cluster.ClusterNode)4 Ignite (org.apache.ignite.Ignite)2 IgniteException (org.apache.ignite.IgniteException)2 List (java.util.List)1 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1 UUID (java.util.UUID)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteSystemProperties.getInteger (org.apache.ignite.IgniteSystemProperties.getInteger)1 BaselineTopology (org.apache.ignite.internal.processors.cluster.BaselineTopology)1 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)1 IgniteProductVersion (org.apache.ignite.lang.IgniteProductVersion)1 NotNull (org.jetbrains.annotations.NotNull)1