/** * 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 Object call() throws Exception { return affinity.mapKeyToNode(key); } }, IgniteException.class, EXPECTED_MSG);
/** {@inheritDoc} */ @Override @Nullable public ClusterNode mapKeyToNode(K key) { CacheOperationContext old = gate.enter(null); try { return delegate.mapKeyToNode(key); } finally { gate.leave(old); } }
/** * @param key Key. * @return Primary node for the key. */ @Nullable private ClusterNode primaryNode(Integer key) { return affinity(0).mapKeyToNode(key); }
/** {@inheritDoc} */ @Override protected UUID run(@Nullable VisorCacheAffinityNodeTaskArg arg) throws IgniteException { assert arg != null; ClusterNode node = ignite.affinity(arg.getCacheName()).mapKeyToNode(arg.getKey()); return node != null ? node.id() : null; }
@Override public void run() { while (!fut.isDone()) assertNotNull(aff.mapKeyToNode(key)); } }, 5, "test-thread");
@Override public Object call() throws Exception { return g2.<Long>affinity(DEFAULT_CACHE_NAME).mapKeyToNode(i0); } }, IgniteException.class, "Failed to find cache");
/** {@inheritDoc} */ @Override public ClusterNode call() throws Exception { return affinity().mapKeyToNode(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; } };
/** {@inheritDoc} */ @Override protected Object executeJob(int gridSize, String arg) { A.notNull(arg, "task argument"); String[] split = arg.split(":", 2); A.ensure(split.length == 2, "Task argument should have format 'cacheName:affinityKey'."); String cacheName = split[0]; String affKey = split[1]; if ("null".equals(cacheName)) cacheName = null; ClusterNode node = ignite.affinity(cacheName).mapKeyToNode(affKey); return node.id().toString(); }
/** * @param key Key. * @return Primary node for the key. */ @Nullable private Ignite primaryGrid(Integer key) { ClusterNode n = affinity(0).mapKeyToNode(key); assert n != null; return G.ignite(n.id()); }
/** * */ @Test public void testMapKeyToNode() { assert grid(0).affinity(DEFAULT_CACHE_NAME).mapKeyToNode("1") == null; }
/** * Check mapKeyToNode, mapKeyToPrimaryAndBackups methods. * * @param testAff Affinity1. * @param aff Affinity2. */ private void checkMapKeyToNode(Affinity testAff, Affinity aff) { for (int i = 0; i < 10000; i++) { assertEquals(testAff.mapKeyToNode(i).id(), aff.mapKeyToNode(i).id()); checkEqualCollection(testAff.mapKeyToPrimaryAndBackups(i), aff.mapKeyToPrimaryAndBackups(i)); } }
/** {@inheritDoc} */ @Override public Object call() throws IgniteCheckedException { assert ignite.cluster().localNode().id().equals(ignite.affinity(DEFAULT_CACHE_NAME).mapKeyToNode(affKey).id()); assert ignite.cluster().localNode().id().equals(ignite.affinity(DEFAULT_CACHE_NAME).mapKeyToNode(key).id()); return null; } }
/** {@inheritDoc} */ @Override public void run() { Integer attempt = jobCtx.getAttribute(ATTR_ATTEMPT); if (attempt == null) attempt = 1; assertEquals(ignite.affinity(NON_DFLT_CACHE_NAME).mapKeyToNode(key), ignite.cluster().localNode()); jobCtx.setAttribute(ATTR_ATTEMPT, attempt + 1); if (attempt < callAttempt) throw new ComputeJobFailoverException("Failover exception."); else assertEquals(callAttempt, attempt); } }
/** {@inheritDoc} */ @Override public void applyx() throws IgniteCheckedException { assert ignite.cluster().localNode().id().equals(ignite.affinity(DEFAULT_CACHE_NAME).mapKeyToNode(affKey).id()); assert ignite.cluster().localNode().id().equals(ignite.affinity(DEFAULT_CACHE_NAME).mapKeyToNode(key).id()); } }
/** {@inheritDoc} */ @Override public Object call() throws IgniteCheckedException { Integer attempt = jobCtx.getAttribute(ATTR_ATTEMPT); if (attempt == null) attempt = 1; assertEquals(ignite.affinity(NON_DFLT_CACHE_NAME).mapKeyToNode(key), ignite.cluster().localNode()); jobCtx.setAttribute(ATTR_ATTEMPT, attempt + 1); if (attempt < callAttempt) throw new ComputeJobFailoverException("Failover exception."); else return attempt; } }
/** @throws Exception If failed. */ @Test public void testAffinity() throws Exception { waitTopologyUpdate(); Ignite g0 = grid(0); Ignite g1 = grid(1); for (int i = 0; i < 100; i++) assertEquals(g0.affinity(DEFAULT_CACHE_NAME).mapKeyToNode(i).id(), g1.affinity(DEFAULT_CACHE_NAME).mapKeyToNode(i).id()); }
/** @throws Exception If failed. */ @Test public void testProjectionAffinity() throws Exception { waitTopologyUpdate(); Ignite g0 = grid(0); Ignite g1 = grid(1); ClusterGroup g0Pinned = g0.cluster().forNodeIds(F.asList(g0.cluster().localNode().id())); ClusterGroup g01Pinned = g1.cluster().forNodeIds(F.asList(g0.cluster().localNode().id(), g1.cluster().localNode().id())); for (int i = 0; i < 100; i++) assertEquals(g0Pinned.ignite().affinity(DEFAULT_CACHE_NAME).mapKeyToNode(i).id(), g01Pinned.ignite().affinity(DEFAULT_CACHE_NAME).mapKeyToNode(i).id()); }