You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by yo...@apache.org on 2008/07/12 18:27:01 UTC

svn commit: r676199 - in /lucene/solr/trunk/src/java/org/apache/solr: core/SolrCore.java update/SolrIndexWriter.java

Author: yonik
Date: Sat Jul 12 09:27:00 2008
New Revision: 676199

URL: http://svn.apache.org/viewvc?rev=676199&view=rev
Log:
move to non-deprecated methods to unlock Directory, use SolrIndexWriter to get Directory to unlock since it needs to set the lock factory

Modified:
    lucene/solr/trunk/src/java/org/apache/solr/core/SolrCore.java
    lucene/solr/trunk/src/java/org/apache/solr/update/SolrIndexWriter.java

Modified: lucene/solr/trunk/src/java/org/apache/solr/core/SolrCore.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/core/SolrCore.java?rev=676199&r1=676198&r2=676199&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/core/SolrCore.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/core/SolrCore.java Sat Jul 12 09:27:00 2008
@@ -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 @@
       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) {

Modified: lucene/solr/trunk/src/java/org/apache/solr/update/SolrIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/update/SolrIndexWriter.java?rev=676199&r1=676198&r2=676199&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/update/SolrIndexWriter.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/update/SolrIndexWriter.java Sat Jul 12 09:27:00 2008
@@ -82,7 +82,7 @@
 
   }
 
-  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;