AMashenkov commented on code in PR #1501:
URL: https://github.com/apache/ignite-3/pull/1501#discussion_r1094456566
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/metadata/ColocationGroup.java:
##########
@@ -194,30 +194,101 @@ public ColocationGroup colocate(ColocationGroup other)
throws ColocationMappingE
return new ColocationGroup(sourceIds, nodeNames, assignments);
}
+ private List<NodeWithTerm> intersect(List<NodeWithTerm> assignment0,
List<NodeWithTerm> assignment1, Predicate<String> filter, int p)
+ throws ColocationMappingException {
+ if (assignment0.size() == 1 && assignment1.size() == 1) {
+ NodeWithTerm first = assignment0.get(0);
+ NodeWithTerm second = assignment1.get(0);
+
+ if (filter.test(first.name()) &&
first.name().equals(second.name())) {
+ validateTerm(first, second, p);
+
+ return assignment0;
+ }
+
+ return Collections.emptyList();
+ } else {
+ if (assignment0.size() > assignment1.size()) {
+ List<NodeWithTerm> tmp = assignment0;
+ assignment0 = assignment1;
+ assignment1 = tmp;
+ }
+
+ List<NodeWithTerm> assignment = new ArrayList<>();
+
+ Map<String, NodeWithTerm> hashedByNameAssignment =
+
assignment1.stream().collect(Collectors.toMap(NodeWithTerm::name, nodeWithTerm
-> nodeWithTerm));
+
+ for (NodeWithTerm first : assignment0) {
+ if (!filter.test(first.name())) {
+ continue;
+ }
+
+ NodeWithTerm second = hashedByNameAssignment.get(first.name());
+
+ if (second == null) {
+ continue;
+ }
+
+ validateTerm(first, second, p);
+
+ assignment.add(first);
+ }
+
+ return assignment;
+ }
+ }
+
+ private void validateTerm(NodeWithTerm first, NodeWithTerm second, int
partId) throws ColocationMappingException {
+ if (first.term() != second.term()) {
+ throw new ColocationMappingException("Primary replica term has
been changed during mapping ["
+ + "node=" + first.name()
+ + ", expectedTerm=" + first.term()
+ + ", actualTerm=" + second.term()
+ + ", part=" + partId
+ + ']');
+ }
+ }
+
+ private List<NodeWithTerm> filterByNodeNames(List<NodeWithTerm>
assignment, Set<String> filter) {
+ if (nullOrEmpty(assignment) || nullOrEmpty(filter)) {
+ return Collections.emptyList();
+ }
+
+ List<NodeWithTerm> res = new ArrayList<>();
Review Comment:
```suggestion
List<NodeWithTerm> res = new ArrayList<>(assignment.size());
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]