/** * @param expVer Expected topology version. * @param curVer Current topology version. * @return {@code True} if cache affinity changed and operation should be remapped. */ protected final boolean needRemap(AffinityTopologyVersion expVer, AffinityTopologyVersion curVer, Collection<KeyCacheObject> keys) { if (curVer.equals(expVer)) return false; AffinityTopologyVersion lastAffChangedTopVer = ctx.shared().exchange().lastAffinityChangedTopologyVersion(expVer); if (curVer.compareTo(lastAffChangedTopVer) >= 0 && curVer.compareTo(expVer) <= 0) return false; // TODO IGNITE-7164 check mvcc crd for mvcc enabled txs. Collection<ClusterNode> cacheNodes0 = ctx.discovery().cacheGroupAffinityNodes(ctx.groupId(), expVer); Collection<ClusterNode> cacheNodes1 = ctx.discovery().cacheGroupAffinityNodes(ctx.groupId(), curVer); if (!cacheNodes0.equals(cacheNodes1) || ctx.affinity().affinityTopologyVersion().compareTo(curVer) < 0) return true; try { List<List<ClusterNode>> aff1 = ctx.affinity().assignments(expVer); List<List<ClusterNode>> aff2 = ctx.affinity().assignments(curVer); return !aff1.equals(aff2); } catch (IllegalStateException ignored) { return true; } }
/** * @param node Node. * @param topVer Topology version. * @param cache Cache name. * @return Affinity assignments. */ private List<List<ClusterNode>> affinity(Ignite node, AffinityTopologyVersion topVer, String cache) { GridCacheContext cctx = ((IgniteKernal)node).context().cache().internalCache(cache).context(); return cctx.affinity().assignments(topVer); }
List<List<ClusterNode>> aff1 = ctx.affinity().assignments(expVer); List<List<ClusterNode>> aff2 = ctx.affinity().assignments(curVer);
topVer = ctx.cache().context().exchange().readyAffinityVersion(); List<List<ClusterNode>> assignments = cctx.affinity().assignments(topVer);
affinity().assignments(new AffinityTopologyVersion(topVer));
/** * @throws Exception If failed. */ private void checkAffinity() throws Exception { List<Ignite> nodes = G.allGrids(); ClusterNode crdNode = null; for (Ignite node : nodes) { ClusterNode locNode = node.cluster().localNode(); if (crdNode == null || locNode.order() < crdNode.order()) crdNode = locNode; } AffinityTopologyVersion topVer = ((IgniteKernal)grid(crdNode)). context().cache().context().exchange().readyAffinityVersion(); Map<String, List<List<ClusterNode>>> affMap = new HashMap<>(); for (Ignite node : nodes) { IgniteKernal node0 = (IgniteKernal)node; for (IgniteInternalCache cache : node0.context().cache().caches()) { List<List<ClusterNode>> aff = affMap.get(cache.name()); List<List<ClusterNode>> aff0 = cache.context().affinity().assignments(topVer); if (aff != null) assertEquals(aff, aff0); else affMap.put(cache.name(), aff0); } } }
List<List<ClusterNode>> aff0 = cache.context().affinity().assignments(topVer);
List<List<ClusterNode>> aff2 = cctx.affinity().assignments(topVer);
/** * @param expVer Expected topology version. * @param curVer Current topology version. * @return {@code True} if cache affinity changed and operation should be remapped. */ protected final boolean needRemap(AffinityTopologyVersion expVer, AffinityTopologyVersion curVer) { if (expVer.equals(curVer)) return false; // TODO IGNITE-7164 check mvcc crd for mvcc enabled txs. Collection<ClusterNode> cacheNodes0 = ctx.discovery().cacheGroupAffinityNodes(ctx.groupId(), expVer); Collection<ClusterNode> cacheNodes1 = ctx.discovery().cacheGroupAffinityNodes(ctx.groupId(), curVer); if (!cacheNodes0.equals(cacheNodes1) || ctx.affinity().affinityTopologyVersion().compareTo(curVer) < 0) return true; try { List<List<ClusterNode>> aff1 = ctx.affinity().assignments(expVer); List<List<ClusterNode>> aff2 = ctx.affinity().assignments(curVer); return !aff1.equals(aff2); } catch (IllegalStateException ignored) { return true; } }
/** * @param expVer Expected topology version. * @param curVer Current topology version. * @param req Request. * @return {@code True} if cache affinity changed and request should be remapped. */ private boolean needRemap(AffinityTopologyVersion expVer, AffinityTopologyVersion curVer, GridNearTxPrepareRequest req) { if (expVer.equals(curVer)) return false; // TODO IGNITE-6754 check mvcc crd for mvcc enabled txs. for (IgniteTxEntry e : F.concat(false, req.reads(), req.writes())) { GridCacheContext ctx = e.context(); Collection<ClusterNode> cacheNodes0 = ctx.discovery().cacheGroupAffinityNodes(ctx.groupId(), expVer); Collection<ClusterNode> cacheNodes1 = ctx.discovery().cacheGroupAffinityNodes(ctx.groupId(), curVer); if (!cacheNodes0.equals(cacheNodes1) || ctx.affinity().affinityTopologyVersion().compareTo(curVer) < 0) return true; try { List<List<ClusterNode>> aff1 = ctx.affinity().assignments(expVer); List<List<ClusterNode>> aff2 = ctx.affinity().assignments(curVer); if (!aff1.equals(aff2)) return true; } catch (IllegalStateException ignored) { return true; } } return false; }
topVer = ctx.cache().context().exchange().readyAffinityVersion(); List<List<ClusterNode>> assignments = cctx.affinity().assignments(topVer);