SOLR-4413: Fix SolrCore#getIndexDir() to return the current index directory.

SOLR-4469: A new IndexWriter must be opened on SolrCore reload when the index directory has changed and the previous SolrCore's state should not be  propagated.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1447089 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Robert Miller 2013-02-17 22:13:35 +00:00
parent d51e6f2c29
commit d3accc58e6
5 changed files with 39 additions and 27 deletions

View File

@ -139,6 +139,13 @@ Bug Fixes
* SOLR-4467: Ephemeral directory implementations may not recover correctly
because the code to clear the tlog files on startup is off. (Mark Miller)
* SOLR-4413: Fix SolrCore#getIndexDir() to return the current index directory.
(Gregg Donovan, Mark Miller)
* SOLR-4469: A new IndexWriter must be opened on SolrCore reload when the index
directory has changed and the previous SolrCore's state should not be
propagated. (Mark Miller, Gregg Donovan)
Optimizations
----------------------

View File

@ -218,8 +218,13 @@ public final class SolrCore implements SolrInfoMBean {
return dataDir;
}
public String getIndexDir() {
return dataDir + "index/";
public String getIndexDir() {
synchronized (searcherLock) {
if (_searcher == null) return getNewIndexDir();
SolrIndexSearcher searcher = _searcher.get();
return searcher.getPath() == null ? dataDir + "index/" : searcher
.getPath();
}
}
@ -395,6 +400,11 @@ public final class SolrCore implements SolrInfoMBean {
solrCoreState.increfSolrCoreState();
if (!getNewIndexDir().equals(getIndexDir())) {
// the directory is changing, don't pass on state
prev = null;
}
SolrCore core = new SolrCore(getName(), getDataDir(), config,
schema, coreDescriptor, updateHandler, prev);
core.solrDelPolicy = this.solrDelPolicy;
@ -1364,7 +1374,7 @@ public final class SolrCore implements SolrInfoMBean {
}
// for now, turn off caches if this is for a realtime reader (caches take a little while to instantiate)
tmp = new SolrIndexSearcher(this, schema, (realtime ? "realtime":"main"), newReader, true, !realtime, true, directoryFactory);
tmp = new SolrIndexSearcher(this, newIndexDir, schema, (realtime ? "realtime":"main"), newReader, true, !realtime, true, directoryFactory);
} else {
// newestSearcher == null at this point
@ -1374,7 +1384,7 @@ public final class SolrCore implements SolrInfoMBean {
// so that we pick up any uncommitted changes and so we don't go backwards
// in time on a core reload
DirectoryReader newReader = newReaderCreator.call();
tmp = new SolrIndexSearcher(this, schema, (realtime ? "realtime":"main"), newReader, true, !realtime, true, directoryFactory);
tmp = new SolrIndexSearcher(this, newIndexDir, schema, (realtime ? "realtime":"main"), newReader, true, !realtime, true, directoryFactory);
} else {
// normal open that happens at startup
// verbose("non-reopen START:");

View File

@ -103,7 +103,7 @@ public class SnapShooter {
Collection<String> files = indexCommit.getFileNames();
FileCopier fileCopier = new FileCopier();
Directory dir = solrCore.getDirectoryFactory().get(solrCore.getNewIndexDir(), DirContext.DEFAULT, solrCore.getSolrConfig().indexConfig.lockType);
Directory dir = solrCore.getDirectoryFactory().get(solrCore.getIndexDir(), DirContext.DEFAULT, solrCore.getSolrConfig().indexConfig.lockType);
try {
fileCopier.copyFiles(dir, files, snapShotDir);
} finally {

View File

@ -610,13 +610,17 @@ public class CoreAdminHandler extends RequestHandlerBase {
}
if (params.getBool(CoreAdminParams.DELETE_INDEX, false)) {
core.addCloseHook(new CloseHook() {
private String indexDir;
@Override
public void preClose(SolrCore core) {}
public void preClose(SolrCore core) {
indexDir = core.getIndexDir();
}
@Override
public void postClose(SolrCore core) {
try {
core.getDirectoryFactory().remove(core.getIndexDir());
core.getDirectoryFactory().remove(indexDir);
} catch (IOException e) {
throw new RuntimeException(e);
}
@ -1026,11 +1030,8 @@ public class CoreAdminHandler extends RequestHandlerBase {
Directory dir;
long size = 0;
try {
if (!core.getDirectoryFactory().exists(core.getIndexDir())) {
dir = core.getDirectoryFactory().get(core.getNewIndexDir(), DirContext.DEFAULT, core.getSolrConfig().indexConfig.lockType);
} else {
dir = core.getDirectoryFactory().get(core.getIndexDir(), DirContext.DEFAULT, core.getSolrConfig().indexConfig.lockType);
}
dir = core.getDirectoryFactory().get(core.getIndexDir(), DirContext.DEFAULT, core.getSolrConfig().indexConfig.lockType);
try {
size = DirectoryFactory.sizeOfDirectory(dir);

View File

@ -116,27 +116,17 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable,SolrIn
private Collection<String> storedHighlightFieldNames;
private DirectoryFactory directoryFactory;
private final AtomicReader atomicReader;
private final AtomicReader atomicReader;
private String path;
public SolrIndexSearcher(SolrCore core, String path, IndexSchema schema, SolrIndexConfig config, String name, boolean enableCache, DirectoryFactory directoryFactory) throws IOException {
// we don't need to reserve the directory because we get it from the factory
this(core, schema,name, core.getIndexReaderFactory().newReader(directoryFactory.get(path, DirContext.DEFAULT, config.lockType), core), true, enableCache, false, directoryFactory);
this(core, path, schema,name, core.getIndexReaderFactory().newReader(directoryFactory.get(path, DirContext.DEFAULT, config.lockType), core), true, enableCache, false, directoryFactory);
}
private static String getIndexDir(Directory dir) {
if (dir instanceof FSDirectory) {
return ((FSDirectory)dir).getDirectory().getAbsolutePath();
} else if (dir instanceof NRTCachingDirectory) {
// recurse on the delegate
return getIndexDir(((NRTCachingDirectory) dir).getDelegate());
} else {
log.warn("WARNING: Directory impl does not support setting indexDir: " + dir.getClass().getName());
return null;
}
}
public SolrIndexSearcher(SolrCore core, IndexSchema schema, String name, DirectoryReader r, boolean closeReader, boolean enableCache, boolean reserveDirectory, DirectoryFactory directoryFactory) throws IOException {
public SolrIndexSearcher(SolrCore core, String path, IndexSchema schema, String name, DirectoryReader r, boolean closeReader, boolean enableCache, boolean reserveDirectory, DirectoryFactory directoryFactory) throws IOException {
super(r);
this.path = path;
this.directoryFactory = directoryFactory;
this.reader = r;
this.atomicReader = SlowCompositeReaderWrapper.wrap(r);
@ -210,6 +200,10 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable,SolrIn
// do this at the end since an exception in the constructor means we won't close
numOpens.incrementAndGet();
}
public String getPath() {
return path;
}
@Override
public String toString() {