Skip to content

Commit 487eaa6

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

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
@@ -1005,11 +1005,11 @@ public synchronized void reloadConfiguration() {
10051005
properties = null; // trigger reload
10061006
finalParameters.clear(); // clear site-limits
10071007
}
1008-
1008+
10091009
private synchronized void addResourceObject(Resource resource) {
10101010
resources.add(resource); // add to resources
10111011
restrictSystemProps |= resource.isParserRestricted();
1012-
reloadConfiguration();
1012+
loadProps(properties, resources.size() - 1, false);
10131013
}
10141014

10151015
private static final int MAX_SUBST = 20;
@@ -2843,12 +2843,27 @@ public Set<String> getFinalParameters() {
28432843
protected synchronized Properties getProps() {
28442844
if (properties == null) {
28452845
properties = new Properties();
2846-
Map<String, String[]> backup = updatingResource != null ?
2847-
new ConcurrentHashMap<String, String[]>(updatingResource) : null;
2848-
loadResources(properties, resources, quietmode);
2846+
loadProps(properties, 0, true);
2847+
}
2848+
return properties;
2849+
}
28492850

2851+
/**
2852+
* Loads the resource at a given index into the properties.
2853+
* @param props the object containing the loaded properties.
2854+
* @param startIdx the index where the new resource has been added.
2855+
* @param fullReload flag whether we do complete reload of the conf instead
2856+
* of just loading the new resource.
2857+
*/
2858+
private synchronized void loadProps(final Properties props,
2859+
final int startIdx, final boolean fullReload) {
2860+
if (props != null) {
2861+
Map<String, String[]> backup =
2862+
updatingResource != null
2863+
? new ConcurrentHashMap<>(updatingResource) : null;
2864+
loadResources(props, resources, startIdx, fullReload, quietmode);
28502865
if (overlay != null) {
2851-
properties.putAll(overlay);
2866+
props.putAll(overlay);
28522867
if (backup != null) {
28532868
for (Map.Entry<Object, Object> item : overlay.entrySet()) {
28542869
String key = (String) item.getKey();
@@ -2860,7 +2875,6 @@ protected synchronized Properties getProps() {
28602875
}
28612876
}
28622877
}
2863-
return properties;
28642878
}
28652879

28662880
/**
@@ -2962,14 +2976,16 @@ private XMLStreamReader parse(InputStream is, String systemIdStr,
29622976

29632977
private void loadResources(Properties properties,
29642978
ArrayList<Resource> resources,
2979+
int startIdx,
2980+
boolean fullReload,
29652981
boolean quiet) {
2966-
if(loadDefaults) {
2982+
if(loadDefaults && fullReload) {
29672983
for (String resource : defaultResources) {
29682984
loadResource(properties, new Resource(resource, false), quiet);
29692985
}
29702986
}
29712987

2972-
for (int i = 0; i < resources.size(); i++) {
2988+
for (int i = startIdx; i < resources.size(); i++) {
29732989
Resource ret = loadResource(properties, resources.get(i), quiet);
29742990
if (ret != null) {
29752991
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)