You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oozie.apache.org by rk...@apache.org on 2017/06/14 18:13:40 UTC

oozie git commit: OOZIE-2651 Set javax.xml.parsers.DocumentBuilderFactory sys prop to make XML handling faster (rkanter)

Repository: oozie
Updated Branches:
  refs/heads/master 62ccfdbab -> 3c4404f7c


OOZIE-2651 Set javax.xml.parsers.DocumentBuilderFactory sys prop to make XML handling faster (rkanter)


Project: http://git-wip-us.apache.org/repos/asf/oozie/repo
Commit: http://git-wip-us.apache.org/repos/asf/oozie/commit/3c4404f7
Tree: http://git-wip-us.apache.org/repos/asf/oozie/tree/3c4404f7
Diff: http://git-wip-us.apache.org/repos/asf/oozie/diff/3c4404f7

Branch: refs/heads/master
Commit: 3c4404f7ce632b92a950136eb9c55ea0bc8b1a9d
Parents: 62ccfdb
Author: Robert Kanter <rk...@apache.org>
Authored: Wed Jun 14 11:13:33 2017 -0700
Committer: Robert Kanter <rk...@apache.org>
Committed: Wed Jun 14 11:13:33 2017 -0700

----------------------------------------------------------------------
 .../oozie/service/ConfigurationService.java     | 13 +++++
 core/src/main/resources/oozie-default.xml       | 12 +++++
 .../DummyDocumentBuilderFactoryImpl.java        | 51 ++++++++++++++++++++
 .../oozie/service/TestConfigurationService.java | 34 +++++++++++++
 .../oozie-site-documentbuilderfactory-empty.xml | 26 ++++++++++
 .../oozie-site-documentbuilderfactory.xml       | 26 ++++++++++
 release-log.txt                                 |  1 +
 7 files changed, 163 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/oozie/blob/3c4404f7/core/src/main/java/org/apache/oozie/service/ConfigurationService.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/oozie/service/ConfigurationService.java b/core/src/main/java/org/apache/oozie/service/ConfigurationService.java
index 524d4d6..9fe179e 100644
--- a/core/src/main/java/org/apache/oozie/service/ConfigurationService.java
+++ b/core/src/main/java/org/apache/oozie/service/ConfigurationService.java
@@ -43,6 +43,8 @@ import org.apache.oozie.util.ZKUtils;
 
 import com.google.common.annotations.VisibleForTesting;
 
+import javax.xml.parsers.DocumentBuilderFactory;
+
 /**
  * Built in service that initializes the services configuration.
  * <p>
@@ -74,6 +76,8 @@ public class ConfigurationService implements Service, Instrumentable {
 
     public static final String CONF_VERIFY_AVAILABLE_PROPS = CONF_PREFIX + "verify.available.properties";
 
+    public static final String CONF_JAVAX_XML_PARSERS_DOCUMENTBUILDERFACTORY = "oozie.javax.xml.parsers.DocumentBuilderFactory";
+
     /**
      * System property that indicates the configuration directory.
      */
