/** {@inheritDoc} */ @Override public Affinity affinity() { return delegate.get().affinity(); }
/** * Maps affinity key to node. * * @param affinityKey Affinity key to map. * @return Primary node for this key. */ public Collection<ClusterNode> affinityNodes(Object affinityKey) { return dataCache.affinity().mapKeyToPrimaryAndBackups(affinityKey); }
/** * Maps affinity key to node. * * @param affinityKey Affinity key to map. * @return Primary node for this key. */ public ClusterNode affinityNode(Object affinityKey) { return dataCache.affinity().mapKeyToNode(affinityKey); }
@Override public int partition(String cacheName, Object key) { return ctx.cache().cache(cacheName).affinity().partition(key); }
/** * Generates next affinity key for local node based on current topology. If previous affinity key maps * on local node, return previous affinity key to prevent unnecessary file map growth. * * @param prevAffKey Affinity key of previous block. * @return Affinity key. */ @SuppressWarnings("ConstantConditions") public IgniteUuid nextAffinityKey(@Nullable IgniteUuid prevAffKey) { // Do not generate affinity key for non-affinity nodes. if (!dataCache.context().affinityNode()) return null; UUID nodeId = igfsCtx.kernalContext().localNodeId(); if (prevAffKey != null && dataCache.affinity().mapKeyToNode(prevAffKey).isLocal()) return prevAffKey; while (true) { IgniteUuid key = new IgniteUuid(nodeId, affKeyGen.getAndIncrement()); if (dataCache.affinity().mapKeyToNode(key).isLocal()) return key; } }
/** {@inheritDoc} */ @Override public Map<UUID, Integer> serviceTopology(String name, long timeout) throws IgniteCheckedException { IgniteInternalCache<Object, Object> cache = serviceCache(); ClusterNode node = cache.affinity().mapKeyToNode(name); final ServiceTopologyCallable call = new ServiceTopologyCallable(name); return ctx.closure().callAsyncNoFailover( GridClosureCallMode.BROADCAST, call, Collections.singletonList(node), false, timeout, true).get(); }
@Override public GridRestResponse applyx(IgniteInternalFuture<?> f) throws IgniteCheckedException { GridCacheRestResponse resp = new GridCacheRestResponse(); resp.setResponse(f.get()); if (key != null) resp.setAffinityNodeId(c.cache().affinity().mapKeyToNode(key).id().toString()); return resp; } };
/** * Check if there is missed keys. * * @throws IgniteCheckedException if failed. */ private static void checkForMissedKeys(IgniteEx ignite, Collection<Integer> exp, List<Cache.Entry<Integer, ?>> all) throws IgniteCheckedException { if (exp.size() == 0) return; IgniteInternalCache<Integer, Person> cache = ignite.cachex(PERSON_CACHE); assertNotNull(cache); StringBuilder sb = new StringBuilder(); Affinity<Integer> aff = cache.affinity(); for (Integer key : exp) { Integer part = aff.partition(key); sb.append( String.format("Query did not return expected key '%d' (exists: %s), partition '%d', partition nodes: ", key, cache.get(key) != null, part)); Collection<ClusterNode> partNodes = aff.mapPartitionToPrimaryAndBackups(part); for (ClusterNode node : partNodes) sb.append(node).append(" "); sb.append(";\n"); } sb.append("Returned keys: "); for (Cache.Entry e : all) sb.append(e.getKey()).append(" "); sb.append(";\n"); fail(sb.toString()); }
@Override public void run() { assertTrue(ignite.cachex(cctx(queue2).cache().name()).affinity().isPrimaryOrBackup( ignite.cluster().localNode(), "Queue2")); assertEquals(100, queue2.take().intValue()); } });
ClusterNode primaryNode = dataCachePrj.cache().affinity().mapKeyToNode(key);
/** * Fill cache. * * @throws IgniteCheckedException if failed. */ private static Set<Integer> populateCache(IgniteEx ignite, boolean loc, int cnt, IgnitePredicate<Integer> expectedEntryFilter) throws IgniteCheckedException { IgniteInternalCache<Integer, Person> cache = ignite.cachex(PERSON_CACHE); assertNotNull(cache); Random rand = new Random(); HashSet<Integer> exp = new HashSet<>(); Affinity<Integer> aff = cache.affinity(); ClusterNode localNode = cache.context().localNode(); for (int i = 0; i < cnt; i++) { int val = rand.nextInt(cnt); cache.put(val, new Person(String.valueOf(val), val)); if (expectedEntryFilter.apply(val) && (!loc || aff.isPrimary(localNode, val))) exp.add(val); } return exp; }
@Override public Integer call() { assertTrue(ignite.cachex(cctx(queue2).cache().name()).affinity().isPrimaryOrBackup( ignite.cluster().localNode(), "Queue2")); return queue2.take(); } });
dataCache.affinity().isPrimaryOrBackup(igfsCtx.kernalContext().discovery().localNode(), key)) { log.debug("Reading non-local data block [path=" + path + ", fileInfo=" + fileInfo + ", blockIdx=" + blockIdx + ']');
Collection<IgfsBlockLocation> res = new LinkedList<>(); splitBlocks(start, len, maxLen, dataCache.affinity().mapKeyToPrimaryAndBackups( new IgfsBlockKey(info.id(), info.affinityKey(), info.evictExclude(), 0)), res); long partEnd = Math.min(range.endOffset() + 1, end); Collection<ClusterNode> affNodes = dataCache.affinity().mapKeyToPrimaryAndBackups( range.affinityKey());
grpIdx * grpSize); Collection<ClusterNode> affNodes = dataCache.affinity().mapKeyToPrimaryAndBackups(key);
if (cache.cache().affinity().isPrimary(ctx.discovery().localNode(), key)) { try { cache.getAndRemove(key);
/** * Test node invalidation when cache meta is corrupted. */ @Test public void testCacheMetaCorruption() throws Exception { IgniteEx ignite = startGrid(0); ignite.cluster().active(true); IgniteInternalCache cache = ignite.cachex(CACHE_NAME1); cache.put(1, 1); int partId = cache.affinity().partition(1); int grpId = cache.context().group().groupId(); corruptTreeRoot(ignite, (PageMemoryEx)cache.context().dataRegion().pageMemory(), grpId, partId); ignite.cluster().active(false); stopGrid(0); try { startGrid(0); ignite.cluster().active(true); cache.put(1, 1); } catch (Exception e) { // No-op. } waitFailure(StorageException.class); }
/** * Maps affinity key to node. * * @param affinityKey Affinity key to map. * @return Primary node for this key. */ public Collection<ClusterNode> affinityNodes(Object affinityKey) { return dataCache.affinity().mapKeyToPrimaryAndBackups(affinityKey); }
/** * Maps affinity key to node. * * @param affinityKey Affinity key to map. * @return Primary node for this key. */ public ClusterNode affinityNode(Object affinityKey) { return dataCache.affinity().mapKeyToNode(affinityKey); }
@Override public GridRestResponse applyx(IgniteInternalFuture<?> f) throws IgniteCheckedException { GridCacheRestResponse resp = new GridCacheRestResponse(); resp.setResponse(f.get()); if (key != null) resp.setAffinityNodeId(c.cache().affinity().mapKeyToNode(key).id().toString()); return resp; } };