ygerzhedovich commented on code in PR #1501:
URL: https://github.com/apache/ignite-3/pull/1501#discussion_r1087879804
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/metadata/ColocationGroup.java:
##########
@@ -194,30 +186,73 @@ public ColocationGroup colocate(ColocationGroup other)
throws ColocationMappingE
return new ColocationGroup(sourceIds, nodeNames, assignments);
}
+ private List<NodeWithTerm> intersect(List<NodeWithTerm> assign0,
List<NodeWithTerm> assign1, @Nullable Set<String> filter, int partId)
+ throws ColocationMappingException {
+ List<NodeWithTerm> intersection = new ArrayList<>();
+
+ for (NodeWithTerm nodeWithTerm : assign0) {
+ if (filter != null && !filter.contains(nodeWithTerm.name())) {
+ continue;
+ }
+
+ for (NodeWithTerm otherNodeWithTerm : assign1) {
+ if (!otherNodeWithTerm.name().equals(nodeWithTerm.name())) {
+ continue;
+ }
+
+ if (nodeWithTerm.term() != otherNodeWithTerm.term()) {
+ throw new ColocationMappingException("Raft group primary
replica term has been changed during mapping ["
+ + "part=" + partId
+ + ", leader=" + nodeWithTerm.name()
+ + ", expectedTerm=" + nodeWithTerm.term()
+ + ", actualTerm=" + otherNodeWithTerm.term() +
']');
+ }
+
+ intersection.add(otherNodeWithTerm);
+ }
+ }
+
+ return intersection;
+ }
+
+ private List<NodeWithTerm> filter(List<NodeWithTerm> assignment,
Set<String> filter) {
+ List<NodeWithTerm> res = new ArrayList<>();
+
+ if (nullOrEmpty(assignment) || nullOrEmpty(filter)) {
+ return Collections.emptyList();
+ }
+
+ for (NodeWithTerm nodeWithTerm : assignment) {
+ if (!filter.contains(nodeWithTerm.name())) {
+ continue;
+ }
+
+ res.add(nodeWithTerm);
+ }
+
+ return res;
+ }
+
/**
* Constructor.
* TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
*/
public ColocationGroup finalaze() {
- if (assignments == null && nodeNames == null) {
- return this;
- }
-
if (assignments != null) {
- List<List<String>> assignments = new
ArrayList<>(this.assignments.size());
+ List<List<NodeWithTerm>> assignments = new
ArrayList<>(this.assignments.size());
Set<String> nodes = new HashSet<>();
- for (List<String> assignment : this.assignments) {
- String first = first(assignment);
+ for (List<NodeWithTerm> assignment : this.assignments) {
+ NodeWithTerm first = first(assignment);
if (first != null) {
- nodes.add(first);
+ nodes.add(first.name());
}
assignments.add(first != null ?
Collections.singletonList(first) : Collections.emptyList());
}
return new ColocationGroup(sourceIds, new ArrayList<>(nodes),
assignments);
}
- return forNodes0(nodeNames);
+ return nodeNames == null ? this : forNodes0(nodeNames);
Review Comment:
```suggestion
return mapToNodes(nodeNames);
```
--
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]