Search in sources :

Example 1 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 initCntr = part.initialUpdateCounter();
            long updCntr = part.updateCounter();
            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 2 with CachePartitionPartialCountersMap

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

the class GridDhtPartitionsStateValidator method validatePartitionsSizes.

/**
 * Validate partitions cache sizes 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, cacheSize)).
 * If map is empty validation is successful.
 */
public Map<Integer, Map<UUID, Long>> validatePartitionsSizes(GridDhtPartitionTopology top, Map<UUID, GridDhtPartitionsSingleMessage> messages, Set<UUID> ignoringNodes) {
    Map<Integer, Map<UUID, Long>> invalidPartitions = new HashMap<>();
    Map<Integer, AbstractMap.Entry<UUID, Long>> sizesAndNodesByPartitions = new HashMap<>();
    // Populate sizes statistics from local node partitions.
    for (GridDhtLocalPartition part : top.currentLocalPartitions()) {
        if (part.state() != GridDhtPartitionState.OWNING)
            continue;
        if (part.updateCounter() == 0 && part.fullSize() == 0)
            continue;
        sizesAndNodesByPartitions.put(part.id(), new AbstractMap.SimpleEntry<>(cctx.localNodeId(), part.fullSize()));
    }
    int partitions = top.partitions();
    // Then process and validate sizes 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 currentSize = sizesMap.getOrDefault(p, 0L);
            process(invalidPartitions, sizesAndNodesByPartitions, p, nodeId, currentSize);
        }
    }
    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 3 with CachePartitionPartialCountersMap

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

the class GridCachePartitionExchangeManager method createPartitionsSingleMessage.

/**
 * Creates partitions single message for selected cache groups.
 *
 * @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}.
 * @param grps Selected cache groups.
 * @return Message.
 */
public GridDhtPartitionsSingleMessage createPartitionsSingleMessage(@Nullable GridDhtPartitionExchangeId exchangeId, boolean clientOnlyExchange, boolean sndCounters, boolean newCntrMap, ExchangeActions exchActions, Collection<CacheGroupContext> grps) {
    GridDhtPartitionsSingleMessage m = new GridDhtPartitionsSingleMessage(exchangeId, clientOnlyExchange, cctx.versions().last(), true);
    Map<Object, T2<Integer, GridPartitionStateMap>> dupData = new HashMap<>();
    for (CacheGroupContext grp : grps) {
        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));
            }
            m.addPartitionSizes(grp.groupId(), grp.topology().partitionSizes());
        }
    }
    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));
        }
        m.addPartitionSizes(top.groupId(), top.partitionSizes());
    }
    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.topology.GridClientPartitionTopology)

Example 4 with CachePartitionPartialCountersMap

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

the class GridContinuousProcessor method processStartRequestV2.

/**
 * @param topVer Current topology version.
 * @param snd Sender.
 * @param msg Start request.
 */
