Return-Path: Delivered-To: apmail-hadoop-common-commits-archive@www.apache.org Received: (qmail 17078 invoked from network); 4 Jan 2011 22:38:34 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 4 Jan 2011 22:38:34 -0000 Received: (qmail 62065 invoked by uid 500); 4 Jan 2011 22:18:10 -0000 Delivered-To: apmail-hadoop-common-commits-archive@hadoop.apache.org Received: (qmail 62039 invoked by uid 500); 4 Jan 2011 22:18:10 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: common-dev@hadoop.apache.org Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 62016 invoked by uid 99); 4 Jan 2011 22:18:06 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Jan 2011 22:18:06 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Jan 2011 22:18:05 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 1829723889B9; Tue, 4 Jan 2011 22:17:45 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1055209 - in /hadoop/common/branches/branch-0.22: CHANGES.txt src/java/org/apache/hadoop/conf/Configuration.java Date: Tue, 04 Jan 2011 22:17:44 -0000 To: common-commits@hadoop.apache.org From: todd@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110104221745.1829723889B9@eris.apache.org> Author: todd Date: Tue Jan 4 22:17:44 2011 New Revision: 1055209 URL: http://svn.apache.org/viewvc?rev=1055209&view=rev Log: HADOOP-7082. Configuration.writeXML should not hold lock while outputting. Contributed by Todd Lipcon Modified: hadoop/common/branches/branch-0.22/CHANGES.txt hadoop/common/branches/branch-0.22/src/java/org/apache/hadoop/conf/Configuration.java Modified: hadoop/common/branches/branch-0.22/CHANGES.txt URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.22/CHANGES.txt?rev=1055209&r1=1055208&r2=1055209&view=diff ============================================================================== --- hadoop/common/branches/branch-0.22/CHANGES.txt (original) +++ hadoop/common/branches/branch-0.22/CHANGES.txt Tue Jan 4 22:17:44 2011 @@ -357,6 +357,9 @@ Release 0.22.0 - Unreleased HADOOP-7038. saveVersion script includes an additional \r while running whoami under windows. (Wang Xu via cos) + HADOOP-7082. Configuration.writeXML should not hold lock while outputting + (todd) + Release 0.21.1 - Unreleased IMPROVEMENTS Modified: hadoop/common/branches/branch-0.22/src/java/org/apache/hadoop/conf/Configuration.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.22/src/java/org/apache/hadoop/conf/Configuration.java?rev=1055209&r1=1055208&r2=1055209&view=diff ============================================================================== --- hadoop/common/branches/branch-0.22/src/java/org/apache/hadoop/conf/Configuration.java (original) +++ hadoop/common/branches/branch-0.22/src/java/org/apache/hadoop/conf/Configuration.java Tue Jan 4 22:17:44 2011 @@ -1578,52 +1578,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; } /**