/** {@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); } }
/** {@inheritDoc} */ @Override public List<List<ClusterNode>> assignPartitions(AffinityFunctionContext ctx) { List<List<ClusterNode>> res = new ArrayList<>(partitions()); List<ClusterNode> topSnapshot = ctx.currentTopologySnapshot(); for (int part = 0; part < parts; part++) { res.add(F.isEmpty(topSnapshot) ? Collections.<ClusterNode>emptyList() : // Wrap affinity nodes with unmodifiable list since unmodifiable generic collection // doesn't provide equals and hashCode implementations. U.sealList(nodes(part, topSnapshot))); } return res; }
/** {@inheritDoc} */ @Override public List<List<ClusterNode>> assignPartitions(AffinityFunctionContext affCtx) { ClusterNode locNode = null; for (ClusterNode n : affCtx.currentTopologySnapshot()) { if (n.isLocal()) { locNode = n; break; } } if (locNode == null) throw new IgniteException("Local node is not included into affinity nodes for 'LOCAL' cache"); List<List<ClusterNode>> res = new ArrayList<>(partitions()); for (int part = 0; part < partitions(); part++) res.add(Collections.singletonList(locNode)); return Collections.unmodifiableList(res); }
/** {@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>> res = new ArrayList<>(); res.add(nodes(0, affCtx.currentTopologySnapshot())); return res; }
/** * 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; 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) { List<ClusterNode> nodes = affCtx.currentTopologySnapshot(); List<List<ClusterNode>> assign = new ArrayList<>(partitions()); for (int i = 0; i < partitions(); ++i) assign.add(Collections.singletonList(nodes.get(0))); return assign; } }
/** {@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; } }
/** {@inheritDoc} */ @Override public List<List<ClusterNode>> assignPartitions(AffinityFunctionContext affCtx) { List<ClusterNode> nodes = affCtx.currentTopologySnapshot(); List<List<ClusterNode>> assignmentParts = new ArrayList<>(partitions()); for (int part = 0; part < partitions(); part++) { int backups = part % nodes.size() + 1; List<ClusterNode> assignmentNodes = new ArrayList<>(backups); for (int backup = 0; backup < backups; backup++) assignmentNodes.add(nodes.get((part + part / nodes.size() + backup) % nodes.size())); assignmentParts.add(assignmentNodes); } return assignmentParts; }
/** {@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 ctx) { List<List<ClusterNode>> res = new ArrayList<>(parts); Collection<ClusterNode> topSnapshot = ctx.currentTopologySnapshot(); for (int part = 0; part < parts; part++) { res.add(F.isEmpty(topSnapshot) ? Collections.<ClusterNode>emptyList() : // Wrap affinity nodes with unmodifiable list since unmodifiable generic collection // doesn't provide equals and hashCode implementations. U.sealList(nodes(part, topSnapshot))); } return Collections.unmodifiableList(res); }
/** {@inheritDoc} */ @Override public List<List<ClusterNode>> assignPartitions(AffinityFunctionContext affCtx) { List<ClusterNode> nodes = affCtx.currentTopologySnapshot(); List<List<ClusterNode>> assignment = new ArrayList<>(PARTS_COUNT); for (int p = 0; p < PARTS_COUNT; p++) { // Get region for partition. int regionId = regionForPart(p); // Filter all nodes for region. AttributeNodeFilter f = new AttributeNodeFilter(REGION_ATTR_NAME, regionId); List<ClusterNode> regionNodes = new ArrayList<>(); for (ClusterNode node : nodes) if (f.apply(node)) regionNodes.add(node); final int cp = p; Collections.sort(regionNodes, new Comparator<ClusterNode>() { @Override public int compare(ClusterNode o1, ClusterNode o2) { return Long.compare(hash(cp, o1), hash(cp, o2)); } }); assignment.add(regionNodes); } return assignment; }
/** {@inheritDoc} */ @Override public List<List<ClusterNode>> assignPartitions(AffinityFunctionContext affCtx) { ClusterNode locNode = null; for (ClusterNode n : affCtx.currentTopologySnapshot()) { if (n.isLocal()) { locNode = n; break; } } if (locNode == null) throw new IgniteException("Local node is not included into affinity nodes for 'LOCAL' cache"); List<List<ClusterNode>> res = new ArrayList<>(partitions()); for (int part = 0; part < partitions(); part++) res.add(Collections.singletonList(locNode)); return Collections.unmodifiableList(res); }