move index exists check into DirectoryFactory so that it can more properly work with RamDir

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/branches/newtrunk@926320 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Robert Miller 2010-03-22 20:31:06 +00:00
parent c8c5dfa543
commit ab336b8a17
3 changed files with 27 additions and 10 deletions

View File

@ -16,6 +16,7 @@ package org.apache.solr.core;
* limitations under the License.
*/
import java.io.File;
import java.io.IOException;
import org.apache.lucene.store.Directory;
@ -34,6 +35,12 @@ public abstract class DirectoryFactory implements NamedListInitializedPlugin {
* @throws IOException
*/
public abstract Directory open(String path) throws IOException;
public boolean exists(String path) {
// back compat behavior
File dirFile = new File(path);
return dirFile.canRead();
}
public void init(NamedList args) {

View File

@ -17,13 +17,12 @@
package org.apache.solr.core;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.RAMDirectory;
import java.io.IOException;
import java.io.File;
import java.util.Map;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.apache.lucene.store.Directory;
/**
* Directory provider for using lucene RAMDirectory
@ -45,6 +44,17 @@ public class RAMDirectoryFactory extends StandardDirectoryFactory {
return directory;
}
}
public boolean exists(String path) {
synchronized (this) {
RefCntRamDirectory directory = directories.get(path);
if (directory == null || !directory.isOpen()) {
return false;
} else {
return true;
}
}
}
/**
* Non-public for unit-test access only. Do not use directly

View File

@ -365,15 +365,15 @@ public final class SolrCore implements SolrInfoMBean {
void initIndex() {
try {
File dirFile = new File(getNewIndexDir());
boolean indexExists = dirFile.canRead();
initDirectoryFactory();
boolean indexExists = getDirectoryFactory().exists(getNewIndexDir());
boolean firstTime;
synchronized (SolrCore.class) {
firstTime = dirs.add(dirFile.getCanonicalPath());
firstTime = dirs.add(new File(getNewIndexDir()).getCanonicalPath());
}
boolean removeLocks = solrConfig.unlockOnStartup;
initDirectoryFactory();
initIndexReaderFactory();
if (indexExists && firstTime && removeLocks) {
@ -391,7 +391,7 @@ public final class SolrCore implements SolrInfoMBean {
// Create the index if it doesn't exist.
if(!indexExists) {
log.warn(logid+"Solr index directory '" + dirFile + "' doesn't exist."
log.warn(logid+"Solr index directory '" + new File(getNewIndexDir()) + "' doesn't exist."
+ " Creating new index...");
SolrIndexWriter writer = new SolrIndexWriter("SolrCore.initIndex", getIndexDir(), getDirectoryFactory(), true, schema, solrConfig.mainIndexConfig, solrDelPolicy);