/** * Apply filter. * * @param part Partition. * @return {@code True} if passed. */ public boolean applyPartition(int part) { if (parts == null) return aff.primaryByPartition(locNode, part, topVer); else return parts.contains(part); } }
/** * @param n Node to check. * @param part Partition. * @param topVer Topology version. * @return {@code True} if checked node is primary for given partition. */ public boolean primaryByPartition(ClusterNode n, int part, AffinityTopologyVersion topVer) { return F.eq(primaryByPartition(part, topVer), n); }
/** * @param key Key to check. * @param topVer Topology version. * @return Primary node for given key. */ @Nullable public ClusterNode primaryByKey(Object key, AffinityTopologyVersion topVer) { return primaryByPartition(partition(key), topVer); }
/** * @param entry Entry. * @return {@code True} if local node is current primary for given entry. */ private boolean primaryLocal(GridCacheEntryEx entry) { return entry.context().affinity().primaryByPartition(cctx.localNode(), entry.partition(), AffinityTopologyVersion.NONE); }
/** * @param nodeId Primary node ID. * @param topVer Topology version. */ private void primaryNode(UUID nodeId, AffinityTopologyVersion topVer) { assert lockedByCurrentThread(); assert nodeId != null; ClusterNode primary = null; try { primary = cctx.affinity().primaryByPartition(part, topVer); } catch (IllegalStateException ignore) { // Do not have affinity history. } if (primary == null || !nodeId.equals(primary.id())) { this.topVer = AffinityTopologyVersion.NONE; return; } if (topVer.compareTo(this.topVer) > 0) this.topVer = topVer; }
ClusterNode node = cctx.affinity().primaryByPartition(key.partition(), topVer);
/** * @param part Partition id. * @return Future. */ private IgniteInternalFuture<?> executePreloadTask(int part) throws IgniteCheckedException { ClusterGroup grp = ctx.grid().cluster().forDataNodes(ctx.name()); @Nullable ClusterNode targetNode = ctx.affinity().primaryByPartition(part, ctx.topology().readyTopologyVersion()); if (targetNode == null || targetNode.version().compareTo(PRELOAD_PARTITION_SINCE) < 0) { if (!partPreloadBadVerWarned) { U.warn(log(), "Attempting to execute partition preloading task on outdated or not mapped node " + "[targetNodeVer=" + (targetNode == null ? "NA" : targetNode.version()) + ", minSupportedNodeVer=" + PRELOAD_PARTITION_SINCE + ']'); partPreloadBadVerWarned = true; } return new GridFinishedFuture<>(); } return ctx.closures().affinityRun(Collections.singleton(name()), part, new PartitionPreloadJob(ctx.name(), part), grp.nodes(), null); }
/** {@inheritDoc} */ @Override public long localSizeLong(int part, CachePeekMode[] peekModes) throws IgniteCheckedException { PeekModes modes = parsePeekModes(peekModes, true); long size = 0; if (modes.near) size += nearSize(); // Swap and offheap are disabled for near cache. if (modes.offheap) { AffinityTopologyVersion topVer = ctx.affinity().affinityTopologyVersion(); IgniteCacheOffheapManager offheap = ctx.offheap(); if (ctx.affinity().primaryByPartition(ctx.localNode(), part, topVer) && modes.primary || ctx.affinity().backupByPartition(ctx.localNode(), part, topVer) && modes.backup) size += offheap.cacheEntriesCount(ctx.cacheId(), part); } return size; }
skip = e.cached().isNear() || e.cached().detached() || !e.context().affinity().primaryByPartition(e.cached().partition(), topologyVersion()).isLocal();
return; boolean primary = cctx.affinity().primaryByPartition(cctx.localNode(), e.partition(), AffinityTopologyVersion.NONE);
if (checkPartMapping && !cctx.affinity().primaryByPartition(partId, topVer).id().equals(ctx.localNodeId())) throw new IgniteException("Failed partition reservation. " + "Partition is not primary on the node. [partition=" + partId + ", cacheName=" + cctx.name() +
/** * @param nodeIdx Node index. * @param part Cache partition. * @return Tuple with number of primary and backup keys (one or both will be zero). */ private T2<Integer, Integer> offheapKeysCount(int nodeIdx, int part) throws IgniteCheckedException { GridCacheContext ctx = ((IgniteEx)ignite(nodeIdx)).context().cache().internalCache(DEFAULT_CACHE_NAME).context(); // Swap and offheap are disabled for near cache. IgniteCacheOffheapManager offheapManager = ctx.isNear() ? ctx.near().dht().context().offheap() : ctx.offheap(); //First count entries... int cnt = (int)offheapManager.cacheEntriesCount(ctx.cacheId(), part); GridCacheAffinityManager affinity = ctx.affinity(); AffinityTopologyVersion topVer = affinity.affinityTopologyVersion(); //And then find out whether they are primary or backup ones. int primaryCnt = 0; int backupCnt = 0; if (affinity.primaryByPartition(ctx.localNode(), part, topVer)) primaryCnt = cnt; else if (affinity.backupByPartition(ctx.localNode(), part, topVer)) backupCnt = cnt; return new T2<>(primaryCnt, backupCnt); }
!affNodes.get(0).equals(dht.context().affinity().primaryByPartition(p, readyVer));
boolean keyPrimary = ctx.affinity().primaryByPartition(ctx.localNode(), part, topVer);
/** * Apply filter. * * @param part Partition. * @return {@code True} if passed. */ public boolean applyPartition(int part) { if (parts == null) return aff.primaryByPartition(locNode, part, topVer); else return parts.contains(part); } }
/** * @param key Key to check. * @param topVer Topology version. * @return Primary node for given key. */ @Nullable public ClusterNode primaryByKey(Object key, AffinityTopologyVersion topVer) { return primaryByPartition(partition(key), topVer); }
/** * @param n Node to check. * @param part Partition. * @param topVer Topology version. * @return {@code True} if checked node is primary for given partition. */ public boolean primaryByPartition(ClusterNode n, int part, AffinityTopologyVersion topVer) { return F.eq(primaryByPartition(part, topVer), n); }
/** * @param entry Entry. * @return {@code True} if local node is current primary for given entry. */ private boolean primaryLocal(GridCacheEntryEx entry) { return entry.context().affinity().primaryByPartition(cctx.localNode(), entry.partition(), AffinityTopologyVersion.NONE); }
/** * @param nodeId Primary node ID. * @param topVer Topology version. */ private void primaryNode(UUID nodeId, AffinityTopologyVersion topVer) { assert lockedByCurrentThread(); assert nodeId != null; ClusterNode primary = null; try { primary = cctx.affinity().primaryByPartition(part, topVer); } catch (IllegalStateException ignore) { // Do not have affinity history. } if (primary == null || !nodeId.equals(primary.id())) { this.topVer = AffinityTopologyVersion.NONE; return; } if (topVer.compareTo(this.topVer) > 0) this.topVer = topVer; }
/** {@inheritDoc} */ @Override public long localSizeLong(int part, CachePeekMode[] peekModes) throws IgniteCheckedException { PeekModes modes = parsePeekModes(peekModes, true); long size = 0; if (modes.near) size += nearSize(); // Swap and offheap are disabled for near cache. if (modes.offheap) { AffinityTopologyVersion topVer = ctx.affinity().affinityTopologyVersion(); IgniteCacheOffheapManager offheap = ctx.offheap(); if (ctx.affinity().primaryByPartition(ctx.localNode(), part, topVer) && modes.primary || ctx.affinity().backupByPartition(ctx.localNode(), part, topVer) && modes.backup) size += offheap.cacheEntriesCount(ctx.cacheId(), part); } return size; }