/** {@inheritDoc} */ @Override public List<List<ClusterNode>> assignPartitions(AffinityFunctionContext affCtx) { List<List<ClusterNode>> assignments = new ArrayList<>(parts); Map<UUID, Collection<ClusterNode>> neighborhoodCache = exclNeighbors ? GridCacheUtils.neighbors(affCtx.currentTopologySnapshot()) : null; List<ClusterNode> nodes = affCtx.currentTopologySnapshot(); for (int i = 0; i < parts; i++) { List<ClusterNode> partAssignment = assignPartition(i, nodes, affCtx.backups(), neighborhoodCache); assignments.add(partAssignment); } return assignments; }
/** {@inheritDoc} */ @Override public List<List<ClusterNode>> assignPartitions(AffinityFunctionContext affCtx) { List<ClusterNode> nodes = new ArrayList<>(affCtx.currentTopologySnapshot()); nodes.sort(Comparator.comparing(o -> o.<String>attribute(ATTR_IGNITE_INSTANCE_NAME))); List<List<ClusterNode>> res = new ArrayList<>(parts); for (int i = 0; i < parts; i++) { Set<ClusterNode> n0 = new LinkedHashSet<>(); n0.add(nodes.get(i % nodes.size())); for (int j = 1; j <= affCtx.backups(); j++) n0.add(nodes.get((i + j) % nodes.size())); res.add(new ArrayList<>(n0)); } return res; }
/** {@inheritDoc} */ @Override public List<List<ClusterNode>> assignPartitions(AffinityFunctionContext affCtx) { List<List<ClusterNode>> assignments = new ArrayList<>(parts); Map<UUID, Collection<ClusterNode>> neighborhoodCache = exclNeighbors ? GridCacheUtils.neighbors(affCtx.currentTopologySnapshot()) : null; MessageDigest d = digest.get(); List<ClusterNode> nodes = affCtx.currentTopologySnapshot(); Map<ClusterNode, byte[]> nodesHash = U.newHashMap(nodes.size()); for (int i = 0; i < parts; i++) { List<ClusterNode> partAssignment = assignPartition(d, i, nodes, nodesHash, affCtx.backups(), neighborhoodCache); assignments.add(partAssignment); } return assignments; }
/** {@inheritDoc} */ @Override public List<List<ClusterNode>> assignPartitions(AffinityFunctionContext affCtx) { int parts = partitions(); List<List<ClusterNode>> assignments = new ArrayList<>(parts); Map<UUID, Collection<ClusterNode>> neighborhoodCache = isExcludeNeighbors() ? GridCacheUtils.neighbors(affCtx.currentTopologySnapshot()) : null; List<ClusterNode> nodes = affCtx.currentTopologySnapshot(); Map<Object, List<ClusterNode>> nodesByGrp = U.newHashMap(2); for (ClusterNode node : nodes) { Object grp = node.attribute(GRP_ATTR); List<ClusterNode> grpNodes = nodesByGrp.get(grp); if (grpNodes == null) nodesByGrp.put(grp, (grpNodes = new ArrayList<>())); grpNodes.add(node); } boolean split = nodesByGrp.size() == 2; for (int i = 0; i < parts; i++) { List<ClusterNode> partAssignment = assignPartition(i, split ? nodesByGrp.get(i % 2 == 0 ? EVEN_GRP : ODD_GRP) : nodes, affCtx.backups(), neighborhoodCache); assignments.add(partAssignment); } return assignments; } }
/** * Writes the affinity function context. * @param affCtx Affinity context. * @param writer Writer. * @param ctx Platform context. */ public static void writeAffinityFunctionContext(AffinityFunctionContext affCtx, BinaryRawWriterEx writer, PlatformContext ctx) { assert affCtx != null; assert writer != null; assert ctx != null; ctx.writeNodes(writer, affCtx.currentTopologySnapshot()); writer.writeInt(affCtx.backups()); writer.writeLong(affCtx.currentTopologyVersion().topologyVersion()); writer.writeInt(affCtx.currentTopologyVersion().minorTopologyVersion()); ctx.writeEvent(writer, affCtx.discoveryEvent()); // Write previous assignment List<List<ClusterNode>> prevAssignment = ((GridAffinityFunctionContextImpl)affCtx).prevAssignment(); if (prevAssignment == null) writer.writeInt(-1); else { writer.writeInt(prevAssignment.size()); for (List<ClusterNode> part : prevAssignment) ctx.writeNodes(writer, part); } }
/** {@inheritDoc} */ @Override public List<List<ClusterNode>> assignPartitions(AffinityFunctionContext affCtx) { List<List<ClusterNode>> assignments = new ArrayList<>(parts); Map<UUID, Collection<ClusterNode>> neighborhoodCache = exclNeighbors ? GridCacheUtils.neighbors(affCtx.currentTopologySnapshot()) : null; List<ClusterNode> nodes = affCtx.currentTopologySnapshot(); for (int i = 0; i < parts; i++) { List<ClusterNode> partAssignment = assignPartition(i, nodes, affCtx.backups(), neighborhoodCache); assignments.add(partAssignment); } return assignments; }
/** * Writes the affinity function context. * @param affCtx Affinity context. * @param writer Writer. * @param ctx Platform context. */ public static void writeAffinityFunctionContext(AffinityFunctionContext affCtx, BinaryRawWriterEx writer, PlatformContext ctx) { assert affCtx != null; assert writer != null; assert ctx != null; ctx.writeNodes(writer, affCtx.currentTopologySnapshot()); writer.writeInt(affCtx.backups()); writer.writeLong(affCtx.currentTopologyVersion().topologyVersion()); writer.writeInt(affCtx.currentTopologyVersion().minorTopologyVersion()); ctx.writeEvent(writer, affCtx.discoveryEvent()); // Write previous assignment List<List<ClusterNode>> prevAssignment = ((GridAffinityFunctionContextImpl)affCtx).prevAssignment(); if (prevAssignment == null) writer.writeInt(-1); else { writer.writeInt(prevAssignment.size()); for (List<ClusterNode> part : prevAssignment) ctx.writeNodes(writer, part); } }