Search in sources :

Example 6 with CachePartitionPartialCountersMap

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

the class GridCachePartitionExchangeManager method createPartitionsSingleMessage.

/**
 * @param exchangeId Exchange ID.
 * @param clientOnlyExchange Client exchange flag.
 * @param sndCounters {@code True} if need send partition update counters.
 * @param newCntrMap {@code True} if possible to use {@link CachePartitionPartialCountersMap}.
 * @return Message.
 */
public GridDhtPartitionsSingleMessage createPartitionsSingleMessage(@Nullable GridDhtPartitionExchangeId exchangeId, boolean clientOnlyExchange, boolean sndCounters, boolean newCntrMap, ExchangeActions exchActions) {
    GridDhtPartitionsSingleMessage m = new GridDhtPartitionsSingleMessage(exchangeId, clientOnlyExchange, cctx.versions().last(), true);
    Map<Object, T2<Integer, GridPartitionStateMap>> dupData = new HashMap<>();
    for (CacheGroupContext grp : cctx.cache().cacheGroups()) {
        if (!grp.isLocal() && (exchActions == null || !exchActions.cacheGroupStopping(grp.groupId()))) {
            GridDhtPartitionMap locMap = grp.topology().localPartitionMap();
            addPartitionMap(m, dupData, true, grp.groupId(), locMap, grp.affinity().similarAffinityKey());
            if (sndCounters) {
                CachePartitionPartialCountersMap cntrsMap = grp.topology().localUpdateCounters(true);
                m.addPartitionUpdateCounters(grp.groupId(), newCntrMap ? cntrsMap : CachePartitionPartialCountersMap.toCountersMap(cntrsMap));
            }
        }
    }
    for (GridClientPartitionTopology top : clientTops.values()) {
        if (m.partitions() != null && m.partitions().containsKey(top.groupId()))
            continue;
        GridDhtPartitionMap locMap = top.localPartitionMap();
        addPartitionMap(m, dupData, true, top.groupId(), locMap, top.similarAffinityKey());
        if (sndCounters) {
            CachePartitionPartialCountersMap cntrsMap = top.localUpdateCounters(true);
            m.addPartitionUpdateCounters(top.groupId(), newCntrMap ? cntrsMap : CachePartitionPartialCountersMap.toCountersMap(cntrsMap));
        }
    }
    return m;
}
Also used : GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject) T2(org.apache.ignite.internal.util.typedef.T2) CachePartitionPartialCountersMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionPartialCountersMap) GridClientPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.GridClientPartitionTopology)

Example 7 with CachePartitionPartialCountersMap

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

the class GridDhtPartitionTopologyImpl method localUpdateCounters.

/**
 * {@inheritDoc}
 */
@Override
public CachePartitionPartialCountersMap localUpdateCounters(boolean skipZeros) {
    lock.readLock().lock();
    try {
        int locPartCnt = 0;
        for (int i = 0; i < locParts.length(); i++) {
            GridDhtLocalPartition part = locParts.get(i);
            if (part != null)
                locPartCnt++;
        }
        CachePartitionPartialCountersMap res = new CachePartitionPartialCountersMap(locPartCnt);
        for (int i = 0; i < locParts.length(); i++) {
            GridDhtLocalPartition part = locParts.get(i);
            if (part == null)
                continue;
            long updCntr = part.updateCounter();
            long initCntr = part.initialUpdateCounter();
            if (skipZeros && initCntr == 0L && updCntr == 0L)
                continue;
            res.add(part.id(), initCntr, updCntr);
        }
        res.trim();
        return res;
    } finally {
        lock.readLock().unlock();
    }
}
Also used : CachePartitionPartialCountersMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionPartialCountersMap)

Example 8 with CachePartitionPartialCountersMap

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

the class GridDhtPartitionsStateValidator method validatePartitionsUpdateCounters.

/**
 * Validate partitions update counters for given {@code top}.
 *
 * @param top Topology to validate.
 * @param messages Single messages received from all nodes.
 * @param ignoringNodes Nodes for what we ignore validation.
 * @return Invalid partitions map with following structure:
 * (partId, (nodeId, updateCounter)).
 * If map is empty validation is successful.
 */
