liuml07 commented on a change in pull request #2223:
URL: https://github.com/apache/hadoop/pull/2223#discussion_r487367770
##########
File path:
hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/Job.java
##########
@@ -1450,26 +1450,33 @@ public static void
setArchiveSharedCacheUploadPolicies(Configuration conf,
*/
private static void setSharedCacheUploadPolicies(Configuration conf,
Map<String, Boolean> policies, boolean areFiles) {
- if (policies != null) {
- StringBuilder sb = new StringBuilder();
- Iterator<Map.Entry<String, Boolean>> it = policies.entrySet().iterator();
- Map.Entry<String, Boolean> e;
- if (it.hasNext()) {
- e = it.next();
- sb.append(e.getKey() + DELIM + e.getValue());
- } else {
- // policies is an empty map, just skip setting the parameter
- return;
- }
- while (it.hasNext()) {
- e = it.next();
- sb.append("," + e.getKey() + DELIM + e.getValue());
- }
- String confParam =
- areFiles ? MRJobConfig.CACHE_FILES_SHARED_CACHE_UPLOAD_POLICIES
- : MRJobConfig.CACHE_ARCHIVES_SHARED_CACHE_UPLOAD_POLICIES;
- conf.set(confParam, sb.toString());
+ String confParam = areFiles ?
+ MRJobConfig.CACHE_FILES_SHARED_CACHE_UPLOAD_POLICIES :
+ MRJobConfig.CACHE_ARCHIVES_SHARED_CACHE_UPLOAD_POLICIES;
+ conf.set(confParam, populateSharedCacheUploadPolicies(policies));
+ }
+
+ private static String populateSharedCacheUploadPolicies(
+ Map<String, Boolean> policies) {
+ // If policies are an empty map or null, we will set EMPTY_STRING.
+ // In other words, cleaning up existing policies. This is useful when we
+ // try to clean up shared cache upload policies for non-application
+ // master tasks. See YARN-10398 for details.
+ if (policies == null || policies.size() == 0) {
+ return "";
+ }
+ StringBuilder sb = new StringBuilder();
Review comment:
I know following code was mostly borrowed from the existing code, but
since we are in Java 8 for Hadoop 3, should we simplify this a bit using this
chance?
```
Iterator<Map.Entry<String, Boolean>> it = policies.entrySet().iterator();
Map.Entry<String, Boolean> e;
if (it.hasNext()) {
e = it.next();
sb.append(e.getKey() + DELIM + e.getValue());
}
while (it.hasNext()) {
e = it.next();
sb.append("," + e.getKey() + DELIM + e.getValue());
}
```
can be shorter and clearer statement, for e.g.
```
policies.forEach((k,v) ->
sb.append(k).append(DELIM).append(v).append(","));
sb.deleteCharAt(sb.length() - 1);
```
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]