You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by sz...@apache.org on 2012/12/05 01:12:29 UTC
svn commit: r1417245 - in /hadoop/common/branches/branch-1.1: ./ CHANGES.txt
src/core/org/apache/hadoop/conf/Configuration.java
src/test/org/apache/hadoop/hdfs/TestWriteConfigurationToDFS.java
Author: szetszwo
Date: Wed Dec 5 00:12:27 2012
New Revision: 1417245
URL: http://svn.apache.org/viewvc?rev=1417245&view=rev
Log:
svn merge -c 1417238 from branch-1 for HADOOP-9115. Backport HADOOP-7082 and HDFS-1542: Configuration.writeXML should not hold lock while outputting and add a test for a deadlock writing Configuration to HDFS.
Added:
hadoop/common/branches/branch-1.1/src/test/org/apache/hadoop/hdfs/TestWriteConfigurationToDFS.java
- copied unchanged from r1417238, hadoop/common/branches/branch-1/src/test/org/apache/hadoop/hdfs/TestWriteConfigurationToDFS.java
Modified:
hadoop/common/branches/branch-1.1/ (props changed)
hadoop/common/branches/branch-1.1/CHANGES.txt (contents, props changed)
hadoop/common/branches/branch-1.1/src/core/org/apache/hadoop/conf/Configuration.java
Propchange: hadoop/common/branches/branch-1.1/
------------------------------------------------------------------------------
Merged /hadoop/common/branches/branch-1:r1417238
Modified: hadoop/common/branches/branch-1.1/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1.1/CHANGES.txt?rev=1417245&r1=1417244&r2=1417245&view=diff
==============================================================================
--- hadoop/common/branches/branch-1.1/CHANGES.txt (original)
+++ hadoop/common/branches/branch-1.1/CHANGES.txt Wed Dec 5 00:12:27 2012
@@ -31,6 +31,10 @@ Release 1.1.2 - Unreleased
HADOOP-9111. Change some JUnit 3 tests to JUnit 4 so that @Ignore tests can
be run with ant 1.8.x. (Jing Zhao via szetszwo)
+ HADOOP-9115. Backport HADOOP-7082 and HDFS-1542: Configuration.writeXML
+ should not hold lock while outputting and add a test for a deadlock writing
+ Configuration to HDFS. (Jing Zhao via szetszwo)
+
Release 1.1.1 - 2012.11.18
INCOMPATIBLE CHANGES
Propchange: hadoop/common/branches/branch-1.1/CHANGES.txt
------------------------------------------------------------------------------
Merged /hadoop/common/branches/branch-1/CHANGES.txt:r1417238
Modified: hadoop/common/branches/branch-1.1/src/core/org/apache/hadoop/conf/Configuration.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1.1/src/core/org/apache/hadoop/conf/Configuration.java?rev=1417245&r1=1417244&r2=1417245&view=diff
==============================================================================
--- hadoop/common/branches/branch-1.1/src/core/org/apache/hadoop/conf/Configuration.java (original)
+++ hadoop/common/branches/branch-1.1/src/core/org/apache/hadoop/conf/Configuration.java Wed Dec 5 00:12:27 2012
@@ -1261,51 +1261,65 @@ public class Configuration implements It
*
* @param out the writer to write to.
*/
- public synchronized void writeXml(Writer out) throws IOException {
- Properties properties = getProps();
+ public void writeXml(Writer out) throws IOException {
+ Document doc = asXmlDocument();
try {
- Document doc =
- DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
- Element conf = doc.createElement("configuration");
- doc.appendChild(conf);
- conf.appendChild(doc.createTextNode("\n"));
- for (Enumeration e = properties.keys(); e.hasMoreElements();) {
- String name = (String)e.nextElement();
- Object object = properties.get(name);
- String value = null;
- if (object instanceof String) {
- value = (String) object;
- }else {
- continue;
- }
- Element propNode = doc.createElement("property");
- conf.appendChild(propNode);
- if (updatingResource != null) {
- Comment commentNode = doc.createComment("Loaded from "
- + updatingResource.get(name));
- propNode.appendChild(commentNode);
- }
- Element nameNode = doc.createElement("name");
- nameNode.appendChild(doc.createTextNode(name));
- propNode.appendChild(nameNode);
-
- Element valueNode = doc.createElement("value");
- valueNode.appendChild(doc.createTextNode(value));
- propNode.appendChild(valueNode);
-
- conf.appendChild(doc.createTextNode("\n"));
- }
-
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(out);
TransformerFactory transFactory = TransformerFactory.newInstance();
Transformer transformer = transFactory.newTransformer();
+
+ // Important to not hold Configuration log while writing result, since
+ // 'out' may be an HDFS stream which needs to lock this configuration
+ // from another thread.
transformer.transform(source, result);
} catch (TransformerException te) {
throw new IOException(te);
+ }
+ }
+
+ /**
+ * Return the XML DOM corresponding to this Configuration.
+ */
+ private synchronized Document asXmlDocument() throws IOException {
+ Document doc;
+ Properties properties = getProps();
+ try {
+ doc =
+ DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
} catch (ParserConfigurationException pe) {
throw new IOException(pe);
}
+ Element conf = doc.createElement("configuration");
+ doc.appendChild(conf);
+ conf.appendChild(doc.createTextNode("\n"));
+ for (Enumeration<Object> e = properties.keys(); e.hasMoreElements();) {
+ String name = (String) e.nextElement();
+ Object object = properties.get(name);
+ String value = null;
+ if (object instanceof String) {
+ value = (String) object;
+ } else {
+ continue;
+ }
+ Element propNode = doc.createElement("property");
+ conf.appendChild(propNode);
+ if (updatingResource != null) {
+ Comment commentNode = doc.createComment("Loaded from "
+ + updatingResource.get(name));
+ propNode.appendChild(commentNode);
+ }
+ Element nameNode = doc.createElement("name");
+ nameNode.appendChild(doc.createTextNode(name));
+ propNode.appendChild(nameNode);
+
+ Element valueNode = doc.createElement("value");
+ valueNode.appendChild(doc.createTextNode(value));
+ propNode.appendChild(valueNode);
+
+ conf.appendChild(doc.createTextNode("\n"));
+ }
+ return doc;
}
/**