hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cdoug...@apache.org
Subject svn commit: r1137838 - in /hadoop/common/branches/MR-279/common: CHANGES.txt src/java/org/apache/hadoop/conf/Configuration.java
Date Tue, 21 Jun 2011 01:36:03 GMT
Author: cdouglas
Date: Tue Jun 21 01:36:03 2011
New Revision: 1137838

URL: http://svn.apache.org/viewvc?rev=1137838&view=rev
Log:
HADOOP-7082. Configuration.writeXML should not hold lock while outputting. Contributed by
Todd Lipcon

Modified:
    hadoop/common/branches/MR-279/common/CHANGES.txt
    hadoop/common/branches/MR-279/common/src/java/org/apache/hadoop/conf/Configuration.java

Modified: hadoop/common/branches/MR-279/common/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/MR-279/common/CHANGES.txt?rev=1137838&r1=1137837&r2=1137838&view=diff
==============================================================================
--- hadoop/common/branches/MR-279/common/CHANGES.txt (original)
+++ hadoop/common/branches/MR-279/common/CHANGES.txt Tue Jun 21 01:36:03 2011
@@ -1,4 +1,4 @@
-Hn jaadoop Change Log
+Hadoop Change Log
 
 Trunk (unreleased changes)
 
@@ -139,6 +139,9 @@ Trunk (unreleased changes)
     HADOOP-7287. Configuration deprecation mechanism doesn't work properly for
     GenericOptionsParser and Tools. (Aaron T. Myers via todd)
 
+    HADOOP-7082. Configuration.writeXML should not hold lock while outputting.
+    (todd)
+
 Release 0.22.0 - Unreleased
 
   INCOMPATIBLE CHANGES

Modified: hadoop/common/branches/MR-279/common/src/java/org/apache/hadoop/conf/Configuration.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/MR-279/common/src/java/org/apache/hadoop/conf/Configuration.java?rev=1137838&r1=1137837&r2=1137838&view=diff
==============================================================================
--- hadoop/common/branches/MR-279/common/src/java/org/apache/hadoop/conf/Configuration.java
(original)
+++ hadoop/common/branches/MR-279/common/src/java/org/apache/hadoop/conf/Configuration.java
Tue Jun 21 01:36:03 2011
@@ -1589,52 +1589,67 @@ public class Configuration implements It
    * 
    * @param out the writer to write to.
    */
-  public synchronized void writeXml(Writer out) throws IOException {
+  public void writeXml(Writer out) throws IOException {
+    Document doc = asXmlDocument();
+
     Properties properties = getProps();
     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;
+    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 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;
   }
 
   /**



Mime
View raw message