@Override public Object call() throws Exception { return affinity.mapPartitionToPrimaryAndBackups(0); } }, IgniteException.class, EXPECTED_MSG);
/** {@inheritDoc} */ @Override public Collection<ClusterNode> mapPartitionToPrimaryAndBackups(int part) { CacheOperationContext old = gate.enter(null); try { return delegate.mapPartitionToPrimaryAndBackups(part); } finally { gate.leave(old); } }
/** {@inheritDoc} */ @Override public Collection<ClusterNode> call() throws Exception { return affinity().mapPartitionToPrimaryAndBackups(part); } }
/** * @param g Grid. * @param p Partition. * @return Affinity nodes. */ private Collection<ClusterNode> affinityNodes(Ignite g, int p) { return affinity(g).mapPartitionToPrimaryAndBackups(p); }
/** * 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()); }
Collection<ClusterNode> results = affinity.mapPartitionToPrimaryAndBackups(x);
/** * * @param ignite Grid * @param key Key. * @return Primary node id. */ @SuppressWarnings("unchecked") private static UUID primaryId(Ignite ignite, Object key) { Affinity aff = ignite.affinity(DEFAULT_CACHE_NAME); Collection<ClusterNode> affNodes = aff.mapPartitionToPrimaryAndBackups(aff.partition(key)); ClusterNode first = F.first(affNodes); assert first != null; return first.id(); }
/** @param cnt Count. */ private Map<UUID, T2<Set<Integer>, Set<Integer>>> mapKeys(int cnt) { Affinity<Object> aff = affinity(0); //Mapping primary and backup keys on node Map<UUID, T2<Set<Integer>, Set<Integer>>> map = new HashMap<>(); for (int i = 0; i < GRID_CNT; i++) { IgniteEx grid = grid(i); map.put(grid.cluster().localNode().id(), new T2<Set<Integer>, Set<Integer>>(new HashSet<Integer>(), new HashSet<Integer>())); } for (int key = 1; key <= cnt; key++) { Integer part = aff.partition(key); assert part != null; Collection<ClusterNode> nodes = aff.mapPartitionToPrimaryAndBackups(part); ClusterNode primary = F.first(nodes); map.get(primary.id()).get1().add(key); if (mapDebug) info("Mapped key to primary node [key=" + key + ", node=" + U.toShortString(primary)); for (ClusterNode n : nodes) { if (n != primary) { map.get(n.id()).get2().add(key); if (mapDebug) info("Mapped key to backup node [key=" + key + ", node=" + U.toShortString(n)); } } } return map; }
/** * @param nodes Count nodes. * @param killedNodeIdx Killed node index. * @param updCntrs Update counters. */ private void checkPartCounter(int nodes, int killedNodeIdx, Map<Integer, Long> updCntrs) { for (int i = 0; i < nodes; i++) { if (i == killedNodeIdx) continue; Affinity<Object> aff = grid(i).affinity(DEFAULT_CACHE_NAME); CachePartitionPartialCountersMap act = grid(i).cachex(DEFAULT_CACHE_NAME).context().topology() .localUpdateCounters(false); for (Map.Entry<Integer, Long> e : updCntrs.entrySet()) { if (aff.mapPartitionToPrimaryAndBackups(e.getKey()).contains(grid(i).localNode())) { int partIdx = act.partitionIndex(e.getKey()); assertEquals(e.getValue(), (Long)act.updateCounterAt(partIdx)); } } } }
/** * Check mapPartitionToPrimaryAndBackups and mapPartitionToNode methods. * * @param testAff Affinity1. * @param aff Affinity2. */ private void checkMapPartitionToNode(Affinity testAff, Affinity aff) { assertEquals(aff.partitions(), testAff.partitions()); for (int part = 0; part < aff.partitions(); ++part) { assertEquals(testAff.mapPartitionToNode(part).id(), aff.mapPartitionToNode(part).id()); checkEqualCollection(testAff.mapPartitionToPrimaryAndBackups(part), aff.mapPartitionToPrimaryAndBackups(part)); } }
/** * @param topVer Topology version. * @throws Exception If failed. */ private void checkAffinity(long topVer) throws Exception { awaitTopology(topVer); Affinity<Object> aff = grid(0).affinity(DEFAULT_CACHE_NAME); for (Ignite grid : Ignition.allGrids()) { try { if (grid.cluster().localNode().id().equals(grid(0).localNode().id())) continue; Affinity<Object> checkAff = grid.affinity(DEFAULT_CACHE_NAME); for (int p = 0; p < PARTS; p++) assertEquals(aff.mapPartitionToPrimaryAndBackups(p), checkAff.mapPartitionToPrimaryAndBackups(p)); } catch (IllegalArgumentException ignored) { // Skip the node without cache. } } }
/** * @param c Cache. * @param cnt Key count. */ private void checkKeys(IgniteCache<Integer, String> c, int cnt) { Affinity<Integer> aff = affinity(c); boolean sync = isSync(c); Ignite ignite = c.unwrap(Ignite.class); for (int i = 0; i < cnt; i++) { if (aff.mapPartitionToPrimaryAndBackups(aff.partition(i)).contains(ignite.cluster().localNode())) { String val = sync ? c.localPeek(i, CachePeekMode.ONHEAP) : c.get(i); assertEquals("Key check failed [igniteInstanceName=" + ignite.name() + ", cache=" + c.getName() + ", key=" + i + ']', Integer.toString(i), val); } } } }
Collection<ClusterNode> nodes = aff.mapPartitionToPrimaryAndBackups(p);
/** * @param cache Cache. * @param cnt Key count. * @param grids Grids. */ private void checkKeys(IgniteCache<Integer, String> cache, int cnt, Iterable<Ignite> grids) { Affinity<Integer> aff = affinity(cache); Ignite ignite = cache.unwrap(Ignite.class); ClusterNode loc = ignite.cluster().localNode(); boolean sync = cache.getConfiguration(CacheConfiguration.class).getRebalanceMode() == SYNC; for (int i = 0; i < cnt; i++) { Collection<ClusterNode> nodes = ignite.cluster().nodes(); Collection<ClusterNode> affNodes = aff.mapPartitionToPrimaryAndBackups(aff.partition(i)); assert !affNodes.isEmpty(); if (affNodes.contains(loc)) { String val = sync ? cache.localPeek(i) : cache.get(i); ClusterNode primaryNode = F.first(affNodes); assert primaryNode != null; boolean primary = primaryNode.equals(loc); assertEquals("Key check failed [igniteInstanceName=" + ignite.name() + ", cache=" + cache.getName() + ", key=" + i + ", expected=" + i + ", actual=" + val + ", part=" + aff.partition(i) + ", primary=" + primary + ", affNodes=" + U.nodeIds(affNodes) + ", locId=" + loc.id() + ", allNodes=" + U.nodeIds(nodes) + ", allParts=" + top2string(grids) + ']', Integer.toString(i), val); } } }
/** * @param cacheName Cache name. * @param expNodes Expected number of nodes per partition. */ private void checkCache(String cacheName, int expNodes) { log.info("Test cache: " + cacheName); Affinity<Object> aff0 = ignite(0).affinity(cacheName); Ignite client = ignite(NODE_CNT - 1); assertTrue(client.configuration().isClientMode()); ClusterNode clientNode = client.cluster().localNode(); for (int i = 0; i < NODE_CNT; i++) { Ignite ignite = ignite(i); Affinity<Object> aff = ignite.affinity(cacheName); for (int part = 0; part < aff.partitions(); part++) { Collection<ClusterNode> nodes = aff.mapPartitionToPrimaryAndBackups(part); assertEquals(expNodes, nodes.size()); assertEquals(aff0.mapPartitionToPrimaryAndBackups(part), nodes); assertFalse(nodes.contains(clientNode)); assertEquals(aff0.partition(part), aff.partition(part)); TestKey key = new TestKey(part, part + 1); assertEquals(aff0.partition(key), aff.partition(key)); assertEquals(aff0.mapKeyToPrimaryAndBackups(key), aff.mapKeyToPrimaryAndBackups(key)); } } }
assertEqualsCollections(ig.affinity(cacheName).mapPartitionToPrimaryAndBackups(p), ig0.affinity(cacheName).mapPartitionToPrimaryAndBackups(p));
Collection<ClusterNode> partNodes = cacheAff.mapPartitionToPrimaryAndBackups(p);
if (aff.mapPartitionToPrimaryAndBackups(aff.partition(i)).contains(g1.cluster().localNode())) { GridDhtPartitionTopology top = dht.topology();
g0.affinity(cfg.getName()).mapPartitionToPrimaryAndBackups(loc.id());
U.toShortString(ignite(gridIdx).affinity(DEFAULT_CACHE_NAME).mapPartitionToPrimaryAndBackups(part)) + ']');