Search in sources :

Example 61 with GridDhtPartitionMap

use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap in project ignite by apache.

the class GridClientPartitionTopology method update.

/**
 * {@inheritDoc}
 */
@Override
public boolean update(@Nullable AffinityTopologyVersion exchangeVer, GridDhtPartitionFullMap partMap, @Nullable CachePartitionFullCountersMap cntrMap, Set<Integer> partsToReload, @Nullable Map<Integer, Long> partSizes, @Nullable AffinityTopologyVersion msgTopVer, @Nullable GridDhtPartitionsExchangeFuture exchFut, @Nullable Set<Integer> lostParts) {
    if (log.isDebugEnabled())
        log.debug("Updating full partition map [exchVer=" + exchangeVer + ", parts=" + fullMapString() + ']');
    lock.writeLock().lock();
    try {
        if (exchangeVer != null && lastExchangeVer != null && lastExchangeVer.compareTo(exchangeVer) >= 0) {
            if (log.isDebugEnabled())
                log.debug("Stale exchange id for full partition map update (will ignore) [lastExchId=" + lastExchangeVer + ", exchVer=" + exchangeVer + ']');
            return false;
        }
        if (msgTopVer != null && lastExchangeVer != null && lastExchangeVer.compareTo(msgTopVer) > 0) {
            if (log.isDebugEnabled())
                log.debug("Stale topology version for full partition map update message (will ignore) " + "[lastExchId=" + lastExchangeVer + ", topVersion=" + msgTopVer + ']');
            return false;
        }
        boolean fullMapUpdated = (node2part == null);
        if (node2part != null) {
            for (GridDhtPartitionMap part : node2part.values()) {
                GridDhtPartitionMap newPart = partMap.get(part.nodeId());
                if (shouldOverridePartitionMap(part, newPart)) {
                    fullMapUpdated = true;
                    if (log.isDebugEnabled())
                        log.debug("Overriding partition map in full update map [exchId=" + exchangeVer + ", curPart=" + mapString(part) + ", newPart=" + mapString(newPart) + ']');
                } else {
                    // If for some nodes current partition has a newer map,
                    // then we keep the newer value.
                    partMap.put(part.nodeId(), part);
                }
            }
            // Check that we have new nodes.
            for (GridDhtPartitionMap part : partMap.values()) {
                if (fullMapUpdated)
                    break;
                fullMapUpdated = !node2part.containsKey(part.nodeId());
            }
            // Remove entry if node left.
            for (Iterator<UUID> it = partMap.keySet().iterator(); it.hasNext(); ) {
                UUID nodeId = it.next();
                if (!cctx.discovery().alive(nodeId)) {
                    if (log.isDebugEnabled())
                        log.debug("Removing left node from full map update [nodeId=" + nodeId + ", partMap=" + partMap + ']');
                    it.remove();
                }
            }
        }
        if (!fullMapUpdated) {
            if (log.isDebugEnabled())
                log.debug("No updates for full partition map (will ignore) [lastExch=" + lastExchangeVer + ", exch=" + exchangeVer + ", curMap=" + node2part + ", newMap=" + partMap + ']');
            return false;
        }
        if (exchangeVer != null)
            lastExchangeVer = exchangeVer;
        node2part = partMap;
        updateSeq.incrementAndGet();
        part2node.clear();
        for (Map.Entry<UUID, GridDhtPartitionMap> e : node2part.entrySet()) {
            for (Map.Entry<Integer, GridDhtPartitionState> e0 : e.getValue().entrySet()) {
                if (e0.getValue() != MOVING && e0.getValue() != OWNING)
                    continue;
                int p = e0.getKey();
                Set<UUID> ids = part2node.get(p);
                if (ids == null)
                    // Initialize HashSet to size 3 in anticipation that there won't be
                    // more than 3 nodes per partitions.
                    part2node.put(p, ids = U.newHashSet(3));
                ids.add(e.getKey());
            }
        }
        if (cntrMap != null)
            this.cntrMap = new CachePartitionFullCountersMap(cntrMap);
        if (partSizes != null)
            this.globalPartSizes = partSizes;
        consistencyCheck();
        if (exchangeVer != null)
            this.lostParts = lostParts == null ? null : new TreeSet<>(lostParts);
        if (log.isDebugEnabled())
            log.debug("Partition map after full update: " + fullMapString());
        return false;
    } finally {
        lock.writeLock().unlock();
    }
}
Also used : CachePartitionFullCountersMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionFullCountersMap) GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap) UUID(java.util.UUID) 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 62 with GridDhtPartitionMap

