hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jeag...@apache.org
Subject hadoop git commit: Configuration#get return value optimization (jeagles)
Date Mon, 27 Mar 2017 17:53:08 GMT
Repository: hadoop
Updated Branches:
  refs/heads/branch-2 675bc97f1 -> e41aac0cd


Configuration#get return value optimization (jeagles)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/e41aac0c
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/e41aac0c
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/e41aac0c

Branch: refs/heads/branch-2
Commit: e41aac0cd41c6a4ee740afd09126bc48072880ab
Parents: 675bc97
Author: Jonathan Eagles <jeagles@yahoo-inc.com>
Authored: Mon Mar 27 12:52:59 2017 -0500
Committer: Jonathan Eagles <jeagles@yahoo-inc.com>
Committed: Mon Mar 27 12:52:59 2017 -0500

----------------------------------------------------------------------
 .../org/apache/hadoop/conf/Configuration.java   | 54 +++++++++++---------
 1 file changed, 29 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/e41aac0c/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java
index a2d0f44..87b608b 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java
@@ -611,37 +611,44 @@ public class Configuration implements Iterable<Map.Entry<String,String>>,
    * deprecated key, the value of the deprecated key is set as the value for
    * the provided property name.
    *
+   * @param deprecations deprecation context
    * @param name the property name
    * @return the first property in the list of properties mapping
    *         the <code>name</code> or the <code>name</code> itself.
    */
   private String[] handleDeprecation(DeprecationContext deprecations,
-      String name) {
+                                     String name) {
     if (null != name) {
       name = name.trim();
     }
-    ArrayList<String > names = new ArrayList<String>();
-	if (isDeprecated(name)) {
-      DeprecatedKeyInfo keyInfo = deprecations.getDeprecatedKeyMap().get(name);
-      warnOnceIfDeprecated(deprecations, name);
-      for (String newKey : keyInfo.newKeys) {
-        if(newKey != null) {
-          names.add(newKey);
-        }
+    // 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) {
+      if (!keyInfo.getAndSetAccessed()) {
+        logDeprecation(keyInfo.getWarningMessage(name));
       }
+      // Override return value for deprecated keys
+      names = keyInfo.newKeys;
     }
-    if(names.size() == 0) {
-    	names.add(name);
-    }
-    for(String n : names) {
-	  String deprecatedKey = deprecations.getReverseDeprecatedKeyMap().get(n);
-	  if (deprecatedKey != null && !getOverlay().containsKey(n) &&
-	      getOverlay().containsKey(deprecatedKey)) {
-	    getProps().setProperty(n, getOverlay().getProperty(deprecatedKey));
-	    getOverlay().setProperty(n, getOverlay().getProperty(deprecatedKey));
-	  }
+    // If there are no overlay values we can return early
+    Properties overlay = getOverlay();
+    if (overlay.isEmpty()) {
+      return names;
+    }
+    // Update properties and overlays with reverse lookup values
+    for (String n : names) {
+      String deprecatedKey = deprecations.getReverseDeprecatedKeyMap().get(n);
+      if (deprecatedKey != null && !overlay.containsKey(n)) {
+        String deprecatedValue = overlay.getProperty(deprecatedKey);
+        if (deprecatedValue != null) {
+          getProps().setProperty(n, deprecatedValue);
+          overlay.setProperty(n, deprecatedValue);
+        }
+      }
     }
-    return names.toArray(new String[names.size()]);
+    return names;
   }
  
   private void handleDeprecation() {
@@ -1179,11 +1186,8 @@ public class Configuration implements Iterable<Map.Entry<String,String>>,
     }
   }
 
-  private void warnOnceIfDeprecated(DeprecationContext deprecations, String name) {
-    DeprecatedKeyInfo keyInfo = deprecations.getDeprecatedKeyMap().get(name);
-    if (keyInfo != null && !keyInfo.getAndSetAccessed()) {
-      LOG_DEPRECATION.info(keyInfo.getWarningMessage(name));
-    }
+  private void logDeprecation(String message) {
+    LOG_DEPRECATION.info(message);
   }
 
   /**


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org


Mime
View raw message