lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r562546 - in /lucene/java/trunk: CHANGES.txt src/java/org/apache/lucene/index/IndexFileDeleter.java src/java/org/apache/lucene/index/IndexWriter.java
Date Fri, 03 Aug 2007 18:41:23 GMT
Author: mikemccand
Date: Fri Aug  3 11:41:22 2007
New Revision: 562546

URL: http://svn.apache.org/viewvc?view=rev&rev=562546
Log:
LUCENE-948: handle stale dir listing caches on NFS (so quickly switching writers between machines
works)

Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/src/java/org/apache/lucene/index/IndexFileDeleter.java
    lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?view=diff&rev=562546&r1=562545&r2=562546
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Fri Aug  3 11:41:22 2007
@@ -61,6 +61,11 @@
  9. LUCENE-832: ParallelReader fixed to not throw NPE if isCurrent(),
     isOptimized() or getVersion() is called. (Michael Busch)
       
+10. LUCENE-948: Fix FNFE exception caused by stale NFS client
+    directory listing caches when writers on different machines are
+    sharing an index over NFS and using a custom deletion policy (Mike
+    McCandless)
+
 New features
 
  1. LUCENE-906: Elision filter for French.

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/IndexFileDeleter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/IndexFileDeleter.java?view=diff&rev=562546&r1=562545&r2=562546
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/IndexFileDeleter.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/IndexFileDeleter.java Fri Aug  3 11:41:22
2007
@@ -23,6 +23,7 @@
 import org.apache.lucene.store.Directory;
 
 import java.io.IOException;
+import java.io.FileNotFoundException;
 import java.io.PrintStream;
 import java.util.Map;
 import java.util.HashMap;
@@ -123,6 +124,9 @@
     this.docWriter = docWriter;
     this.infoStream = infoStream;
 
+    if (infoStream != null)
+      message("init: current segments file is \"" + segmentInfos.getCurrentSegmentFileName()
+ "\"");
+
     this.policy = policy;
     this.directory = directory;
 
@@ -156,13 +160,29 @@
               message("init: load commit \"" + fileName + "\"");
             }
             SegmentInfos sis = new SegmentInfos();
-            sis.read(directory, fileName);
-            CommitPoint commitPoint = new CommitPoint(sis);
-            if (sis.getGeneration() == segmentInfos.getGeneration()) {
-              currentCommitPoint = commitPoint;
+            try {
+              sis.read(directory, fileName);
+            } catch (FileNotFoundException e) {
+              // LUCENE-948: on NFS (and maybe others), if
+              // you have writers switching back and forth
+              // between machines, it's very likely that the
+              // dir listing will be stale and will claim a
+              // file segments_X exists when in fact it
+              // doesn't.  So, we catch this and handle it
+              // as if the file does not exist
+              if (infoStream != null) {
+                message("init: hit FileNotFoundException when loading commit \"" + fileName
+ "\"; skipping this commit point");
+              }
+              sis = null;
+            }
+            if (sis != null) {
+              CommitPoint commitPoint = new CommitPoint(sis);
+              if (sis.getGeneration() == segmentInfos.getGeneration()) {
+                currentCommitPoint = commitPoint;
+              }
+              commits.add(commitPoint);
+              incRef(sis, true);
             }
-            commits.add(commitPoint);
-            incRef(sis, true);
           }
         }
       }

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java?view=diff&rev=562546&r1=562545&r2=562546
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java Fri Aug  3 11:41:22
2007
@@ -928,6 +928,8 @@
 
       if (commitPending) {
         segmentInfos.write(directory);         // now commit changes
+        if (infoStream != null)
+          infoStream.println("close: wrote segments file \"" + segmentInfos.getCurrentSegmentFileName()
+ "\"");
         deleter.checkpoint(segmentInfos, true);
         commitPending = false;
         rollbackSegmentInfos = null;
@@ -1478,6 +1480,8 @@
   private void checkpoint() throws IOException {
     if (autoCommit) {
       segmentInfos.write(directory);
+      if (infoStream != null)
+        infoStream.println("checkpoint: wrote segments file \"" + segmentInfos.getCurrentSegmentFileName()
+ "\"");
     } else {
       commitPending = true;
     }



Mime
View raw message