[ 
https://issues.apache.org/jira/browse/HADOOP-18748?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17728323#comment-17728323
 ] 

ASF GitHub Bot commented on HADOOP-18748:
-----------------------------------------

steveloughran commented on code in PR #5685:
URL: https://github.com/apache/hadoop/pull/5685#discussion_r1213046499


##########
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java:
##########
@@ -724,54 +724,41 @@ private String[] handleDeprecation(DeprecationContext 
deprecations,
     if (null != name) {
       name = name.trim();
     }
-    // Initialize the return value with requested name
-    String[] names = new String[]{name};
-    // Deprecated keys are logged once and an updated names are returned
-    DeprecatedKeyInfo keyInfo = deprecations.getDeprecatedKeyMap().get(name);
-    if (keyInfo != null) {
+
+    final DeprecatedKeyInfo keyInfo = 
deprecations.getDeprecatedKeyMap().get(name);
+    final String[] names;
+    if (keyInfo == null) {
+      names = new String[]{name};
+      // Handling deprecations is rare so bail out early for the common case.
+      if (deprecations.getReverseDeprecatedKeyMap().get(name) == null) {
+        return names;
+      }
+    } else {
+      names = keyInfo.newKeys;
       if (!keyInfo.getAndSetAccessed()) {
         logDeprecation(keyInfo.getWarningMessage(name));
       }
-      // Override return value for deprecated keys
-      names = keyInfo.newKeys;
     }
 
-    // Update properties with deprecated key if already loaded and new
-    // deprecation has been added
-    updatePropertiesWithDeprecatedKeys(deprecations, names);
-
-    // If there are no overlay values we can return early
-    Properties overlayProperties = getOverlay();
-    if (overlayProperties.isEmpty()) {
-      return names;
-    }
-    // Update properties and overlays with reverse lookup values
-    for (String n : names) {
-      String deprecatedKey = deprecations.getReverseDeprecatedKeyMap().get(n);
-      if (deprecatedKey != null && !overlayProperties.containsKey(n)) {
-        String deprecatedValue = overlayProperties.getProperty(deprecatedKey);
-        if (deprecatedValue != null) {
-          getProps().setProperty(n, deprecatedValue);
-          overlayProperties.setProperty(n, deprecatedValue);
-        }
-      }
+    propagateProps(names, deprecations.getReverseDeprecatedKeyMap(), 
getProps());
+    Properties overlay = getOverlay();
+    if (!overlay.isEmpty()) {
+      propagateProps(names, deprecations.getReverseDeprecatedKeyMap(), 
overlay);
     }
+
     return names;
   }
 
-  private void updatePropertiesWithDeprecatedKeys(
-      DeprecationContext deprecations, String[] newNames) {
-    for (String newName : newNames) {
-      String deprecatedKey = 
deprecations.getReverseDeprecatedKeyMap().get(newName);
-      if (deprecatedKey != null && !getProps().containsKey(newName)) {
-        String deprecatedValue = getProps().getProperty(deprecatedKey);
-        if (deprecatedValue != null) {
-          getProps().setProperty(newName, deprecatedValue);
-        }
-      }
+  private static void propagateProps(String[] keys, Map<String, String> map, 
Properties props) {

Review Comment:
   needs javadocs and a name like "propagateDeprecatedProperties" would be more 
informative



##########
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java:
##########
@@ -724,54 +724,41 @@ private String[] handleDeprecation(DeprecationContext 
deprecations,
     if (null != name) {
       name = name.trim();
     }
-    // Initialize the return value with requested name
-    String[] names = new String[]{name};
-    // Deprecated keys are logged once and an updated names are returned
-    DeprecatedKeyInfo keyInfo = deprecations.getDeprecatedKeyMap().get(name);
-    if (keyInfo != null) {
+
+    final DeprecatedKeyInfo keyInfo = 
deprecations.getDeprecatedKeyMap().get(name);
+    final String[] names;
+    if (keyInfo == null) {
+      names = new String[]{name};
+      // Handling deprecations is rare so bail out early for the common case.
+      if (deprecations.getReverseDeprecatedKeyMap().get(name) == null) {
+        return names;
+      }
+    } else {
+      names = keyInfo.newKeys;
       if (!keyInfo.getAndSetAccessed()) {
         logDeprecation(keyInfo.getWarningMessage(name));
       }
-      // Override return value for deprecated keys
-      names = keyInfo.newKeys;
     }
 
-    // Update properties with deprecated key if already loaded and new
-    // deprecation has been added
-    updatePropertiesWithDeprecatedKeys(deprecations, names);
-
-    // If there are no overlay values we can return early
-    Properties overlayProperties = getOverlay();
-    if (overlayProperties.isEmpty()) {
-      return names;
-    }
-    // Update properties and overlays with reverse lookup values
-    for (String n : names) {
-      String deprecatedKey = deprecations.getReverseDeprecatedKeyMap().get(n);
-      if (deprecatedKey != null && !overlayProperties.containsKey(n)) {
-        String deprecatedValue = overlayProperties.getProperty(deprecatedKey);
-        if (deprecatedValue != null) {
-          getProps().setProperty(n, deprecatedValue);
-          overlayProperties.setProperty(n, deprecatedValue);
-        }
-      }
+    propagateProps(names, deprecations.getReverseDeprecatedKeyMap(), 
getProps());
+    Properties overlay = getOverlay();
+    if (!overlay.isEmpty()) {
+      propagateProps(names, deprecations.getReverseDeprecatedKeyMap(), 
overlay);
     }
+
     return names;
   }
 
-  private void updatePropertiesWithDeprecatedKeys(
-      DeprecationContext deprecations, String[] newNames) {
-    for (String newName : newNames) {
-      String deprecatedKey = 
deprecations.getReverseDeprecatedKeyMap().get(newName);
-      if (deprecatedKey != null && !getProps().containsKey(newName)) {
-        String deprecatedValue = getProps().getProperty(deprecatedKey);
-        if (deprecatedValue != null) {
-          getProps().setProperty(newName, deprecatedValue);
-        }
-      }
+  private static void propagateProps(String[] keys, Map<String, String> map, 
Properties props) {
+    for (String k : keys) {
+      String mk = map.get(k);
+      if (mk == null) continue;

Review Comment:
   add braces





> Configuration.get is slow
> -------------------------
>
>                 Key: HADOOP-18748
>                 URL: https://issues.apache.org/jira/browse/HADOOP-18748
>             Project: Hadoop Common
>          Issue Type: Improvement
>          Components: conf
>    Affects Versions: 3.3.5
>            Reporter: Alkis Evlogimenos
>            Priority: Major
>              Labels: pull-request-available
>
> `Configuration.get` is slow mainly because of the overhead of 
> `handleDeprecation` and eager creation of `overlay` even when null.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to