@@ -164,6 +168,15 @@ public class ConfigurationService implements Service, Instrumentable {
         if (configuration.getBoolean(CONF_VERIFY_AVAILABLE_PROPS, false)) {
             verifyConfigurationName();
         }
+
+        // Set the javax.xml.parsers.DocumentBuilderFactory property, which should make finding these classes faster, as the JVM
+        // doesn't have to do expensive searching.  This happens quite frequently in Oozie.
+        String docFac = configuration.get(CONF_JAVAX_XML_PARSERS_DOCUMENTBUILDERFACTORY);
+        if (docFac != null && !docFac.trim().isEmpty()) {
+            System.setProperty("javax.xml.parsers.DocumentBuilderFactory", docFac.trim());
+            Class<?> dbfClass = DocumentBuilderFactory.newInstance().getClass();
+            log.debug("Using javax.xml.parsers.DocumentBuilderFactory: {0}", dbfClass.getName());
+        }
     }
 
     public static String getConfigurationDirectory() throws ServiceException {

http://git-wip-us.apache.org/repos/asf/oozie/blob/3c4404f7/core/src/main/resources/oozie-default.xml
----------------------------------------------------------------------
diff --git a/core/src/main/resources/oozie-default.xml b/core/src/main/resources/oozie-default.xml
index a2d376a..c60a458 100644
--- a/core/src/main/resources/oozie-default.xml
+++ b/core/src/main/resources/oozie-default.xml
@@ -3023,4 +3023,16 @@ will be the requeue interval for the actions which are waiting for a long time w
             given action. That is, the args[] array will contain "null" elements. When set to false, then "nulls" are removed.
         </description>
     </property>
+
+    <property>
+        <name>oozie.javax.xml.parsers.DocumentBuilderFactory</name>
+        <value>org.apache.xerces.jaxp.DocumentBuilderFactoryImpl</value>
+        <description>
+            Oozie will set the javax.xml.parsers.DocumentBuilderFactory Java System Property to this value.  This helps speed up
+            XML handling because the JVM doesn't have to search for the proper class every time.  An empty or whitespace value
+            skips setting the System Property.  The default implementation that Oozie uses is Xerces.
+            Most users should not have to change this.
+        </description>
+    </property>
+
 </configuration>

http://git-wip-us.apache.org/repos/asf/oozie/blob/3c4404f7/core/src/test/java/org/apache/oozie/service/DummyDocumentBuilderFactoryImpl.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/oozie/service/DummyDocumentBuilderFactoryImpl.java b/core/src/test/java/org/apache/oozie/service/DummyDocumentBuilderFactoryImpl.java
new file mode 100644
index 0000000..df07cb8
--- /dev/null
+++ b/core/src/test/java/org/apache/oozie/service/DummyDocumentBuilderFactoryImpl.java
@@ -0,0 +1,51 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.oozie.service;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+/**
+ * Used by {@link TestConfigurationService#testDocumentBuilderFactorySystemPropertyCustom}.
+ */
+public class DummyDocumentBuilderFactoryImpl extends DocumentBuilderFactory {
+    @Override
+    public DocumentBuilder newDocumentBuilder() throws ParserConfigurationException {
+        return null;
+    }
+
+    @Override
+    public void setAttribute(String name, Object value) throws IllegalArgumentException {
+    }
+
+    @Override
+    public Object getAttribute(String name) throws IllegalArgumentException {
+        return null;
+    }
+
+    @Override
+    public void setFeature(String name, boolean value) throws ParserConfigurationException {
+    }
+
+    @Override
+    public boolean getFeature(String name) throws ParserConfigurationException {
+        return false;
+    }
+}

http://git-wip-us.apache.org/repos/asf/oozie/blob/3c4404f7/core/src/test/java/org/apache/oozie/service/TestConfigurationService.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/oozie/service/TestConfigurationService.java b/core/src/test/java/org/apache/oozie/service/TestConfigurationService.java
index 5957ad6..7bc81c8 100644
--- a/core/src/test/java/org/apache/oozie/service/TestConfigurationService.java
+++ b/core/src/test/java/org/apache/oozie/service/TestConfigurationService.java
@@ -38,7 +38,9 @@ import org.apache.oozie.util.IOUtils;
 import org.apache.oozie.util.XLogFilter;
 import org.apache.oozie.util.XLogStreamer;
 import org.apache.oozie.workflow.lite.LiteWorkflowAppParser;
+import org.apache.xerces.jaxp.DocumentBuilderFactoryImpl;
 
+import javax.xml.parsers.DocumentBuilderFactory;
 import java.io.File;
 import java.io.FileOutputStream;
 
@@ -288,4 +290,36 @@ public class TestConfigurationService extends XTestCase {
         cl.destroy();
     }
 
+    public void testDocumentBuilderFactorySystemPropertyDefault() throws Exception {
+        verifyDocumentBuilderFactoryClass(DocumentBuilderFactoryImpl.class.getName(), DocumentBuilderFactoryImpl.class);
+    }
+
+    public void testDocumentBuilderFactorySystemPropertyCustom() throws Exception {
+        prepareOozieConfDir("oozie-site-documentbuilderfactory.xml");
+        verifyDocumentBuilderFactoryClass(DummyDocumentBuilderFactoryImpl.class.getName(), DummyDocumentBuilderFactoryImpl.class);
+    }
+
+    public void testDocumentBuilderFactorySystemPropertyEmpty() throws Exception {
+        // Determine the class that the JVM would provide if we don't set the property
+        setSystemProperty("javax.xml.parsers.DocumentBuilderFactory", null);
+        assertNull(System.getProperty("javax.xml.parsers.DocumentBuilderFactory"));
+        Class<?> dbfClass = DocumentBuilderFactory.newInstance().getClass();
+
+        prepareOozieConfDir("oozie-site-documentbuilderfactory-empty.xml");
+        verifyDocumentBuilderFactoryClass(null, dbfClass);
+    }
+
+    private void verifyDocumentBuilderFactoryClass(String expectedPropertyValue, Class<?> expectedClass) throws Exception {
+        setSystemProperty("javax.xml.parsers.DocumentBuilderFactory", null);
+        assertNull(System.getProperty("javax.xml.parsers.DocumentBuilderFactory"));
+        ConfigurationService cl = new ConfigurationService();
+        cl.init(null);
+        assertEquals(expectedPropertyValue, System.getProperty("javax.xml.parsers.DocumentBuilderFactory"));
+        DocumentBuilderFactory docFac = DocumentBuilderFactory.newInstance();
+        assertTrue("Expected DocumentBuilderFactory to be of class [" + expectedClass.getName() + "] but was ["
+                + docFac.getClass().getName() + "]", expectedClass.isInstance(docFac));
+        cl.destroy();
+    }
+
 }
