JAkutenshi commented on code in PR #5153:
URL: https://github.com/apache/ignite-3/pull/5153#discussion_r1939222721


##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/AssignmentsTracker.java:
##########
@@ -241,4 +241,87 @@ private static String 
collectKeysFromEventAsString(WatchEvent event) {
                 .collect(Collectors.joining(","));
     }
 
+    /**
+     * Prepares assignments for logging using the following structure:
+     * consistentId=[peers=[1_part_1, 1_part_2], learners=[2_part_0]].
+     *
+     * @param assignmentsMap assignments to be logged.
+     * @return String representation of assignments.
+     */
+    private static String prepareAssignmentsForLogging(Map<ReplicationGroupId, 
TokenizedAssignments> assignmentsMap) {
+        class NodeAssignments {
+            private List<ReplicationGroupId> peers;
+            private List<ReplicationGroupId> learners;
+
+            private NodeAssignments() {
+            }
+
+            private void addReplicationGroupId(ReplicationGroupId 
replicationGroupId, boolean isPeer) {
+                List<ReplicationGroupId> peersOrLearners;
+
+                if (isPeer) {
+                    if (peers == null) {
+                        peers = new ArrayList<>();
+                    }
+                    peersOrLearners = peers;
+                } else {
+                    if (learners == null) {
+                        learners = new ArrayList<>();
+                    }
+                    peersOrLearners = learners;
+                }
+
+                peersOrLearners.add(replicationGroupId);
+            }
+
+            private boolean arePeersEmpty() {
+                return peers == null || peers.isEmpty();
+            }
+
+            private boolean areLearnersEmpty() {
+                return learners == null || learners.isEmpty();
+            }
+        }
+
+        Map<String, NodeAssignments> assignmentsToLog = new HashMap<>();
+
+        for (Map.Entry<ReplicationGroupId, TokenizedAssignments> assignments : 
assignmentsMap.entrySet()) {
+            for (Assignment assignment : assignments.getValue().nodes()) {
+                assignmentsToLog
+                        .computeIfAbsent(assignment.consistentId(), k -> new 
NodeAssignments())
+                        .addReplicationGroupId(assignments.getKey(), 
assignment.isPeer());
+            }
+        }
+
+        boolean first = true;
+        StringBuilder sb = new StringBuilder();
+
+        for (Map.Entry<String, NodeAssignments> entry : 
assignmentsToLog.entrySet()) {
+            NodeAssignments value = entry.getValue();
+
+            if (value.arePeersEmpty() && value.areLearnersEmpty()) {
+                continue;
+            }
+
+            if (first) {
+                first = false;
+            } else {
+                sb.append(", ");
+            }
+
+            sb.append(entry.getKey()).append("=[");

Review Comment:
   The string that will be produced from there doesn't match with JIRA's one. 
Is it ok?



##########
modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/AssignmentsTracker.java:
##########
@@ -241,4 +241,87 @@ private static String 
collectKeysFromEventAsString(WatchEvent event) {
                 .collect(Collectors.joining(","));
     }
 
+    /**
+     * Prepares assignments for logging using the following structure:
+     * consistentId=[peers=[1_part_1, 1_part_2], learners=[2_part_0]].
+     *
+     * @param assignmentsMap assignments to be logged.
+     * @return String representation of assignments.
+     */
+    private static String prepareAssignmentsForLogging(Map<ReplicationGroupId, 
TokenizedAssignments> assignmentsMap) {
+        class NodeAssignments {
+            private List<ReplicationGroupId> peers;
+            private List<ReplicationGroupId> learners;
+
+            private NodeAssignments() {
+            }
+
+            private void addReplicationGroupId(ReplicationGroupId 
replicationGroupId, boolean isPeer) {
+                List<ReplicationGroupId> peersOrLearners;
+
+                if (isPeer) {
+                    if (peers == null) {

Review Comment:
   We may initialize the fields with empty lists (I bet Linked lists are fine 
there in terms of memory) and emptiness check right through `list.isEmpty()` 
only below.



-- 
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]

Reply via email to