You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by yo...@apache.org on 2011/11/18 00:50:28 UTC

svn commit: r1203425 - in /lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update: DefaultSolrCoreState.java DirectUpdateHandler2.java SolrCoreState.java

Author: yonik
Date: Thu Nov 17 23:50:28 2011
New Revision: 1203425

URL: http://svn.apache.org/viewvc?rev=1203425&view=rev
Log:
add SolrCoreState hook for closing writer

Modified:
    lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/DefaultSolrCoreState.java
    lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java
    lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/SolrCoreState.java

Modified: lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/DefaultSolrCoreState.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/DefaultSolrCoreState.java?rev=1203425&r1=1203424&r2=1203425&view=diff
==============================================================================
--- lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/DefaultSolrCoreState.java (original)
+++ lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/DefaultSolrCoreState.java Thu Nov 17 23:50:28 2011
@@ -50,10 +50,12 @@ public final class DefaultSolrCoreState 
   }
 
   @Override
-  public synchronized void decref() throws IOException {
+  public synchronized void decref(IndexWriterCloser closer) throws IOException {
     refCnt--;
     if (refCnt == 0) {
-      if (indexWriter != null) {
+      if (closer != null) {
+        closer.closeWriter(indexWriter);
+      } else if (indexWriter != null) {
         indexWriter.close();
       }
       directoryFactory.close();

Modified: lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java?rev=1203425&r1=1203424&r2=1203425&view=diff
==============================================================================
--- lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java (original)
+++ lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java Thu Nov 17 23:50:28 2011
@@ -54,7 +54,7 @@ import org.apache.solr.search.SolrIndexS
  * <code>DirectUpdateHandler2</code> implements an UpdateHandler where documents are added
  * directly to the main Lucene index as opposed to adding to a separate smaller index.
  */
-public class DirectUpdateHandler2 extends UpdateHandler {
+public class DirectUpdateHandler2 extends UpdateHandler implements SolrCoreState.IndexWriterCloser {
   protected SolrCoreState solrCoreState;
   protected final Lock commitLock = new ReentrantLock();
 
@@ -467,11 +467,26 @@ public class DirectUpdateHandler2 extend
 
     numDocsPending.set(0);
 
-    solrCoreState.decref();
-    
-    log.info("closed " + this);
+    solrCoreState.decref(this);
   }
 
+  // IndexWriterCloser interface method - called from solrCoreState.decref(this)
+  @Override
+  public void closeWriter(IndexWriter writer) throws IOException {
+    if (writer == null) return;
+    commitLock.lock();
+    try {
+      writer.close();
+      // if the writer hits an exception, it's OK (and perhaps desirable)
+      // to not close the ulog?
+
+      // Closing the log currently deletes the log file.
+      // If this changes, we should record this as a "commit".
+      ulog.close();
+    } finally {
+      commitLock.unlock();
+    }
+  }
 
   /////////////////////////////////////////////////////////////////////
   // SolrInfoMBean stuff: Statistics and Module Info
@@ -551,7 +566,7 @@ public class DirectUpdateHandler2 extend
   @Override
   public void decref() {
     try {
-      solrCoreState.decref();
+      solrCoreState.decref(this);
     } catch (IOException e) {
       throw new SolrException(ErrorCode.SERVER_ERROR, "", e, false);
     }

Modified: lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/SolrCoreState.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/SolrCoreState.java?rev=1203425&r1=1203424&r2=1203425&view=diff
==============================================================================
--- lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/SolrCoreState.java (original)
+++ lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/SolrCoreState.java Thu Nov 17 23:50:28 2011
@@ -49,11 +49,12 @@ public abstract class SolrCoreState {
   
   /**
    * Decrement the number of references to this state. When then number of
-   * references hits 0, the state will close.
+   * references hits 0, the state will close.  If an optional closer is
+   * passed, that will be used to close the writer.
    * 
    * @throws IOException
    */
-  public abstract void decref() throws IOException;
+  public abstract void decref(IndexWriterCloser closer) throws IOException;
   
   /**
    * Increment the number of references to this state.
@@ -73,5 +74,9 @@ public abstract class SolrCoreState {
    * @return the {@link DirectoryFactory} that should be used.
    */
   public abstract DirectoryFactory getDirectoryFactory();
-  
+
+
+  public interface IndexWriterCloser {
+    public void closeWriter(IndexWriter writer) throws IOException;
+  }
 }