/** * @return {@code True} if local node can calculate affinity on it's own for this partition map exchange. */ private boolean canCalculateAffinity() { GridCacheAffinityFunction affFunc = cctx.config().getAffinity(); // Do not request affinity from remote nodes if affinity function is not centralized. if (!U.hasAnnotation(affFunc, GridCacheCentralizedAffinityFunction.class)) return true; // If local node did not initiate exchange or local node is the only cache node in grid. Collection<GridNode> affNodes = CU.affinityNodes(cctx, exchId.topologyVersion()); return !exchId.nodeId().equals(cctx.localNodeId()) || (affNodes.size() == 1 && affNodes.contains(cctx.localNode())); }
/** * @param topVer Topology version. * @return Nodes where set data request should be sent. * @throws GridException If all cache nodes left grid. */ @SuppressWarnings("unchecked") private Collection<GridNode> dataNodes(long topVer) throws GridException { if (ctx.isLocal() || ctx.isReplicated()) return Collections.singleton(ctx.localNode()); Collection<GridNode> nodes; if (collocated) { List<GridNode> nodes0 = ctx.affinity().nodes(hdrPart, topVer); nodes = !nodes0.isEmpty() ? Collections.singleton(nodes0.contains(ctx.localNode()) ? ctx.localNode() : F.first(nodes0)) : nodes0; } else nodes = CU.affinityNodes(ctx, topVer); if (nodes.isEmpty()) throw new GridException("Failed to get set data, all cache nodes left grid."); return nodes; }
/** * @param ctx Context. * @param keys Keys. * @return Mapped keys. */ @SuppressWarnings( {"unchecked", "MismatchedQueryAndUpdateOfCollection"}) public static <K> Map<GridNode, Collection<K>> mapKeysToNodes(GridCacheContext<K, ?> ctx, Collection<? extends K> keys) { if (keys == null || keys.isEmpty()) return Collections.emptyMap(); // Map all keys to local node for local caches. if (ctx.config().getCacheMode() == LOCAL) return F.asMap(ctx.localNode(), (Collection<K>)keys); long topVer = ctx.discovery().topologyVersion(); if (CU.affinityNodes(ctx, topVer).isEmpty()) return Collections.emptyMap(); if (keys.size() == 1) return Collections.singletonMap(ctx.affinity().primary(F.first(keys), topVer), (Collection<K>)keys); Map<GridNode, Collection<K>> map = new GridLeanMap<>(5); for (K k : keys) { GridNode primary = ctx.affinity().primary(k, topVer); Collection<K> mapped = map.get(primary); if (mapped == null) map.put(primary, mapped = new LinkedList<>()); mapped.add(k); } return map; }
new GridDhtAssignmentFetchFuture<>(cctx, exchId.topologyVersion(), CU.affinityNodes(cctx));
if (CU.affinityNodes(cctx, topVer).isEmpty()) { onDone(new GridTopologyException("Failed to map keys for cache (all partition nodes left the grid).")); Map<GridNode, LinkedHashMap<K, Boolean>> mappings = U.newHashMap(CU.affinityNodes(cctx, topVer).size());
Collection<GridNode> affNodes = CU.affinityNodes(cctx, topVer);
Collection<GridNode> topNodes = CU.affinityNodes(cctx, topVer);
if (CU.affinityNodes(cctx, topVer).isEmpty()) { onDone(new GridTopologyException("Failed to map keys for near-only cache (all " + "partition nodes left the grid)."));
if (CU.affinityNodes(cctx, topVer).isEmpty()) { onDone(new GridTopologyException("Failed to map keys for cache (all partition nodes left the grid)."));
if (CU.affinityNodes(cctx, topVer).isEmpty()) { onDone(new GridTopologyException("Failed to map keys for cache (all partition nodes left the grid)."));
if (CU.affinityNodes(cctx, topVer).isEmpty()) { onDone(new GridTopologyException("Failed to map keys for near-only cache (all " + "partition nodes left the grid)."));
long topVer = cctx.topologyVersionFuture().get(); Collection<GridNode> nodes = CU.affinityNodes(cctx, topVer);