Repository: ignite Updated Branches: refs/heads/ignite-4154-2 d5d58f0af -> c2f4276e1
ignite-4154 zip Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/c2f4276e Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/c2f4276e Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/c2f4276e Branch: refs/heads/ignite-4154-2 Commit: c2f4276e1d5034329fcf4262da32638e77e4e7e3 Parents: d5d58f0 Author: sboikov <[email protected]> Authored: Wed Nov 2 16:08:26 2016 +0300 Committer: sboikov <[email protected]> Committed: Wed Nov 2 16:08:26 2016 +0300 ---------------------------------------------------------------------- .../affinity/GridAffinityAssignment.java | 110 +++++++++++-------- 1 file changed, 65 insertions(+), 45 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/c2f4276e/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignment.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignment.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignment.java index 2940d92..18c7ec2 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignment.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignment.java @@ -141,76 +141,96 @@ public class GridAffinityAssignment implements AffinityAssignment, Serializable return topVer; } - /** {@inheritDoc} */ - @Override public List<ClusterNode> get(int part) { + /** + * Get affinity nodes for partition. + * + * @param part Partition. + * @return Affinity nodes. + */ + public List<ClusterNode> get(int part) { assert part >= 0 && part < assignment.size() : "Affinity partition is out of range" + - " [part=" + part + ", partitions=" + assignment.size() + ']'; + " [part=" + part + ", partitions=" + assignment.size() + ']'; return assignment.get(part); } - /** {@inheritDoc} */ - @Override public HashSet<UUID> getIds(int part) { + /** + * Get affinity node IDs for partition. + * + * @param part Partition. + * @return Affinity nodes IDs. + */ + public HashSet<UUID> getIds(int part) { assert part >= 0 && part < assignment.size() : "Affinity partition is out of range" + - " [part=" + part + ", partitions=" + assignment.size() + ']'; + " [part=" + part + ", partitions=" + assignment.size() + ']'; - List<ClusterNode> nodes = assignment.get(part); + List<HashSet<UUID>> assignmentIds0 = assignmentIds; - HashSet<UUID> ids = U.newHashSet(nodes.size()); + if (assignmentIds0 == null) { + assignmentIds0 = new ArrayList<>(); - for (int i = 0; i < nodes.size(); i++) - ids.add(nodes.get(i).id()); + for (List<ClusterNode> assignmentPart : assignment) { + HashSet<UUID> partIds = new HashSet<>(); - return ids; - } - - /** {@inheritDoc} */ - @Override public Set<ClusterNode> primaryPartitionNodes() { - Set<ClusterNode> res = new HashSet<>(); + for (ClusterNode node : assignmentPart) + partIds.add(node.id()); - for (int p = 0; p < assignment.size(); p++) { - List<ClusterNode> nodes = assignment.get(p); + assignmentIds0.add(partIds); + } - if (!F.isEmpty(nodes)) - res.add(nodes.get(0)); + assignmentIds = assignmentIds0; } - return res; + return assignmentIds0.get(part); } - /** {@inheritDoc} */ - @Override public Set<Integer> primaryPartitions(UUID nodeId) { - Set<Integer> res = new HashSet<>(); + /** + * @return Nodes having primary partitions assignments. + */ + @SuppressWarnings("ForLoopReplaceableByForEach") + public Set<ClusterNode> primaryPartitionNodes() { + Set<ClusterNode> primaryPartsNodes0 = primaryPartsNodes; - for (int p = 0; p < assignment.size(); p++) { - List<ClusterNode> nodes = assignment.get(p); + if (primaryPartsNodes0 == null) { + int parts = assignment.size(); - if (!F.isEmpty(nodes) && nodes.get(0).id().equals(nodeId)) - res.add(p); - } + primaryPartsNodes0 = new HashSet<>(); - return res; - } + for (int p = 0; p < parts; p++) { + List<ClusterNode> nodes = assignment.get(p); - /** {@inheritDoc} */ - @Override public Set<Integer> backupPartitions(UUID nodeId) { - Set<Integer> res = new HashSet<>(); + if (nodes.size() > 0) + primaryPartsNodes0.add(nodes.get(0)); + } + + primaryPartsNodes = primaryPartsNodes0; + } - for (int p = 0; p < assignment.size(); p++) { - List<ClusterNode> nodes = assignment.get(p); + return primaryPartsNodes0; + } - for (int i = 1; i < nodes.size(); i++) { - ClusterNode node = nodes.get(i); + /** + * Get primary partitions for specified node ID. + * + * @param nodeId Node ID to get primary partitions for. + * @return Primary partitions for specified node ID. + */ + public Set<Integer> primaryPartitions(UUID nodeId) { + Set<Integer> set = primary.get(nodeId); - if (node.id().equals(nodeId)) { - res.add(p); + return set == null ? Collections.<Integer>emptySet() : set; + } - break; - } - } - } + /** + * Get backup partitions for specified node ID. + * + * @param nodeId Node ID to get backup partitions for. + * @return Backup partitions for specified node ID. + */ + public Set<Integer> backupPartitions(UUID nodeId) { + Set<Integer> set = backup.get(nodeId); - return res; + return set == null ? Collections.<Integer>emptySet() : set; } /**