+

http://git-wip-us.apache.org/repos/asf/oozie/blob/3c4404f7/core/src/test/resources/oozie-site-documentbuilderfactory-empty.xml
----------------------------------------------------------------------
diff --git a/core/src/test/resources/oozie-site-documentbuilderfactory-empty.xml b/core/src/test/resources/oozie-site-documentbuilderfactory-empty.xml
new file mode 100644
index 0000000..c4727fa
--- /dev/null
+++ b/core/src/test/resources/oozie-site-documentbuilderfactory-empty.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<configuration>
+
+    <property>
+        <name>oozie.javax.xml.parsers.DocumentBuilderFactory</name>
+        <value> </value>
+    </property>
+
+</configuration>

http://git-wip-us.apache.org/repos/asf/oozie/blob/3c4404f7/core/src/test/resources/oozie-site-documentbuilderfactory.xml
----------------------------------------------------------------------
diff --git a/core/src/test/resources/oozie-site-documentbuilderfactory.xml b/core/src/test/resources/oozie-site-documentbuilderfactory.xml
new file mode 100644
index 0000000..82ed20d
--- /dev/null
+++ b/core/src/test/resources/oozie-site-documentbuilderfactory.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<configuration>
+
+    <property>
+        <name>oozie.javax.xml.parsers.DocumentBuilderFactory</name>
+        <value>org.apache.oozie.service.DummyDocumentBuilderFactoryImpl</value>
+    </property>
+
+</configuration>

http://git-wip-us.apache.org/repos/asf/oozie/blob/3c4404f7/release-log.txt
----------------------------------------------------------------------
diff --git a/release-log.txt b/release-log.txt
index 6b1c2f6..73e3967 100644
--- a/release-log.txt
+++ b/release-log.txt
@@ -1,5 +1,6 @@
 -- Oozie 5.0.0 release (trunk - unreleased)
 
+OOZIE-2651 Set javax.xml.parsers.DocumentBuilderFactory sys prop to make XML handling faster (rkanter)
 OOZIE-2938 Fix Findbugs warnings in oozie-sharelib-hive module (Jan Hentschel via gezapeti)
 OOZIE-2939 Fix Findbugs warnings related to reliance on default encoding in oozie-sharelib-hive2 module (Jan Hentschel via gezapeti)
 OOZIE-2935 Fix "concatenates strings using + in a loop" Findbugs error in oozie-sharelib-streaming (Jan Hentschel via rkanter)