use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap in project ignite by apache.

the class CacheExchangeMessageDuplicatedStateTest method checkFullMessage.

/**
 * @param cache1 Cache 1.
 * @param cache2 Cache 2.
 * @param dupPartsData Duplicated data map.
 * @param msg Message.
 */
private void checkFullMessage(String cache1, String cache2, Map<Integer, Integer> dupPartsData, GridDhtPartitionsFullMessage msg) {
    int cache1Grp = groupIdForCache(ignite(0), cache1);
    int cache2Grp = groupIdForCache(ignite(0), cache2);
    Integer grpId;
    Integer dupGrpId;
    if (dupPartsData.containsKey(cache1Grp)) {
        grpId = cache1Grp;
        dupGrpId = cache2Grp;
    } else {
        grpId = cache2Grp;
        dupGrpId = cache1Grp;
    }
    assertTrue(dupPartsData.containsKey(grpId));
    assertEquals(dupGrpId, dupPartsData.get(grpId));
    assertFalse(dupPartsData.containsKey(dupGrpId));
    Map<Integer, GridDhtPartitionFullMap> parts = msg.partitions();
    GridDhtPartitionFullMap emptyFullMap = parts.get(grpId);
    for (GridDhtPartitionMap map : emptyFullMap.values()) assertEquals(0, map.map().size());
    GridDhtPartitionFullMap fullMap = parts.get(dupGrpId);
    for (GridDhtPartitionMap map : fullMap.values()) assertFalse(map.map().isEmpty());
}
Also used : GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap) GridDhtPartitionFullMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap)

Example 63 with GridDhtPartitionMap

use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap in project ignite by apache.

the class CacheExchangeMessageDuplicatedStateTest method checkSingleMessage.

/**
 * @param cache1 Cache 1.
 * @param cache2 Cache 2.
 * @param dupPartsData Duplicated data map.
 * @param msg Message.
 */
private void checkSingleMessage(String cache1, String cache2, Map<Integer, Integer> dupPartsData, GridDhtPartitionsSingleMessage msg) {
    if (!F.isEmpty(msg.cacheGroupsAffinityRequest())) {
        for (GridDhtPartitionMap map : msg.partitions().values()) assertTrue(F.isEmpty(map.map()));
        return;
    }
    int cache1Grp = groupIdForCache(ignite(0), cache1);
    int cache2Grp = groupIdForCache(ignite(0), cache2);
    Integer grpId;
    Integer dupGrpId;
    if (dupPartsData.containsKey(cache1Grp)) {
        grpId = cache1Grp;
        dupGrpId = cache2Grp;
    } else {
        grpId = cache2Grp;
        dupGrpId = cache1Grp;
    }
    assertTrue(dupPartsData.containsKey(grpId));
    assertEquals(dupGrpId, dupPartsData.get(grpId));
    assertFalse(dupPartsData.containsKey(dupGrpId));
    Map<Integer, GridDhtPartitionMap> parts = msg.partitions();
    GridDhtPartitionMap emptyMap = parts.get(grpId);
    assertEquals(0, emptyMap.map().size());
    GridDhtPartitionMap map = parts.get(dupGrpId);
    assertFalse(map.map().isEmpty());
}
Also used : GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap)

Example 64 with GridDhtPartitionMap

use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap in project ignite by apache.

the class GridCacheDhtPreloadDelayedSelfTest method testAutomaticPreloadWithEmptyCache.

/**
 * @throws Exception If failed.
 */
@Test
public void testAutomaticPreloadWithEmptyCache() throws Exception {
    preloadMode = SYNC;
    delay = 0;
    Collection<Ignite> ignites = new ArrayList<>();
    try {
        for (int i = 0; i < 5; i++) {
            ignites.add(startGrid(i));
            if (persistenceEnabled()) {
                if (i == 0)
                    grid(0).cluster().active(true);
                else
                    resetBaselineTopology();
            }
            awaitPartitionMapExchange(true, true, null, false);
            for (Ignite g : ignites) {
                info(">>> Checking affinity for grid: " + g.name());
                GridDhtPartitionTopology top = topology(g);
                GridDhtPartitionFullMap fullMap = top.partitionMap(true);
                for (Map.Entry<UUID, GridDhtPartitionMap> fe : fullMap.entrySet()) {
                    UUID nodeId = fe.getKey();
                    GridDhtPartitionMap m = fe.getValue();
                    for (Map.Entry<Integer, GridDhtPartitionState> e : m.entrySet()) {
                        int p = e.getKey();
                        GridDhtPartitionState state = e.getValue();
                        Collection<ClusterNode> nodes = affinityNodes(g, p);
                        Collection<UUID> nodeIds = U.nodeIds(nodes);
                        assert nodeIds.contains(nodeId) : "Invalid affinity mapping [nodeId=" + nodeId + ", part=" + p + ", state=" + state + ", igniteInstanceName=" + G.ignite(nodeId).name() + ", affNames=" + U.nodes2names(nodes) + ", affIds=" + nodeIds + ']';
                    }
                }
            }
        }
    } finally {
        stopAllGrids();
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridDhtPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology) ArrayList(java.util.ArrayList) GridDhtPartitionFullMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap) GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap) GridDhtPartitionState(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID) Map(java.util.Map) GridDhtPartitionFullMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap) GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 65 with GridDhtPartitionMap

