Search in sources :

Example 96 with ClusterNode

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

the class GridClientPartitionTopology method beforeExchange0.

/**
 * @param loc Local node.
 * @param exchFut Exchange future.
 */
private void beforeExchange0(ClusterNode loc, GridDhtPartitionsExchangeFuture exchFut) {
    GridDhtPartitionExchangeId exchId = exchFut.exchangeId();
    if (exchFut.context().events().hasServerLeft()) {
        for (DiscoveryEvent evt : exchFut.context().events().events()) {
            if (ExchangeDiscoveryEvents.serverLeftEvent(evt))
                removeNode(evt.eventNode().id());
        }
    }
    // In case if node joins, get topology at the time of joining node.
    ClusterNode oldest = discoCache.oldestAliveServerNode();
    assert oldest != null;
    if (log.isDebugEnabled())
        log.debug("Partition map beforeExchange [exchId=" + exchId + ", fullMap=" + fullMapString() + ']');
    long updateSeq = this.updateSeq.incrementAndGet();
    // If this is the oldest node (coordinator) or cache was added during this exchange
    if (oldest.id().equals(loc.id()) || exchFut.dynamicCacheGroupStarted(grpId)) {
        if (node2part == null) {
            node2part = new GridDhtPartitionFullMap(oldest.id(), oldest.order(), updateSeq);
            if (log.isDebugEnabled())
                log.debug("Created brand new full topology map on oldest node [exchId=" + exchId + ", fullMap=" + fullMapString() + ']');
        } else if (!node2part.valid()) {
            node2part = new GridDhtPartitionFullMap(oldest.id(), oldest.order(), updateSeq, node2part, false);
            if (log.isDebugEnabled())
                log.debug("Created new full topology map on oldest node [exchId=" + exchId + ", fullMap=" + node2part + ']');
        } else if (!node2part.nodeId().equals(loc.id())) {
            node2part = new GridDhtPartitionFullMap(oldest.id(), oldest.order(), updateSeq, node2part, false);
            if (log.isDebugEnabled())
                log.debug("Copied old map into new map on oldest node (previous oldest node left) [exchId=" + exchId + ", fullMap=" + fullMapString() + ']');
        }
    }
    consistencyCheck();
    if (log.isDebugEnabled())
        log.debug("Partition map after beforeExchange [exchId=" + exchId + ", fullMap=" + fullMapString() + ']');
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) GridDhtPartitionExchangeId(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionExchangeId) GridDhtPartitionFullMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap)

Example 97 with ClusterNode

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

the class GridClientPartitionTopology method beforeExchange.

/**
 * {@inheritDoc}
 */
@Override
public void beforeExchange(GridDhtPartitionsExchangeFuture exchFut, boolean initParts, boolean updateMoving) throws IgniteCheckedException {
    ClusterNode loc = cctx.localNode();
    U.writeLock(lock);
    try {
        if (stopping)
            return;
        discoCache = exchFut.events().discoveryCache();
        beforeExchange0(loc, exchFut);
        if (updateMoving) {
            ExchangeDiscoveryEvents evts = exchFut.context().events();
            GridAffinityAssignmentCache aff = cctx.affinity().affinity(grpId);
            assert aff.lastVersion().equals(evts.topologyVersion());
            createMovingPartitions(aff.readyAffinity(evts.topologyVersion()));
        }
    } finally {
        lock.writeLock().unlock();
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridAffinityAssignmentCache(org.apache.ignite.internal.processors.affinity.GridAffinityAssignmentCache) ExchangeDiscoveryEvents(org.apache.ignite.internal.processors.cache.ExchangeDiscoveryEvents)

Example 98 with ClusterNode

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

the class GridClientPartitionTopology method allOwners.

/**
 * {@inheritDoc}
 */
@Override
public List<List<ClusterNode>> allOwners() {
    lock.readLock().lock();
    try {
        int parts = partitions();
        List<List<ClusterNode>> res = new ArrayList<>(parts);
        for (int i = 0; i < parts; i++) res.add(new ArrayList<>());
        List<ClusterNode> allNodes = discoCache.cacheGroupAffinityNodes(grpId);
        for (int i = 0; i < allNodes.size(); i++) {
            ClusterNode node = allNodes.get(i);
            GridDhtPartitionMap nodeParts = node2part.get(node.id());
            if (nodeParts != null) {
                for (Map.Entry<Integer, GridDhtPartitionState> e : nodeParts.map().entrySet()) {
                    if (e.getValue() == OWNING) {
                        int part = e.getKey();
                        List<ClusterNode> owners = res.get(part);
                        owners.add(node);
                    }
                }
            }
        }
        return res;
    } finally {
        lock.readLock().unlock();
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) GridPartitionStateMap(org.apache.ignite.internal.util.GridPartitionStateMap) CachePartitionFullCountersMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionFullCountersMap) HashMap(java.util.HashMap) Map(java.util.Map) GridDhtPartitionFullMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap) CachePartitionPartialCountersMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionPartialCountersMap) GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap)

