You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "sk0x50 (via GitHub)" <gi...@apache.org> on 2025/01/30 16:29:26 UTC

[PR] IGNITE-23365 Improve assignments tracker logging [ignite-3]

sk0x50 opened a new pull request, #5153:
URL: https://github.com/apache/ignite-3/pull/5153

   https://issues.apache.org/jira/browse/IGNITE-23365
   
   Thank you for submitting the pull request.
   
   To streamline the review process of the patch and ensure better code quality
   we ask both an author and a reviewer to verify the following:
   
   ### The Review Checklist
   - [ ] **Formal criteria:** TC status, codestyle, mandatory documentation. Also make sure to complete the following:  
   \- There is a single JIRA ticket related to the pull request.  
   \- The web-link to the pull request is attached to the JIRA ticket.  
   \- The JIRA ticket has the Patch Available state.  
   \- The description of the JIRA ticket explains WHAT was made, WHY and HOW.  
   \- The pull request title is treated as the final commit message. The following pattern must be used: IGNITE-XXXX Change summary where XXXX - number of JIRA issue.
   - [ ] **Design:** new code conforms with the design principles of the components it is added to.
   - [ ] **Patch quality:** patch cannot be split into smaller pieces, its size must be reasonable.
   - [ ] **Code quality:** code is clean and readable, necessary developer documentation is added if needed.
   - [ ] **Tests code quality:** test set covers positive/negative scenarios, happy/edge cases. Tests are effective in terms of execution time and resources.
   
   ### Notes
   - [Apache Ignite Coding Guidelines](https://cwiki.apache.org/confluence/display/IGNITE/Java+Code+Style+Guide)


-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-23365 Improve assignments tracker logging [ignite-3]

Posted by "sk0x50 (via GitHub)" <gi...@apache.org>.
sk0x50 merged PR #5153:
URL: https://github.com/apache/ignite-3/pull/5153


-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-23365 Improve assignments tracker logging [ignite-3]

Posted by "JAkutenshi (via GitHub)" <gi...@apache.org>.
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-23365 Improve assignments tracker logging [ignite-3]

Posted by "sk0x50 (via GitHub)" <gi...@apache.org>.
sk0x50 commented on code in PR #5153:
URL: https://github.com/apache/ignite-3/pull/5153#discussion_r1939239488


##########
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:
   I updated the ticket's description in accordance with the proposed code:
   ```
   Assignment cache initialized for placement driver 
       [stableAssignments=[node1=[peers=[1_part_0]], learners=[2_part_0]], pendingAssignments=[node=[peers=[1_part_0]]]]
   ```
   
   IMHO, it would be better to use only one style to log messages. The Apache Ignite 2 and the vast of majority cases the Apache Ignite 3 use a JSON-like approach. Also, it allows getting a structure view using common tools https://jsonformatter.curiousconcept.com:
   ```
   "Assignment cache initialized for placement driver"[
      "stableAssignments="[
         node1=[
            "peers="[
               1_part_0
            ]
         ],
         "learners="[
            2_part_0
         ]
      ],
      "pendingAssignments="[
         "node="[
            "peers="[
               1_part_0
            ]
         ]
      ]
   ]
   ```



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-23365 Improve assignments tracker logging [ignite-3]

Posted by "sk0x50 (via GitHub)" <gi...@apache.org>.
sk0x50 commented on code in PR #5153:
URL: https://github.com/apache/ignite-3/pull/5153#discussion_r1939244239


##########
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:
   Yep, it was my explicit intention not to allocate objects until we know that the collection is not empty, to avoid any GC pressure. IMHO, this does not in any way impair the readability of the code. 



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org