private void processStartRequestV2(final AffinityTopologyVersion topVer, final ClusterNode snd, final StartRoutineDiscoveryMessageV2 msg) {
    StartRequestDataV2 reqData = msg.startRequestData();
    ContinuousRoutineInfo routineInfo = new ContinuousRoutineInfo(snd.id(), msg.routineId(), reqData.handlerBytes(), reqData.nodeFilterBytes(), reqData.bufferSize(), reqData.interval(), reqData.autoUnsubscribe());
    routinesInfo.addRoutineInfo(routineInfo);
    final DiscoCache discoCache = ctx.discovery().discoCache(topVer);
    // Should not use marshaller and send messages from discovery thread.
    ctx.pools().getSystemExecutorService().execute(new Runnable() {

        @Override
        public void run() {
            if (snd.id().equals(ctx.localNodeId())) {
                StartFuture fut = startFuts.get(msg.routineId());
                if (fut != null)
                    fut.initRemoteNodes(discoCache);
                return;
            }
            StartRequestDataV2 reqData = msg.startRequestData();
            Exception err = null;
            IgnitePredicate<ClusterNode> nodeFilter = null;
            byte[] cntrs = null;
            if (reqData.nodeFilterBytes() != null) {
                try {
                    if (ctx.config().isPeerClassLoadingEnabled() && reqData.className() != null) {
                        String clsName = reqData.className();
                        GridDeploymentInfo depInfo = reqData.deploymentInfo();
                        GridDeployment dep = ctx.deploy().getGlobalDeployment(depInfo.deployMode(), clsName, clsName, depInfo.userVersion(), snd.id(), depInfo.classLoaderId(), depInfo.participants(), null);
                        if (dep == null) {
                            throw new IgniteDeploymentCheckedException("Failed to obtain deployment " + "for class: " + clsName);
                        }
                        nodeFilter = U.unmarshal(marsh, reqData.nodeFilterBytes(), U.resolveClassLoader(dep.classLoader(), ctx.config()));
                    } else {
                        nodeFilter = U.unmarshal(marsh, reqData.nodeFilterBytes(), U.resolveClassLoader(ctx.config()));
                    }
                    if (nodeFilter != null)
                        ctx.resource().injectGeneric(nodeFilter);
                } catch (Exception e) {
                    err = e;
                    U.error(log, "Failed to unmarshal continuous routine filter [" + "routineId=" + msg.routineId + ", srcNodeId=" + snd.id() + ']', e);
                }
            }
            boolean register = err == null && (nodeFilter == null || nodeFilter.apply(ctx.discovery().localNode()));
            if (register) {
                try {
                    GridContinuousHandler hnd = U.unmarshal(marsh, reqData.handlerBytes(), U.resolveClassLoader(ctx.config()));
                    if (ctx.config().isPeerClassLoadingEnabled())
                        hnd.p2pUnmarshal(snd.id(), ctx);
                    if (msg.keepBinary()) {
                        assert hnd instanceof CacheContinuousQueryHandler : hnd;
                        ((CacheContinuousQueryHandler) hnd).keepBinary(true);
                    }
                    registerHandler(snd.id(), msg.routineId, hnd, reqData.bufferSize(), reqData.interval(), reqData.autoUnsubscribe(), false);
                    if (hnd.isQuery()) {
                        GridCacheProcessor proc = ctx.cache();
                        if (proc != null) {
                            GridCacheAdapter cache = ctx.cache().internalCache(hnd.cacheName());
                            if (cache != null && !cache.isLocal() && cache.context().userCache()) {
                                CachePartitionPartialCountersMap cntrsMap = cache.context().topology().localUpdateCounters(false);
                                cntrs = U.marshal(marsh, cntrsMap);
                            }
                        }
                    }
                } catch (Exception e) {
                    err = e;
                    U.error(log, "Failed to register continuous routine handler [" + "routineId=" + msg.routineId + ", srcNodeId=" + snd.id() + ']', e);
                }
            }
            sendMessageStartResult(snd, msg.routineId(), cntrs, err);
        }
    });
}
Also used : DiscoCache(org.apache.ignite.internal.managers.discovery.DiscoCache) IgniteDeploymentCheckedException(org.apache.ignite.internal.IgniteDeploymentCheckedException) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) CacheContinuousQueryHandler(org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryHandler) GridDeploymentInfo(org.apache.ignite.internal.managers.deployment.GridDeploymentInfo) GridCacheProcessor(org.apache.ignite.internal.processors.cache.GridCacheProcessor) IgniteDeploymentCheckedException(org.apache.ignite.internal.IgniteDeploymentCheckedException) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) IOException(java.io.IOException) CachePartitionPartialCountersMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionPartialCountersMap) GridDeployment(org.apache.ignite.internal.managers.deployment.GridDeployment) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) GridPlainRunnable(org.apache.ignite.internal.util.lang.GridPlainRunnable)

Example 5 with CachePartitionPartialCountersMap

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

the class CacheContinuousQueryFailoverAbstractSelfTest method checkPartCounter.

/**
 * @param nodes Count nodes.
 * @param killedNodeIdx Killed node index.
 * @param updCntrs Update counters.
 */
private void checkPartCounter(int nodes, int killedNodeIdx, Map<Integer, Long> updCntrs) {
    for (int i = 0; i < nodes; i++) {
        if (i == killedNodeIdx)
            continue;
        Affinity<Object> aff = grid(i).affinity(DEFAULT_CACHE_NAME);
        CachePartitionPartialCountersMap act = grid(i).cachex(DEFAULT_CACHE_NAME).context().topology().localUpdateCounters(false);
        for (Map.Entry<Integer, Long> e : updCntrs.entrySet()) {
            if (aff.mapPartitionToPrimaryAndBackups(e.getKey()).contains(grid(i).localNode())) {
                int partIdx = act.partitionIndex(e.getKey());
                assertEquals(e.getValue(), (Long) act.updateCounterAt(partIdx));
            }
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicLong(java.util.concurrent.atomic.AtomicLong) Map(java.util.Map) CachePartitionPartialCountersMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionPartialCountersMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) CachePartitionPartialCountersMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionPartialCountersMap)

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