mirror of https://github.com/apache/lucene.git
SOLR-6718: coreRootDirectory should be resolved against SOLR_HOME
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1646660 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
eef8a835dd
commit
8079368b8b
|
@ -126,6 +126,10 @@ Upgrading from Solr 4.x
|
|||
java -jar -Dc=<collection_name> post.jar *.xml (new call with collection name)
|
||||
See SOLR-6852 for more details.
|
||||
|
||||
* Relative paths specified in the solr.xml coreRootDirectory parameter for core
|
||||
discovery are now resolved relative to SOLR_HOME, rather than cwd. See
|
||||
SOLR-6718.
|
||||
|
||||
Detailed Change List
|
||||
----------------------
|
||||
|
||||
|
@ -330,6 +334,9 @@ Bug Fixes
|
|||
component. Increased test coverage of expand component with docValues.
|
||||
(Christine Poerschke, Per Steffensen, shalin)
|
||||
|
||||
* SOLR-6718: Core discovery was walking paths relative to the Jetty working
|
||||
directory, rather than SOLR_HOME. (Andreas Hubold, Alan Woodward)
|
||||
|
||||
* SOLR-6864: Support registering searcher listeners in SolrCoreAware.inform(SolrCore)
|
||||
method. Existing components rely on this. (Tomás Fernández Löbbe)
|
||||
|
||||
|
|
|
@ -17,18 +17,6 @@ package org.apache.solr.core;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import javax.xml.xpath.XPath;
|
||||
import javax.xml.xpath.XPathConstants;
|
||||
import javax.xml.xpath.XPathExpressionException;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.solr.cloud.CloudConfigSetService;
|
||||
import org.apache.solr.cloud.ZkController;
|
||||
|
@ -42,6 +30,18 @@ import org.w3c.dom.Node;
|
|||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
import javax.xml.xpath.XPath;
|
||||
import javax.xml.xpath.XPathConstants;
|
||||
import javax.xml.xpath.XPathExpressionException;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
|
||||
public abstract class ConfigSolr {
|
||||
protected static Logger log = LoggerFactory.getLogger(ConfigSolr.class);
|
||||
|
@ -105,7 +105,11 @@ public abstract class ConfigSolr {
|
|||
* @return core root directory
|
||||
*/
|
||||
public String getCoreRootDirectory() {
|
||||
return SolrResourceLoader.normalizeDir( get(CfgProp.SOLR_COREROOTDIRECTORY, config.getResourceLoader().getInstanceDir()) );
|
||||
SolrResourceLoader loader = config.getResourceLoader();
|
||||
String relativeDir = get(CfgProp.SOLR_COREROOTDIRECTORY, null);
|
||||
if (relativeDir != null)
|
||||
return loader.resolve(relativeDir);
|
||||
return loader.getInstanceDir();
|
||||
}
|
||||
|
||||
public PluginInfo getShardHandlerFactoryPluginInfo() {
|
||||
|
|
|
@ -19,7 +19,6 @@ package org.apache.solr.core;
|
|||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.solr.cloud.CloudDescriptor;
|
||||
import org.apache.solr.common.SolrException;
|
||||
|
@ -32,6 +31,7 @@ import java.io.FileInputStream;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Locale;
|
||||
import java.util.Properties;
|
||||
|
||||
|
@ -324,10 +324,7 @@ public class CoreDescriptor {
|
|||
|
||||
private static String convertToAbsolute(String instDir, String solrHome) {
|
||||
checkNotNull(instDir);
|
||||
File f = new File(instDir);
|
||||
if (f.isAbsolute())
|
||||
return SolrResourceLoader.normalizeDir(instDir);
|
||||
return SolrResourceLoader.normalizeDir(solrHome + SolrResourceLoader.normalizeDir(instDir));
|
||||
return SolrResourceLoader.normalizeDir(Paths.get(solrHome).resolve(instDir).toString());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -48,7 +48,6 @@ import javax.naming.Context;
|
|||
import javax.naming.InitialContext;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.NoInitialContextException;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
|
@ -65,6 +64,7 @@ import java.net.URLClassLoader;
|
|||
import java.nio.charset.CharacterCodingException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
@ -857,4 +857,8 @@ public class SolrResourceLoader implements ResourceLoader,Closeable
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String resolve(String pathToResolve) {
|
||||
return Paths.get(instanceDir).resolve(pathToResolve).toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,13 +17,6 @@ package org.apache.solr.core;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
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;
|
||||
import org.apache.lucene.util.IOUtils;
|
||||
import org.apache.solr.SolrTestCaseJ4;
|
||||
|
@ -32,7 +25,17 @@ import org.junit.After;
|
|||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Properties;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
import static org.junit.internal.matchers.StringContains.containsString;
|
||||
|
||||
public class TestCoreDiscovery extends SolrTestCaseJ4 {
|
||||
|
||||
|
@ -211,6 +214,38 @@ public class TestCoreDiscovery extends SolrTestCaseJ4 {
|
|||
cc.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAlternateRelativeCoreDir() throws Exception {
|
||||
|
||||
String relative = "relativeCoreDir";
|
||||
|
||||
setMeUp(relative);
|
||||
// two cores under the relative directory
|
||||
addCoreWithProps(makeCorePropFile("core1", false, true, "dataDir=core1"),
|
||||
solrHomeDirectory.toPath().resolve(relative).resolve("core1").resolve(CorePropertiesLocator.PROPERTIES_FILENAME).toFile());
|
||||
addCoreWithProps(makeCorePropFile("core2", false, false, "dataDir=core2"),
|
||||
solrHomeDirectory.toPath().resolve(relative).resolve("core2").resolve(CorePropertiesLocator.PROPERTIES_FILENAME).toFile());
|
||||
// one core *not* under the relative directory
|
||||
addCoreWithProps(makeCorePropFile("core0", false, true, "datadir=core0"),
|
||||
solrHomeDirectory.toPath().resolve("core0").resolve(CorePropertiesLocator.PROPERTIES_FILENAME).toFile());
|
||||
|
||||
CoreContainer cc = init();
|
||||
try (SolrCore core1 = cc.getCore("core1");
|
||||
SolrCore core2 = cc.getCore("core2")) {
|
||||
assertNotNull(core1);
|
||||
assertNotNull(core2);
|
||||
|
||||
assertNull(cc.getCore("core0"));
|
||||
|
||||
SolrCore core3 = cc.create(new CoreDescriptor(cc, "core3", "core3", "configSet", "minimal"));
|
||||
assertThat(core3.getCoreDescriptor().getInstanceDir(), containsString("relative"));
|
||||
|
||||
} finally {
|
||||
cc.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoCoreDir() throws Exception {
|
||||
File noCoreDir = createTempDir().toFile();
|
||||
|
@ -344,9 +379,11 @@ public class TestCoreDiscovery extends SolrTestCaseJ4 {
|
|||
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> " +
|
||||
"<str name=\"configSetBaseDir\">" + Paths.get(TEST_HOME()).resolve("configsets").toString() + "</str>" +
|
||||
"<solrcloud> " +
|
||||
"<str name=\"hostContext\">solrprop</str> " +
|
||||
"<int name=\"zkClientTimeout\">20</int> " +
|
||||
|
@ -354,4 +391,16 @@ public class TestCoreDiscovery extends SolrTestCaseJ4 {
|
|||
"<int name=\"hostPort\">6000</int> " +
|
||||
"</solrcloud> " +
|
||||
"</solr>";
|
||||
|
||||
@Test
|
||||
public void testRootDirectoryResolution() {
|
||||
|
||||
SolrResourceLoader loader = new SolrResourceLoader(solrHomeDirectory.getAbsolutePath());
|
||||
|
||||
ConfigSolr config = ConfigSolr.fromString(loader, "<solr><str name=\"coreRootDirectory\">relative</str></solr>");
|
||||
assertThat(config.getCoreRootDirectory(), containsString(solrHomeDirectory.getAbsolutePath()));
|
||||
|
||||
ConfigSolr absConfig = ConfigSolr.fromString(loader, "<solr><str name=\"coreRootDirectory\">/absolute</str></solr>");
|
||||
assertThat(absConfig.getCoreRootDirectory(), not(containsString(solrHomeDirectory.getAbsolutePath())));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,10 +17,6 @@ package org.apache.solr.core;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
|
||||
import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.lucene.util.TestUtil;
|
||||
|
@ -33,6 +29,12 @@ import org.junit.rules.ExpectedException;
|
|||
import org.junit.rules.RuleChain;
|
||||
import org.junit.rules.TestRule;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
|
||||
import static org.junit.internal.matchers.StringContains.containsString;
|
||||
|
||||
public class TestSolrXml extends SolrTestCaseJ4 {
|
||||
|
||||
@Rule
|
||||
|
@ -67,7 +69,7 @@ public class TestSolrXml extends SolrTestCaseJ4 {
|
|||
assertEquals("collection handler class", "testCollectionsHandler", cfg.getCollectionsHandlerClass());
|
||||
assertEquals("info handler class", "testInfoHandler", cfg.getInfoHandlerClass());
|
||||
assertEquals("core load threads", 11, cfg.getCoreLoadThreadCount());
|
||||
assertEquals("core root dir", "testCoreRootDirectory" + File.separator, cfg.getCoreRootDirectory());
|
||||
assertThat("core root dir", cfg.getCoreRootDirectory(), containsString("testCoreRootDirectory"));
|
||||
assertEquals("distrib conn timeout", 22, cfg.getDistributedConnectionTimeout());
|
||||
assertEquals("distrib socket timeout", 33, cfg.getDistributedSocketTimeout());
|
||||
assertEquals("max update conn", 3, cfg.getMaxUpdateConnections());
|
||||
|
@ -103,7 +105,7 @@ public class TestSolrXml extends SolrTestCaseJ4 {
|
|||
FileUtils.copyFile(new File(testSrcRoot, "solr-50-all.xml"), new File(solrHome, "solr.xml"));
|
||||
|
||||
ConfigSolr cfg = ConfigSolr.fromSolrHome(loader, solrHome.getAbsolutePath());
|
||||
assertEquals("core root dir", "myCoreRoot" + File.separator, cfg.getCoreRootDirectory());
|
||||
assertThat(cfg.getCoreRootDirectory(), containsString("myCoreRoot"));
|
||||
assertEquals("solr host port", "8888", cfg.getSolrHostPort());
|
||||
assertEquals("schema cache", false, cfg.hasSchemaCache());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue