You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/06/20 07:23:31 UTC

[GitHub] [pulsar] fantapsody opened a new pull request, #16138: [improve][broker] Use LinkedHashSet for config items of type Set to preserve elements order

fantapsody opened a new pull request, #16138:
URL: https://github.com/apache/pulsar/pull/16138

   
   
   <!--
   ### Contribution Checklist
     
     - PR title format should be *[type][component] summary*. For details, see *[Guideline - Pulsar PR Naming Convention](https://docs.google.com/document/d/1d8Pw6ZbWk-_pCKdOmdvx9rnhPiyuxwq60_TrD68d7BA/edit#heading=h.trs9rsex3xom)*. 
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
     
     - Each pull request should address only one issue, not mix up code from multiple issues.
     
     - Each commit in the pull request has a meaningful commit message
   
     - Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
   
   **(The sections below can be removed for hotfixes of typos)**
   -->
   
   Fixes https://github.com/apache/pulsar/issues/16137
   
   ### Motivation
   
   The order of items is not preserved for configuration fields of the type `Set`. Preserving the order of items in the config would make the program behavior to be more predictable, and may potentially make it possible for more operation flexibilities.
   
   ### Modifications
   
   Create a `LinkedHashSet` rather than a `HashSet` when converting string to Set.
   
   ### Verifying this change
   
   - [ ] Make sure that the change passes the CI checks.
   
   This change is already covered by existing tests, such as `FieldParserTest.testConversion`.
   
   
   ### Does this pull request potentially affect one of the following parts:
   
   *If `yes` was chosen, please highlight the changes*
   
     - Dependencies (does it add or upgrade a dependency): (yes / no)
     - The public API: (yes / no)
     - The schema: (yes / no / don't know)
     - The default values of configurations: (yes / no)
     - The wire protocol: (yes / no)
     - The rest endpoints: (yes / no)
     - The admin cli options: (yes / no)
     - Anything that affects deployment: (yes / no / don't know)
   
   ### Documentation
   
   Check the box below or label this PR directly.
   
   Need to update docs? 
   
   - [ ] `doc-required` 
   (Your PR needs to update docs and you will update later)
     
   - [ ] `doc-not-needed` 
   (Please explain why)
     
   - [ ] `doc` 
   (Your PR contains doc changes)
   
   - [ ] `doc-complete`
   (Docs have been already added)


-- 
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: commits-unsubscribe@pulsar.apache.org

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


[GitHub] [pulsar] fantapsody commented on a diff in pull request #16138: [improve][broker] Use LinkedHashSet for config items of type Set to preserve elements order

Posted by GitBox <gi...@apache.org>.
fantapsody commented on code in PR #16138:
URL: https://github.com/apache/pulsar/pull/16138#discussion_r901415236


##########
pulsar-common/src/main/java/org/apache/pulsar/common/util/FieldParser.java:
##########
@@ -212,7 +212,7 @@ public static <T> void setEmptyValue(String strValue, Field field, T obj)
             if (field.getType().equals(List.class)) {
                 field.set(obj, new ArrayList<>());
             } else if (field.getType().equals(Set.class)) {
-                field.set(obj, new HashSet<>());
+                field.set(obj, new LinkedHashSet<>());

Review Comment:
   It's true for new configuration fields. However, using `Set` ensures the uniqueness of the elements in the collection, so it's non-trivial to convert the type of these fields from `Set` to `List`, and there are quite a few existing configuration fields of the type `Set`. On the other hand, changing `HashSet` to `LinkedHashSet` makes all existing fields ordered and it seems harmless except for a bit increase in the per-element memory consumption which should be acceptable for configuration items.



-- 
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: commits-unsubscribe@pulsar.apache.org

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


[GitHub] [pulsar] github-actions[bot] commented on pull request #16138: [improve][broker] Use LinkedHashSet for config items of type Set to preserve elements order

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #16138:
URL: https://github.com/apache/pulsar/pull/16138#issuecomment-1161048884

   @fantapsody Please provide a correct documentation label for your PR.
   Instructions see [Pulsar Documentation Label Guide](https://docs.google.com/document/d/1Qw7LHQdXWBW9t2-r-A7QdFDBwmZh6ytB4guwMoXHqc0).


-- 
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: commits-unsubscribe@pulsar.apache.org

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


[GitHub] [pulsar] github-actions[bot] commented on pull request #16138: [improve][broker] Use LinkedHashSet for config items of type Set to preserve elements order

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #16138:
URL: https://github.com/apache/pulsar/pull/16138#issuecomment-1160084888

   @fantapsody Please provide a correct documentation label for your PR.
   Instructions see [Pulsar Documentation Label Guide](https://docs.google.com/document/d/1Qw7LHQdXWBW9t2-r-A7QdFDBwmZh6ytB4guwMoXHqc0).


-- 
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: commits-unsubscribe@pulsar.apache.org

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


[GitHub] [pulsar] HQebupt commented on a diff in pull request #16138: [improve][broker] Use LinkedHashSet for config items of type Set to preserve elements order

Posted by GitBox <gi...@apache.org>.
HQebupt commented on code in PR #16138:
URL: https://github.com/apache/pulsar/pull/16138#discussion_r901391420


##########
pulsar-common/src/main/java/org/apache/pulsar/common/util/FieldParser.java:
##########
@@ -212,7 +212,7 @@ public static <T> void setEmptyValue(String strValue, Field field, T obj)
             if (field.getType().equals(List.class)) {
                 field.set(obj, new ArrayList<>());
             } else if (field.getType().equals(Set.class)) {
-                field.set(obj, new HashSet<>());
+                field.set(obj, new LinkedHashSet<>());

Review Comment:
   If order is required, it is recommended to use `List` instead of `Set`.



-- 
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: commits-unsubscribe@pulsar.apache.org

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


[GitHub] [pulsar] codelipenghui merged pull request #16138: [improve][broker] Use LinkedHashSet for config items of type Set to preserve elements order

Posted by GitBox <gi...@apache.org>.
codelipenghui merged PR #16138:
URL: https://github.com/apache/pulsar/pull/16138


-- 
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: commits-unsubscribe@pulsar.apache.org

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


[GitHub] [pulsar] codelipenghui commented on pull request #16138: [improve][broker] Use LinkedHashSet for config items of type Set to preserve elements order

Posted by GitBox <gi...@apache.org>.
codelipenghui commented on PR #16138:
URL: https://github.com/apache/pulsar/pull/16138#issuecomment-1161050118

   @tuteng I have removed the cherry-picked/ label, the cherry-picked label should be added after we complete the cherry-picking. Otherwise, we might miss the cherry-pick after the PR get merged.


-- 
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: commits-unsubscribe@pulsar.apache.org

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