move to non-deprecated methods to unlock Directory, use SolrIndexWriter to get Directory to unlock since it needs to set the lock factory

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@676199 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2008-07-12 16:27:00 +00:00
parent a11f1fc0b5
commit dc6d97da65
2 changed files with 7 additions and 8 deletions

View File

@ -18,6 +18,7 @@
package org.apache.solr.core;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
@ -256,25 +257,23 @@ public final class SolrCore {
boolean indexExists = dirFile.canRead();
boolean removeLocks = solrConfig.getBool("mainIndex/unlockOnStartup", false);
if (removeLocks) {
if (indexExists && removeLocks) {
// to remove locks, the directory must already exist... so we create it
// if it didn't exist already...
Directory dir = FSDirectory.getDirectory(dirFile, !indexExists);
if (IndexReader.isLocked(dir)) {
Directory dir = SolrIndexWriter.getDirectory(getIndexDir(), solrConfig.mainIndexConfig);
if (dir != null && IndexWriter.isLocked(dir)) {
log.warning(logid+"WARNING: Solr index directory '" + getIndexDir() + "' is locked. Unlocking...");
IndexReader.unlock(dir);
IndexWriter.unlock(dir);
}
}
// Create the index if it doesn't exist. Note that indexExists was tested *before*
// lock removal, since that will result in the creation of the directory.
// Create the index if it doesn't exist.
if(!indexExists) {
log.warning(logid+"Solr index directory '" + dirFile + "' doesn't exist."
+ " Creating new index...");
SolrIndexWriter writer = new SolrIndexWriter("SolrCore.initIndex",getIndexDir(), true, schema, solrConfig.mainIndexConfig);
writer.close();
}
} catch (IOException e) {

View File

@ -82,7 +82,7 @@ public class SolrIndexWriter extends IndexWriter {
}
private static Directory getDirectory(String path, SolrIndexConfig config) throws IOException {
public static Directory getDirectory(String path, SolrIndexConfig config) throws IOException {
Directory d = FSDirectory.getDirectory(path);
String rawLockType = (null == config) ? null : config.lockType;