liuml07 commented on a change in pull request #2327:
URL: https://github.com/apache/hadoop/pull/2327#discussion_r495375367



##########
File path: 
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/CallerContext.java
##########
@@ -108,24 +117,86 @@ public String toString() {
   }
 
   /** The caller context builder. */
-  public static final class Builder {
-    private final String context;
+  public static final class Builder implements Configurable {

Review comment:
       I am not sure we need to implement the `Configurable` to make this 
flexible. How about:
   1. Add a new final `separator` field
   1. Add a new final `StringBuilder sb = new StringBuilder();` field and 
remove `context` variable
   1. Existing constructor `public Builder(String context)` will simply 
call`sb.append(context)` and assign `separator` field with default value `,` 
aka `HADOOP_CALLER_CONTEXT_ITEM_SEPARATOR_DEFAULT`
   1. Create a new constructor `public Builder(Configuration conf)` which 
initializes the `separator` with the config, do not save the `conf` since we do 
not need it
   1. Add a new method `public append(String key, String value)` which calls 
`sb.append(key).append(separator).append(value)`
   1. Replace all places using `builder.context` with `builder.sb.toString()`, 
especially in `CallerContext(Builder b)` constructor.
   
   This seems very straightforward without losing configurability:
   1. it will not allow user to mix different separator when appending multiple 
key/values since it's final either from the default `,` or from Configuration
   1. no need to create a new string builder every time calling `append(key, 
value)`
   1. user does not need to call `builder.setConf(conf)`
   1. we do not  save `conf` by implementing `Configurable` interface so this 
builder lightweight
   
   Thoughts?
   




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

Reply via email to