public Map<Integer, Map<UUID, Long>> validatePartitionsUpdateCounters(GridDhtPartitionTopology top, Map<UUID, GridDhtPartitionsSingleMessage> messages, Set<UUID> ignoringNodes) {
    Map<Integer, Map<UUID, Long>> invalidPartitions = new HashMap<>();
    Map<Integer, AbstractMap.Entry<UUID, Long>> updateCountersAndNodesByPartitions = new HashMap<>();
    // Populate counters statistics from local node partitions.
    for (GridDhtLocalPartition part : top.currentLocalPartitions()) {
        if (part.state() != GridDhtPartitionState.OWNING)
            continue;
        if (part.updateCounter() == 0 && part.fullSize() == 0)
            continue;
        updateCountersAndNodesByPartitions.put(part.id(), new AbstractMap.SimpleEntry<>(cctx.localNodeId(), part.updateCounter()));
    }
    int partitions = top.partitions();
    // Then process and validate counters from other nodes.
    for (Map.Entry<UUID, GridDhtPartitionsSingleMessage> e : messages.entrySet()) {
        UUID nodeId = e.getKey();
        if (ignoringNodes.contains(nodeId))
            continue;
        final GridDhtPartitionsSingleMessage message = e.getValue();
        CachePartitionPartialCountersMap countersMap = message.partitionUpdateCounters(top.groupId(), partitions);
        Map<Integer, Long> sizesMap = message.partitionSizes(top.groupId());
        Set<Integer> ignorePartitions = shouldIgnore(top, nodeId, countersMap, sizesMap);
        for (int i = 0; i < countersMap.size(); i++) {
            int p = countersMap.partitionAt(i);
            if (ignorePartitions != null && ignorePartitions.contains(p))
                continue;
            long currentCounter = countersMap.updateCounterAt(i);
            process(invalidPartitions, updateCountersAndNodesByPartitions, p, nodeId, currentCounter);
        }
    }
    return invalidPartitions;
}
Also used : HashMap(java.util.HashMap) CachePartitionPartialCountersMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionPartialCountersMap) AbstractMap(java.util.AbstractMap) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) UUID(java.util.UUID) CachePartitionPartialCountersMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionPartialCountersMap) HashMap(java.util.HashMap) NavigableMap(java.util.NavigableMap) AbstractMap(java.util.AbstractMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 9 with CachePartitionPartialCountersMap

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

the class CacheExchangeMessageDuplicatedStateTest method checkSingleMessage.

/**
 * @param msg Message.
 */
private void checkSingleMessage(GridDhtPartitionsSingleMessage msg) {
    Map<Integer, Integer> dupPartsData = getFieldValue(msg, "dupPartsData");
    assertNotNull(dupPartsData);
    checkSingleMessage(AFF1_CACHE1, AFF1_CACHE2, dupPartsData, msg);
    checkSingleMessage(AFF4_FILTER_CACHE1, AFF4_FILTER_CACHE2, dupPartsData, msg);
    assertFalse(dupPartsData.containsKey(CU.cacheId(AFF3_CACHE1)));
    Map<Integer, CachePartitionPartialCountersMap> partCntrs = getFieldValue(msg, "partCntrs");
    if (partCntrs != null) {
        for (CachePartitionPartialCountersMap cntrs : partCntrs.values()) assertEquals(0, cntrs.size());
    }
}
Also used : CachePartitionPartialCountersMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionPartialCountersMap)

Example 10 with CachePartitionPartialCountersMap

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

the class CachePartitionPartialCountersMapSelfTest method testAddAndRemove.

/**
 */
@Test
public void testAddAndRemove() throws Exception {
    CachePartitionPartialCountersMap map = new CachePartitionPartialCountersMap(10);
    for (int p = 0; p < 10; p++) map.add(p, 2 * p, 3 * p);
    for (int p = 0; p < 10; p++) {
        assertEquals(p, map.partitionAt(p));
        assertEquals(2 * p, map.initialUpdateCounterAt(p));
        assertEquals(3 * p, map.updateCounterAt(p));
    }
    map.remove(3);
    map.remove(11);
    map.remove(7);
    assertEquals(8, map.size());
    int idx = 0;
    for (int p = 0; p < 10; p++) {
        if (p == 3 || p == 10 || p == 7)
            continue;
        assertEquals(p, map.partitionAt(idx));
        assertEquals(2 * p, map.initialUpdateCounterAt(idx));
        assertEquals(3 * p, map.updateCounterAt(idx));
        idx++;
    }
}
Also used : CachePartitionPartialCountersMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionPartialCountersMap) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

CachePartitionPartialCountersMap (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionPartialCountersMap)11 HashMap (java.util.HashMap)5 GridDhtPartitionsSingleMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage)4 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 AbstractMap (java.util.AbstractMap)2 NavigableMap (java.util.NavigableMap)2 TreeMap (java.util.TreeMap)2 UUID (java.util.UUID)2 GridDhtPartitionMap (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap)2 GridTimeoutObject (org.apache.ignite.internal.processors.timeout.GridTimeoutObject)2 T2 (org.apache.ignite.internal.util.typedef.T2)2 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1