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:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]