/** * Gets current topology version. * * @return Topology version. */ private AffinityTopologyVersion topologyVersion() { return cctx.affinity().affinityTopologyVersion(); } }
/** {@inheritDoc} */ @Override public int partition() { return cctx.affinity().partition(key); } }
/** * @param ctx Cache context. * @param key Cache key. */ public GridNearCacheEntry( GridCacheContext ctx, KeyCacheObject key ) { super(ctx, key); part = ctx.affinity().partition(key); }
/** * @param key Entry key. * @return Entry (never {@code null}). */ public final GridCacheEntryEx entryEx(KeyCacheObject key) { return entryEx(key, ctx.affinity().affinityTopologyVersion()); }
/** {@inheritDoc} */ @Override public void invalidPartition(int part) { if (entry != null && entry.context().affinity().partition(entry.key()) == part) entry = null; }
/** * @param e Transaction entry. * @param topVer Topology version. * @return {@code True} if entry is locally mapped as a primary or back up node. */ protected boolean isNearLocallyMapped(GridCacheEntryEx e, AffinityTopologyVersion topVer) { return ctx.affinity().partitionBelongs(ctx.localNode(), e.partition(), topVer); }
/** * @param cctx Cache context. * @param key Key. * @return Data store. */ @Nullable private CacheDataStore dataStore(GridCacheContext cctx, KeyCacheObject key) { if (grp.isLocal()) return locCacheDataStore; GridDhtLocalPartition part = grp.topology().localPartition(cctx.affinity().partition(key), null, false); return part != null ? dataStore(part) : null; }
/** {@inheritDoc} */ @Override protected boolean updateNearCache(GridCacheContext cacheCtx, KeyCacheObject key, AffinityTopologyVersion topVer) { if (!cacheCtx.isDht() || !isNearEnabled(cacheCtx) || cctx.localNodeId().equals(nearNodeId)) return false; if (cacheCtx.config().getBackups() == 0) return true; // Check if we are on the backup node. return !cacheCtx.affinity().backupsByKey(key, topVer).contains(cctx.localNode()); }
/** */ private static Optional<IgniteCacheOffheapManager.CacheDataStore> dataStore( GridCacheContext<?, ?> cctx, Object key) { int p = cctx.affinity().partition(key); IgniteCacheOffheapManager offheap = cctx.offheap(); return StreamSupport.stream(offheap.cacheDataStores().spliterator(), false) .filter(ds -> ds.partId() == p) .findFirst(); } }
/** {@inheritDoc} */ @Override public int[] primaryPartitions(ClusterNode n) { A.notNull(n, "n"); Set<Integer> parts = cctx.affinity().primaryPartitions(n.id(), topologyVersion()); return U.toIntArray(parts); }
/** */ private static Optional<IgniteCacheOffheapManager.CacheDataStore> dataStore( GridCacheContext<?, ?> cctx, Object key) { int p = cctx.affinity().partition(key); return StreamSupport.stream(cctx.offheap().cacheDataStores().spliterator(), false) .filter(ds -> ds.partId() == p) .findFirst(); } }
/** {@inheritDoc} */ @Override public int[] backupPartitions(ClusterNode n) { A.notNull(n, "n"); Set<Integer> parts = cctx.affinity().backupPartitions(n.id(), topologyVersion()); return U.toIntArray(parts); }
/** */ private static Optional<IgniteCacheOffheapManager.CacheDataStore> dataStore( GridCacheContext<?, ?> cctx, Object key) { int p = cctx.affinity().partition(key); return StreamSupport.stream(cctx.offheap().cacheDataStores().spliterator(), false) .filter(ds -> ds.partId() == p) .findFirst(); }
/** {@inheritDoc} */ @Override public IgniteInternalFuture<?> removeAllAsync() { GridFutureAdapter<Void> opFut = new GridFutureAdapter<>(); AffinityTopologyVersion topVer = ctx.affinity().affinityTopologyVersion(); CacheOperationContext opCtx = ctx.operationContextPerCall(); removeAllAsync(opFut, topVer, opCtx != null && opCtx.skipStore(), opCtx != null && opCtx.isKeepBinary()); return opFut; }
/** */ private KeyCacheObject toKey(EnlistOperation op, Object cur) { KeyCacheObject key = cctx.toCacheKeyObject(op.isDeleteOrLock() ? cur : ((IgniteBiTuple)cur).getKey()); if (key.partition() == -1) key.partition(cctx.affinity().partition(key)); return key; }
/** {@inheritDoc} */ @Override public long primarySizeLong() { long sum = 0; AffinityTopologyVersion topVer = ctx.affinity().affinityTopologyVersion(); for (GridDhtLocalPartition p : topology().currentLocalPartitions()) { if (p.primary(topVer)) sum += p.dataStore().cacheSize(ctx.cacheId()); } return sum; }
/** {@inheritDoc} */ @Override public void run(int idx) throws Exception { GridCacheContext<String, Integer> ctx = ((IgniteKernal)ignite).<String, Integer>internalCache(cacheName).context(); int size = 0; for (String key : map.keySet()) if (ctx.affinity().keyLocalNode(key, ctx.discovery().topologyVersionEx())) size++; assertEquals("Incorrect key size on cache #" + idx, size, ignite.cache(ctx.name()).localSize(ALL)); } }
/** {@inheritDoc} */ @Override public void run(int idx) throws Exception { GridCacheContext<String, Integer> ctx = ((IgniteKernal)ignite).<String, Integer>internalCache(DEFAULT_CACHE_NAME).context(); int size = 0; for (String key : keys) if (ctx.affinity().keyLocalNode(key, ctx.discovery().topologyVersionEx())) size++; assertEquals("Incorrect key size on cache #" + idx, size, ignite.cache(DEFAULT_CACHE_NAME).localSize(ALL)); } }
/** {@inheritDoc} */ @Override public long getNonHeapMemoryUsed() { Collection<GridCacheAdapter<?, ?>> caches = ctx.cache().internalCaches(); long nonHeapUsed = vmMetrics.getNonHeapMemoryUsed(); for (GridCacheAdapter<?, ?> cache : caches) if (cache.context().statisticsEnabled() && cache.context().started() && cache.context().affinity().affinityTopologyVersion().topologyVersion() > 0) nonHeapUsed += cache.metrics0().getOffHeapAllocatedSize(); return nonHeapUsed; }
/** * @param node Node. * @param key Key. * @return Extracts update counter of partition which key belongs to. */ private long getUpdateCounter(IgniteEx node, Integer key) { int partId = node.cachex(DEFAULT_CACHE_NAME).context().affinity().partition(key); GridDhtLocalPartition part = node.cachex(DEFAULT_CACHE_NAME).context().dht().topology().localPartition(partId); assert part != null; return part.updateCounter(); } }