Skip to content

Commit 71071e5

Browse files
amahusseinahussein
andauthored
HADOOP-17358. Improve excessive reloading of Configurations (apache#2436)
Co-authored-by: ahussein <[email protected]>
1 parent 188ebb5 commit 71071e5

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;
@@ -2876,12 +2876,27 @@ public Set<String> getFinalParameters() {
28762876
protected synchronized Properties getProps() {
28772877
if (properties == null) {
28782878
properties = new Properties();
2879-
Map<String, String[]> backup = updatingResource != null ?
2880-
new ConcurrentHashMap<String, String[]>(updatingResource) : null;
2881-
loadResources(properties, resources, quietmode);
2879+
loadProps(properties, 0, true);
2880+
}
2881+
return properties;
2882+
}
28822883

2884+
/**
2885+
* Loads the resource at a given index into the properties.
2886+
* @param props the object containing the loaded properties.
2887+
* @param startIdx the index where the new resource has been added.
2888+
* @param fullReload flag whether we do complete reload of the conf instead
2889+
* of just loading the new resource.
2890+
*/
2891+
private synchronized void loadProps(final Properties props,
2892+
final int startIdx, final boolean fullReload) {
2893+
if (props != null) {
2894+
Map<String, String[]> backup =
2895+
updatingResource != null
2896+
? new ConcurrentHashMap<>(updatingResource) : null;
2897+
loadResources(props, resources, startIdx, fullReload, quietmode);
28832898
if (overlay != null) {
2884-
properties.putAll(overlay);
2899+
props.putAll(overlay);
28852900
if (backup != null) {
28862901
for (Map.Entry<Object, Object> item : overlay.entrySet()) {
28872902
String key = (String) item.getKey();
@@ -2893,7 +2908,6 @@ protected synchronized Properties getProps() {
28932908
}
28942909
}
28952910
}
2896-
return properties;
28972911
}
28982912

28992913
/**
@@ -2995,14 +3009,16 @@ private XMLStreamReader parse(InputStream is, String systemIdStr,
29953009

29963010
private void loadResources(Properties properties,
29973011
ArrayList<Resource> resources,
3012+
int startIdx,
3013+
boolean fullReload,
29983014
boolean quiet) {
2999-
if(loadDefaults) {
3015+
if(loadDefaults && fullReload) {
30003016
for (String resource : defaultResources) {
30013017
loadResource(properties, new Resource(resource, false), quiet);
30023018
}
30033019
}
30043020

3005-
for (int i = 0; i < resources.size(); i++) {
3021+
for (int i = startIdx; i < resources.size(); i++) {
30063022
Resource ret = loadResource(properties, resources.get(i), quiet);
30073023
if (ret != null) {
30083024
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)