Example 99 with ClusterNode

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

the class GridClientPartitionTopology method updateLocal.

/**
 * Updates value for single partition.
 *
 * @param p Partition.
 * @param nodeId Node ID.
 * @param state State.
 * @param updateSeq Update sequence.
 */
private void updateLocal(int p, UUID nodeId, GridDhtPartitionState state, long updateSeq) {
    assert lock.isWriteLockedByCurrentThread();
    assert nodeId.equals(cctx.localNodeId());
    // In case if node joins, get topology at the time of joining node.
    ClusterNode oldest = discoCache.oldestAliveServerNode();
    // If this node became the oldest node.
    if (cctx.localNode().equals(oldest)) {
        long seq = node2part.updateSequence();
        if (seq != updateSeq) {
            if (seq > updateSeq) {
                if (this.updateSeq.get() < seq) {
                    // Update global counter if necessary.
                    boolean b = this.updateSeq.compareAndSet(this.updateSeq.get(), seq + 1);
                    assert b : "Invalid update sequence [updateSeq=" + updateSeq + ", seq=" + seq + ", curUpdateSeq=" + this.updateSeq.get() + ", node2part=" + node2part.toFullString() + ']';
                    updateSeq = seq + 1;
                } else
                    updateSeq = seq;
            }
            node2part.updateSequence(updateSeq);
        }
    }
    GridDhtPartitionMap map = node2part.get(nodeId);
    if (map == null)
        node2part.put(nodeId, map = new GridDhtPartitionMap(nodeId, updateSeq, topVer, GridPartitionStateMap.EMPTY, false));
    map.updateSequence(updateSeq, topVer);
    map.put(p, state);
    Set<UUID> ids = part2node.get(p);
    if (ids == null)
        part2node.put(p, ids = U.newHashSet(3));
    ids.add(nodeId);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap) UUID(java.util.UUID)

Example 100 with ClusterNode

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

the class GridClientPartitionTopology method nodes.

/**
 * {@inheritDoc}
 */
@Override
public List<ClusterNode> nodes(int p, AffinityTopologyVersion topVer) {
    lock.readLock().lock();
    try {
        assert node2part != null && node2part.valid() : "Invalid node-to-partitions map [topVer=" + topVer + ", node2part=" + node2part + ']';
        List<ClusterNode> nodes = null;
        Collection<UUID> nodeIds = part2node.get(p);
        if (!F.isEmpty(nodeIds)) {
            for (UUID nodeId : nodeIds) {
                ClusterNode n = discoCache.node(nodeId);
                if (n != null && (topVer.topologyVersion() < 0 || n.order() <= topVer.topologyVersion())) {
                    if (nodes == null)
                        nodes = new ArrayList<>(nodeIds.size());
                    nodes.add(n);
                }
            }
        }
        return nodes;
    } finally {
        lock.readLock().unlock();
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) ArrayList(java.util.ArrayList) UUID(java.util.UUID)

Aggregations

ClusterNode (org.apache.ignite.cluster.ClusterNode)1104 UUID (java.util.UUID)281 ArrayList (java.util.ArrayList)280 Test (org.junit.Test)276 Ignite (org.apache.ignite.Ignite)239 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)239 HashMap (java.util.HashMap)184 Map (java.util.Map)182 List (java.util.List)165 IgniteException (org.apache.ignite.IgniteException)147 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)147 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)143 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)126 Collection (java.util.Collection)113 Message (org.apache.ignite.plugin.extensions.communication.Message)106 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)87 HashSet (java.util.HashSet)85 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)82 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)81 IgniteEx (org.apache.ignite.internal.IgniteEx)81