use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap in project ignite by apache.

the class GridCacheRebalancingSyncSelfTest method checkPartitionMapExchangeFinished.

/**
 */
public static void checkPartitionMapExchangeFinished() {
    for (Ignite g : G.allGrids()) {
        IgniteKernal g0 = (IgniteKernal) g;
        for (IgniteCacheProxy<?, ?> c : g0.context().cache().jcaches()) {
            CacheConfiguration cfg = c.context().config();
            if (cfg.getCacheMode() != LOCAL && cfg.getRebalanceMode() != NONE) {
                GridDhtCacheAdapter<?, ?> dht = dht(c);
                GridDhtPartitionTopology top = dht.topology();
                List<GridDhtLocalPartition> locs = top.localPartitions();
                for (GridDhtLocalPartition loc : locs) {
                    GridDhtPartitionState actl = loc.state();
                    boolean res = GridDhtPartitionState.OWNING.equals(actl);
                    if (!res)
                        printPartitionState(c);
                    assertTrue("Wrong local partition state part=" + loc.id() + ", should be OWNING [state=" + actl + "], node=" + g0.name() + " cache=" + c.getName(), res);
                    Collection<ClusterNode> affNodes = g0.affinity(cfg.getName()).mapPartitionToPrimaryAndBackups(loc.id());
                    assertTrue(affNodes.contains(g0.localNode()));
                }
                for (Ignite remote : G.allGrids()) {
                    IgniteKernal remote0 = (IgniteKernal) remote;
                    IgniteCacheProxy<?, ?> remoteC = remote0.context().cache().jcache(cfg.getName());
                    GridDhtCacheAdapter<?, ?> remoteDht = dht(remoteC);
                    GridDhtPartitionTopology remoteTop = remoteDht.topology();
                    GridDhtPartitionMap pMap = remoteTop.partitionMap(true).get(((IgniteKernal) g).localNodeId());
                    assertEquals(pMap.size(), locs.size());
                    for (Map.Entry entry : pMap.entrySet()) {
                        assertTrue("Wrong remote partition state part=" + entry.getKey() + ", should be OWNING [state=" + entry.getValue() + "], node=" + remote.name() + " cache=" + c.getName(), entry.getValue() == GridDhtPartitionState.OWNING);
                    }
                    for (GridDhtLocalPartition loc : locs) assertTrue(pMap.containsKey(loc.id()));
                }
            }
        }
    }
    log.info("checkPartitionMapExchangeFinished finished");
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridDhtPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology) GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap) GridDhtPartitionState(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState) Ignite(org.apache.ignite.Ignite) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) Map(java.util.Map) GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Aggregations

GridDhtPartitionMap (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap)67 UUID (java.util.UUID)47 GridDhtPartitionFullMap (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap)46 Map (java.util.Map)41 HashMap (java.util.HashMap)36 GridPartitionStateMap (org.apache.ignite.internal.util.GridPartitionStateMap)32 CachePartitionPartialCountersMap (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionPartialCountersMap)30 CachePartitionFullCountersMap (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionFullCountersMap)28 ClusterNode (org.apache.ignite.cluster.ClusterNode)20 HashSet (java.util.HashSet)14 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)10 Set (java.util.Set)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 AffinityAssignment (org.apache.ignite.internal.processors.affinity.AffinityAssignment)8 ArrayList (java.util.ArrayList)7 Ignite (org.apache.ignite.Ignite)7 IgniteKernal (org.apache.ignite.internal.IgniteKernal)7 GridDhtPartitionState (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState)7 GridDhtPartitionTopology (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology)7 List (java.util.List)6