HADOOP-11274. ConcurrentModificationException in Configuration Copy Constructor. Contributed by Junping Du.

This commit is contained in:
Jing Zhao 2014-11-06 16:07:50 -08:00
parent a19123df9a
commit 22ecbd4ab3
2 changed files with 46 additions and 38 deletions

View File

@ -381,6 +381,9 @@ Release 2.6.0 - UNRELEASED
HADOOP-11253. Hadoop streaming test TestStreamXmlMultipleRecords fails on
Windows. (Varun Vasudev via wheat9)
HADOOP-11274. ConcurrentModificationException in Configuration Copy Constructor.
(Junping Du via jing9)
BREAKDOWN OF HDFS-6134 AND HADOOP-10150 SUBTASKS AND RELATED JIRAS
HADOOP-10734. Implement high-performance secure random number sources.

View File

@ -690,8 +690,8 @@ public Configuration(boolean loadDefaults) {
*/
@SuppressWarnings("unchecked")
public Configuration(Configuration other) {
this.resources = (ArrayList<Resource>) other.resources.clone();
synchronized(other) {
this.resources = (ArrayList<Resource>) other.resources.clone();
if (other.properties != null) {
this.properties = (Properties)other.properties.clone();
}
@ -702,15 +702,15 @@ public Configuration(Configuration other) {
this.updatingResource = new HashMap<String, String[]>(other.updatingResource);
this.finalParameters = new HashSet<String>(other.finalParameters);
}
synchronized(Configuration.class) {
REGISTRY.put(this, null);
}
this.classLoader = other.classLoader;
this.loadDefaults = other.loadDefaults;
setQuietMode(other.getQuietMode());
}
synchronized(Configuration.class) {
REGISTRY.put(this, null);
}
}
/**
* Add a default resource. Resources are loaded in the order of the resources
@ -1019,6 +1019,7 @@ public void set(String name, String value, String source) {
getProps().setProperty(name, value);
String newSource = (source == null ? "programatically" : source);
synchronized (this) {
if (!isDeprecated(name)) {
updatingResource.put(name, new String[] {newSource});
String[] altNames = getAlternativeNames(name);
@ -1042,6 +1043,7 @@ public void set(String name, String value, String source) {
}
}
}
}
private void warnOnceIfDeprecated(DeprecationContext deprecations, String name) {
DeprecatedKeyInfo keyInfo = deprecations.getDeprecatedKeyMap().get(name);
@ -2269,7 +2271,7 @@ public Reader getConfResourceAsReader(String name) {
*
* @return final parameter set.
*/
public Set<String> getFinalParameters() {
public synchronized Set<String> getFinalParameters() {
return new HashSet<String>(finalParameters);
}
@ -2532,16 +2534,20 @@ private void loadProperty(Properties properties, String name, String attr,
if (value != null) {
if (!finalParameters.contains(attr)) {
properties.setProperty(attr, value);
synchronized(this) {
updatingResource.put(attr, source);
}
} else if (!value.equals(properties.getProperty(attr))) {
LOG.warn(name+":an attempt to override final parameter: "+attr
+"; Ignoring.");
}
}
if (finalParameter) {
synchronized(this) {
finalParameters.add(attr);
}
}
}
/**
* Write out the non-default properties in this configuration to the given
@ -2733,7 +2739,7 @@ public static void main(String[] args) throws Exception {
}
@Override
public void readFields(DataInput in) throws IOException {
public synchronized void readFields(DataInput in) throws IOException {
clear();
int size = WritableUtils.readVInt(in);
for(int i=0; i < size; ++i) {
@ -2745,9 +2751,8 @@ public void readFields(DataInput in) throws IOException {
}
}
//@Override
@Override
public void write(DataOutput out) throws IOException {
public synchronized void write(DataOutput out) throws IOException {
Properties props = getProps();
WritableUtils.writeVInt(out, props.size());
for(Map.Entry<Object, Object> item: props.entrySet()) {