Skip to content

Commit 23fe3bd

Browse files
amahusseinahussein
authored andcommitted
HADOOP-17358. Improve excessive reloading of Configurations (#2436)
Co-authored-by: ahussein <[email protected]> (cherry picked from commit 71071e5)
1 parent 47131cd commit 23fe3bd

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,11 +1027,11 @@ public synchronized void reloadConfiguration() {
10271027
properties = null; // trigger reload
10281028
finalParameters.clear(); // clear site-limits
10291029
}
1030-
1030+
10311031
private synchronized void addResourceObject(Resource resource) {
10321032
resources.add(resource); // add to resources
10331033
restrictSystemProps |= resource.isParserRestricted();
1034-
reloadConfiguration();
1034+
loadProps(properties, resources.size() - 1, false);
10351035
}
10361036

10371037
private static final int MAX_SUBST = 20;
@@ -2872,12 +2872,27 @@ public Set<String> getFinalParameters() {
28722872
protected synchronized Properties getProps() {
28732873
if (properties == null) {
28742874
properties = new Properties();
2875-
Map<String, String[]> backup = updatingResource != null ?
2876-
new ConcurrentHashMap<String, String[]>(updatingResource) : null;
2877-
loadResources(properties, resources, quietmode);
2875+
loadProps(properties, 0, true);
2876+
}
2877+
return properties;
2878+
}
28782879

2880+
/**
2881+
* Loads the resource at a given index into the properties.
2882+
* @param props the object containing the loaded properties.
2883+
* @param startIdx the index where the new resource has been added.
2884+
* @param fullReload flag whether we do complete reload of the conf instead
2885+
* of just loading the new resource.
2886+
*/
2887+
private synchronized void loadProps(final Properties props,
2888+
final int startIdx, final boolean fullReload) {
2889+
if (props != null) {
2890+
Map<String, String[]> backup =
2891+
updatingResource != null
2892+
? new ConcurrentHashMap<>(updatingResource) : null;
2893+
loadResources(props, resources, startIdx, fullReload, quietmode);
28792894
if (overlay != null) {
2880-
properties.putAll(overlay);
2895+
props.putAll(overlay);
28812896
if (backup != null) {
28822897
for (Map.Entry<Object, Object> item : overlay.entrySet()) {
28832898
String key = (String) item.getKey();
@@ -2889,7 +2904,6 @@ protected synchronized Properties getProps() {
28892904
}
28902905
}
28912906
}
2892-
return properties;
28932907
}
28942908

28952909
/**
@@ -2991,14 +3005,16 @@ private XMLStreamReader parse(InputStream is, String systemIdStr,
29913005

29923006
private void loadResources(Properties properties,
29933007
ArrayList<Resource> resources,
3008+
int startIdx,
3009+
boolean fullReload,
29943010
boolean quiet) {
2995-
if(loadDefaults) {
3011+
if(loadDefaults && fullReload) {
29963012
for (String resource : defaultResources) {
29973013
loadResource(properties, new Resource(resource, false), quiet);
29983014
}
29993015
}
30003016

3001-
for (int i = 0; i < resources.size(); i++) {
3017+
for (int i = startIdx; i < resources.size(); i++) {
30023018
Resource ret = loadResource(properties, resources.get(i), quiet);
30033019
if (ret != null) {
30043020
resources.set(i, ret);

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfigurationSubclass.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ public void testReloadNotQuiet() throws Throwable {
5353
SubConf conf = new SubConf(true);
5454
conf.setQuietMode(false);
5555
assertFalse(conf.isReloaded());
56+
// adding a resource does not force a reload.
5657
conf.addResource("not-a-valid-resource");
57-
assertTrue(conf.isReloaded());
58+
assertFalse(conf.isReloaded());
5859
try {
5960
Properties properties = conf.getProperties();
6061
fail("Should not have got here");

0 commit comments

Comments
 (0)