You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by er...@apache.org on 2014/09/05 20:43:49 UTC
svn commit: r1622756 - in /lucene/dev/branches/branch_4x: ./ solr/
solr/core/ solr/core/src/java/org/apache/solr/core/
solr/core/src/test/org/apache/solr/core/
Author: erick
Date: Fri Sep 5 18:43:48 2014
New Revision: 1622756
URL: http://svn.apache.org/r1622756
Log:
SOLR-5322: core discovery can fail w/NPE and no explanation if a non-readable directory exists
Modified:
lucene/dev/branches/branch_4x/ (props changed)
lucene/dev/branches/branch_4x/solr/ (props changed)
lucene/dev/branches/branch_4x/solr/CHANGES.txt (contents, props changed)
lucene/dev/branches/branch_4x/solr/core/ (props changed)
lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/core/CorePropertiesLocator.java
lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java
lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/core/TestCoreDiscovery.java
Modified: lucene/dev/branches/branch_4x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/CHANGES.txt?rev=1622756&r1=1622755&r2=1622756&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_4x/solr/CHANGES.txt Fri Sep 5 18:43:48 2014
@@ -112,6 +112,8 @@ Other Changes
* SOLR-6445: Upgrade Noggit to verion 0.6 to support more flexible JSON input (Noble Paul , Yonik Seeley)
+* SOLR-5322: core discovery can fail w/NPE and no explanation if a non-readable directory exists
+ (Said Chavkin, Erick Erickson)
================== 4.10.0 =================
Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/core/CorePropertiesLocator.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/core/CorePropertiesLocator.java?rev=1622756&r1=1622755&r2=1622756&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/core/CorePropertiesLocator.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/core/CorePropertiesLocator.java Fri Sep 5 18:43:48 2014
@@ -120,15 +120,20 @@ public class CorePropertiesLocator imple
public List<CoreDescriptor> discover(CoreContainer cc) {
logger.info("Looking for core definitions underneath {}", rootDirectory.getAbsolutePath());
List<CoreDescriptor> cds = Lists.newArrayList();
+ if (rootDirectory.canRead() == false) {
+ throw new RuntimeException("Solr home '" + rootDirectory.getAbsolutePath() + "' doesn't have read permissions");
+ }
discoverUnder(rootDirectory, cds, cc);
logger.info("Found {} core definitions", cds.size());
return cds;
}
private void discoverUnder(File root, List<CoreDescriptor> cds, CoreContainer cc) {
- if (!root.exists())
- return;
for (File child : root.listFiles()) {
+ if (child.canRead() == false) {
+ logger.warn("Cannot read directory or file during core discovery '" + child.getAbsolutePath() + "' during core discovery. Skipping");
+ continue;
+ }
File propertiesFile = new File(child, PROPERTIES_FILENAME);
if (propertiesFile.exists()) {
CoreDescriptor cd = buildCoreDescriptor(propertiesFile, cc);
Modified: lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java?rev=1622756&r1=1622755&r2=1622756&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java Fri Sep 5 18:43:48 2014
@@ -348,7 +348,9 @@ public class TestCoreContainer extends S
@Test
public void testCustomHandlers() throws Exception {
- SolrResourceLoader loader = new SolrResourceLoader("solr/collection1");
+ solrHomeDirectory = createTempDir("_customHandlers");
+ SolrResourceLoader loader = new SolrResourceLoader(solrHomeDirectory.getAbsolutePath());
+
ConfigSolr config = ConfigSolr.fromString(loader, CUSTOM_HANDLERS_SOLR_XML);
CoreContainer cc = new CoreContainer(loader, config);
Modified: lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/core/TestCoreDiscovery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/core/TestCoreDiscovery.java?rev=1622756&r1=1622755&r2=1622756&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/core/TestCoreDiscovery.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/core/TestCoreDiscovery.java Fri Sep 5 18:43:48 2014
@@ -21,6 +21,7 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
+import java.nio.file.Files;
import java.util.Properties;
import org.apache.commons.io.FileUtils;
@@ -227,6 +228,122 @@ public class TestCoreDiscovery extends S
cc.shutdown();
}
}
+
+ @Test
+ public void testCoreDirCantRead() throws Exception {
+ File coreDir = solrHomeDirectory;
+ setMeUp(coreDir.getAbsolutePath());
+ addCoreWithProps(makeCorePropFile("core1", false, true),
+ new File(coreDir, "core1" + File.separator + CorePropertiesLocator.PROPERTIES_FILENAME));
+
+ // Insure that another core is opened successfully
+ addCoreWithProps(makeCorePropFile("core2", false, false, "dataDir=core2"),
+ new File(coreDir, "core2" + File.separator + CorePropertiesLocator.PROPERTIES_FILENAME));
+
+ File toSet = new File(coreDir, "core1");
+ toSet.setReadable(false, false);
+ CoreContainer cc = init();
+ try (SolrCore core1 = cc.getCore("core1");
+ SolrCore core2 = cc.getCore("core2")) {
+ assertNull(core1);
+ assertNotNull(core2);
+ } finally {
+ cc.shutdown();
+ }
+ // So things can be cleaned up by the framework!
+ toSet.setReadable(true, false);
+ }
+
+ @Test
+ public void testNonCoreDirCantRead() throws Exception {
+ File coreDir = solrHomeDirectory;
+ setMeUp(coreDir.getAbsolutePath());
+ addCoreWithProps(makeCorePropFile("core1", false, true),
+ new File(coreDir, "core1" + File.separator + CorePropertiesLocator.PROPERTIES_FILENAME));
+
+ addCoreWithProps(makeCorePropFile("core2", false, false, "dataDir=core2"),
+ new File(coreDir, "core2" + File.separator + CorePropertiesLocator.PROPERTIES_FILENAME));
+
+ File toSet = new File(solrHomeDirectory, "cantReadDir");
+ assertTrue("Should have been able to make directory '" + toSet.getAbsolutePath() + "' ", toSet.mkdirs());
+ toSet.setReadable(false, false);
+ CoreContainer cc = init();
+ try (SolrCore core1 = cc.getCore("core1");
+ SolrCore core2 = cc.getCore("core2")) {
+ assertNotNull(core1); // Should be able to open the perfectly valid core1 despite a non-readable directory
+ assertNotNull(core2);
+ } finally {
+ cc.shutdown();
+ }
+ // So things can be cleaned up by the framework!
+ toSet.setReadable(true, false);
+
+ }
+
+ @Test
+ public void testFileCantRead() throws Exception {
+ File coreDir = solrHomeDirectory;
+ setMeUp(coreDir.getAbsolutePath());
+ addCoreWithProps(makeCorePropFile("core1", false, true),
+ new File(coreDir, "core1" + File.separator + CorePropertiesLocator.PROPERTIES_FILENAME));
+
+ File toSet = new File(solrHomeDirectory, "cantReadFile");
+ assertTrue("Should have been able to make file '" + toSet.getAbsolutePath() + "' ", toSet.createNewFile());
+ toSet.setReadable(false, false);
+ CoreContainer cc = init();
+ try (SolrCore core1 = cc.getCore("core1")) {
+ assertNotNull(core1); // Should still be able to create core despite r/o file.
+ } finally {
+ cc.shutdown();
+ }
+ // So things can be cleaned up by the framework!
+ toSet.setReadable(true, false);
+ }
+
+ @Test
+ public void testSolrHomeDoesntExist() throws Exception {
+ File homeDir = solrHomeDirectory;
+ Files.delete(homeDir.toPath());
+ CoreContainer cc = null;
+ try {
+ cc = init();
+ } catch (SolrException ex) {
+ assertTrue("Core init doesn't report if solr home directory doesn't exist " + ex.getMessage(),
+ 0 <= ex.getMessage().indexOf("solr.xml does not exist"));
+ } finally {
+ if (cc != null) {
+ cc.shutdown();
+ }
+ }
+ }
+
+
+ @Test
+ public void testSolrHomeNotReadable() throws Exception {
+ File homeDir = solrHomeDirectory;
+ setMeUp(homeDir.getAbsolutePath());
+ addCoreWithProps(makeCorePropFile("core1", false, true),
+ new File(homeDir, "core1" + File.separator + CorePropertiesLocator.PROPERTIES_FILENAME));
+
+ homeDir.setReadable(false, false);
+
+ CoreContainer cc = null;
+ try {
+ cc = init();
+ } catch (Exception ex) {
+ String eoe = ex.getMessage();
+
+ assertTrue("Should have had a runtime exception here",
+ 0 < ex.getMessage().indexOf("doesn't have read permissions"));
+ } finally {
+ if (cc != null) {
+ cc.shutdown();
+ }
+ }
+ // So things can be cleaned up by the framework!
+ homeDir.setReadable(true, false);
+
+ }
// For testing whether finding a solr.xml overrides looking at solr.properties
private final static String SOLR_XML = "<solr> " +
"<int name=\"transientCacheSize\">2</int> " +