You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@helix.apache.org by GitBox <gi...@apache.org> on 2020/08/12 17:17:27 UTC

[GitHub] [helix] NealSun96 commented on a change in pull request #1256: Do not ignore any map or list field key change in the Change Detector.

NealSun96 commented on a change in pull request #1256:
URL: https://github.com/apache/helix/pull/1256#discussion_r469416552



##########
File path: helix-core/src/main/java/org/apache/helix/controller/changedetector/trimmer/HelixPropertyTrimmer.java
##########
@@ -57,38 +57,49 @@
    * @param originalProperty
    */
   protected ZNRecord doTrim(T originalProperty) {
+    ZNRecord originalZNRecord = originalProperty.getRecord();
     ZNRecord trimmedZNRecord = new ZNRecord(originalProperty.getId());
-    for (Map.Entry<FieldType, Set<String>> fieldEntry : getNonTrimmableFields(
-        originalProperty).entrySet()) {
+    Map<FieldType, Set<String>> nonTrimmableFields = getNonTrimmableFields(originalProperty);
+
+    // Ensure the keys of all map fields and list fields are preserved even after the trim.
+    // The keys of list and map fields are relatively stable and contain important information. So
+    // they should not be trimmed.
+    originalZNRecord.getMapFields().keySet().stream()
+        .forEach(key -> trimmedZNRecord.setMapField(key, Collections.EMPTY_MAP));
+    originalZNRecord.getListFields().keySet().stream()
+        .forEach(key -> trimmedZNRecord.setListField(key, Collections.EMPTY_LIST));

Review comment:
       This part of code may come as a surprise to future developers that extend this class. When `getNonTrimmableFields()` is provided for overriding, it's natural to think `getNonTrimmableFields()` provides full control on "what fields to keep". This logic here, while necessary, may become debug overhead. It's also hard to change this behavior in the future if it stays in `doTrim()` like so. 
   
   I suggest creating another function such as `getNonTrimmableKeysOnly()` and implement it under `HelixPropertyTrimmer.java` to preserve MapField and ListField keys by default; in `doTrim()`, we call that function and preserve keys only. The extended classes may choose to override it (and for now, they shouldn't). This is a clearer approach to creating this abstract class. 




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

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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org