alkis commented on code in PR #5685:
URL: https://github.com/apache/hadoop/pull/5685#discussion_r1213414808
##########
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:
Added. I left the name as is because the function is not related to
deprecated properties or not.
##########
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:
done
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]