From 52fe544a4c60fa3ec86c438a62ad12b5c45db07d Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Mon, 18 Aug 2014 17:33:49 +0000 Subject: [PATCH] SOLR-6387: Add better error messages throughout Solr and supply a work around for Java bug #8047340 to SystemInfoHandler: On Turkish default locale, some JVMs fail to fork on MacOSX, BSD, AIX, and Solaris platforms. git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1618672 13f79535-47bb-0310-9956-ffa450edef68 --- solr/CHANGES.txt | 4 ++++ .../org/apache/solr/hadoop/MRUnitBase.java | 5 ++++- .../solr/AbstractSolrMorphlineTestBase.java | 2 ++ .../solr/AbstractSolrMorphlineZkTestBase.java | 3 +++ .../solr/core/RunExecutableListener.java | 13 ++++++++++++- .../solr/handler/admin/SystemInfoHandler.java | 18 +++++++++++------- 6 files changed, 36 insertions(+), 9 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index d581eee2a52..711012ab9df 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -285,6 +285,10 @@ Bug Fixes * SOLR-6383: RegexTransformer returns no results after replaceAll if regex does not match a value. (Alexander Kingson, shalin) +* SOLR-6387: Add better error messages throughout Solr and supply a work around for + Java bug #8047340 to SystemInfoHandler: On Turkish default locale, some JVMs fail + to fork on MacOSX, BSD, AIX, and Solaris platforms. (hossman, Uwe Schindler) + Optimizations --------------------- diff --git a/solr/contrib/map-reduce/src/test/org/apache/solr/hadoop/MRUnitBase.java b/solr/contrib/map-reduce/src/test/org/apache/solr/hadoop/MRUnitBase.java index 31e5a919ef6..42ff9d9a99b 100644 --- a/solr/contrib/map-reduce/src/test/org/apache/solr/hadoop/MRUnitBase.java +++ b/solr/contrib/map-reduce/src/test/org/apache/solr/hadoop/MRUnitBase.java @@ -18,6 +18,7 @@ package org.apache.solr.hadoop; import java.io.File; import java.io.IOException; +import java.util.Locale; import org.apache.commons.io.FileUtils; import org.apache.hadoop.conf.Configuration; @@ -35,13 +36,15 @@ public abstract class MRUnitBase extends SolrTestCaseJ4 { @BeforeClass public static void setupClass() throws Exception { + assumeFalse("This test fails on UNIX with Turkish default locale (https://issues.apache.org/jira/browse/SOLR-6387)", + new Locale("tr").getLanguage().equals(Locale.getDefault().getLanguage())); solrHomeZip = SolrOutputFormat.createSolrHomeZip(new File(RESOURCES_DIR + "/solr/mrunit")); assertNotNull(solrHomeZip); } @AfterClass public static void teardownClass() throws Exception { - solrHomeZip.delete(); + if (solrHomeZip != null) solrHomeZip.delete(); } protected void setupHadoopConfig(Configuration config) throws IOException { diff --git a/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/AbstractSolrMorphlineTestBase.java b/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/AbstractSolrMorphlineTestBase.java index e997b591c1e..af0b033c6dc 100644 --- a/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/AbstractSolrMorphlineTestBase.java +++ b/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/AbstractSolrMorphlineTestBase.java @@ -84,6 +84,8 @@ public class AbstractSolrMorphlineTestBase extends SolrTestCaseJ4 { @BeforeClass public static void beforeClass() throws Exception { + assumeFalse("This test fails on UNIX with Turkish default locale (https://issues.apache.org/jira/browse/SOLR-6387)", + new Locale("tr").getLanguage().equals(Locale.getDefault().getLanguage())); myInitCore(DEFAULT_BASE_DIR); } diff --git a/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/AbstractSolrMorphlineZkTestBase.java b/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/AbstractSolrMorphlineZkTestBase.java index 2b501171b6f..da9ef6324fa 100644 --- a/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/AbstractSolrMorphlineZkTestBase.java +++ b/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/AbstractSolrMorphlineZkTestBase.java @@ -20,6 +20,7 @@ package org.apache.solr.morphlines.solr; import java.io.File; import java.io.IOException; import java.util.Iterator; +import java.util.Locale; import org.apache.commons.io.FileUtils; import org.apache.solr.client.solrj.SolrServerException; @@ -68,6 +69,8 @@ public abstract class AbstractSolrMorphlineZkTestBase extends AbstractFullDistri @BeforeClass public static void setupClass() throws Exception { + assumeFalse("This test fails on UNIX with Turkish default locale (https://issues.apache.org/jira/browse/SOLR-6387)", + new Locale("tr").getLanguage().equals(Locale.getDefault().getLanguage())); solrHomeDirectory = createTempDir(); AbstractZkTestCase.SOLRHOME = solrHomeDirectory; FileUtils.copyDirectory(SOLR_INSTANCE_DIR, solrHomeDirectory); diff --git a/solr/core/src/java/org/apache/solr/core/RunExecutableListener.java b/solr/core/src/java/org/apache/solr/core/RunExecutableListener.java index 43fbc589fa9..e0300b3163c 100644 --- a/solr/core/src/java/org/apache/solr/core/RunExecutableListener.java +++ b/solr/core/src/java/org/apache/solr/core/RunExecutableListener.java @@ -78,7 +78,18 @@ class RunExecutableListener extends AbstractSolrEventListener { if (doLog) { log.debug("About to exec " + cmd[0]); } - Process proc = Runtime.getRuntime().exec(cmd, envp ,dir); + final Process proc; + try { + proc = Runtime.getRuntime().exec(cmd, envp ,dir); + } catch (Error err) { + // Create better error message + if (err.getMessage() != null && err.getMessage().contains("posix_spawn")) { + Error newErr = new Error("Error forking command due to JVM locale bug (see https://issues.apache.org/jira/browse/SOLR-6387): " + err.getMessage()); + newErr.setStackTrace(err.getStackTrace()); + err = newErr; + } + throw err; + } if (wait) { try { diff --git a/solr/core/src/java/org/apache/solr/handler/admin/SystemInfoHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/SystemInfoHandler.java index b58e52a8f0f..f09c1a8e5de 100644 --- a/solr/core/src/java/org/apache/solr/handler/admin/SystemInfoHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/admin/SystemInfoHandler.java @@ -17,9 +17,9 @@ package org.apache.solr.handler.admin; -import java.io.DataInputStream; import java.io.File; import java.io.IOException; +import java.io.InputStream; import java.io.InputStreamReader; import java.lang.management.ManagementFactory; import java.lang.management.OperatingSystemMXBean; @@ -213,20 +213,24 @@ public class SystemInfoHandler extends RequestHandlerBase */ private static String execute( String cmd ) { - DataInputStream in = null; + InputStream in = null; Process process = null; try { process = Runtime.getRuntime().exec(cmd); - in = new DataInputStream( process.getInputStream() ); + in = process.getInputStream(); // use default charset from locale here, because the command invoked also uses the default locale: return IOUtils.toString(new InputStreamReader(in, Charset.defaultCharset())); - } - catch( Exception ex ) { + } catch( Exception ex ) { // ignore - log.warn("Error executing command", ex); return "(error executing: " + cmd + ")"; - } - finally { + } catch (Error err) { + if (err.getMessage() != null && err.getMessage().contains("posix_spawn")) { + log.warn("Error forking command due to JVM locale bug (see https://issues.apache.org/jira/browse/SOLR-6387): " + err.getMessage()); + return "(error executing: " + cmd + ")"; + } + throw err; + } finally { if (process != null) { IOUtils.closeQuietly( process.getOutputStream() ); IOUtils.closeQuietly( process.getInputStream() );