/** {@inheritDoc} */ @Override public boolean valid(AffinityTopologyVersion topVer) { assert topVer.topologyVersion() > 0 : "Topology version is invalid: " + topVer; AffinityTopologyVersion topVer0 = this.topVer; if (topVer0.equals(topVer)) return true; if (topVer0.equals(AffinityTopologyVersion.NONE) || topVer.compareTo(topVer0) < 0) return false; try { if (cctx.affinity().primaryChanged(partition(), topVer0, topVer)) { this.topVer = AffinityTopologyVersion.NONE; return false; } if (cctx.affinity().backupByPartition(cctx.localNode(), part, topVer)) { this.topVer = AffinityTopologyVersion.NONE; return false; } this.topVer = topVer; return true; } catch (IllegalStateException ignore) { // Do not have affinity history. this.topVer = AffinityTopologyVersion.NONE; return false; } }
/** {@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; }
/** * @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); }
int part = partCntrs.partition(i); if (affinity.backupByPartition(node, part, top)) resCntrs.add(part, partCntrs.initialCounter(i), partCntrs.updatesCount(i));
/** {@inheritDoc} */ @Override public boolean valid(AffinityTopologyVersion topVer) { assert topVer.topologyVersion() > 0 : "Topology version is invalid: " + topVer; AffinityTopologyVersion topVer0 = this.topVer; if (topVer0.equals(topVer)) return true; if (topVer0.equals(AffinityTopologyVersion.NONE) || topVer.compareTo(topVer0) < 0) return false; try { if (cctx.affinity().primaryChanged(partition(), topVer0, topVer)) { this.topVer = AffinityTopologyVersion.NONE; return false; } if (cctx.affinity().backupByPartition(cctx.localNode(), part, topVer)) { this.topVer = AffinityTopologyVersion.NONE; return false; } this.topVer = topVer; return true; } catch (IllegalStateException ignore) { // Do not have affinity history. this.topVer = AffinityTopologyVersion.NONE; return false; } }
/** {@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; }