You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2011/12/22 18:39:33 UTC

svn commit: r1222368 - in /lucene/dev/trunk/lucene: CHANGES.txt src/java/org/apache/lucene/index/SegmentInfos.java src/test-framework/java/org/apache/lucene/store/MockDirectoryWrapper.java

Author: mikemccand
Date: Thu Dec 22 17:39:33 2011
New Revision: 1222368

URL: http://svn.apache.org/viewvc?rev=1222368&view=rev
Log:
LUCENE-3605: don't sleep in retry loop in SegmentInfos.read

Modified:
    lucene/dev/trunk/lucene/CHANGES.txt
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/SegmentInfos.java
    lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/store/MockDirectoryWrapper.java

Modified: lucene/dev/trunk/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/CHANGES.txt?rev=1222368&r1=1222367&r2=1222368&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/CHANGES.txt (original)
+++ lucene/dev/trunk/lucene/CHANGES.txt Thu Dec 22 17:39:33 2011
@@ -770,6 +770,9 @@ Bug fixes
   NRTCachingDir, fixed createOutput to overwrite any previous file,
   and removed invalid asserts (Robert Muir, Mike McCandless)
 
+* LUCENE-3605: don't sleep in a retry loop when trying to locate the
+  segments_N file (Robert Muir, Mike McCandless)
+
 Optimizations
 
 * LUCENE-3653: Improve concurrency in VirtualMethod and AttributeSource by

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/SegmentInfos.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/SegmentInfos.java?rev=1222368&r1=1222367&r2=1222368&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/SegmentInfos.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/SegmentInfos.java Thu Dec 22 17:39:33 2011
@@ -447,54 +447,24 @@ public final class SegmentInfos implemen
 
   /* Advanced configuration of retry logic in loading
      segments_N file */
-  private static int defaultGenFileRetryCount = 10;
-  private static int defaultGenFileRetryPauseMsec = 50;
   private static int defaultGenLookaheadCount = 10;
 
   /**
-   * Advanced: set how many times to try loading the
-   * segments.gen file contents to determine current segment
-   * generation.  This file is only referenced when the
-   * primary method (listing the directory) fails.
-   */
-  public static void setDefaultGenFileRetryCount(int count) {
-    defaultGenFileRetryCount = count;
-  }
-
-  /**
-   * @see #setDefaultGenFileRetryCount
-   */
-  public static int getDefaultGenFileRetryCount() {
-    return defaultGenFileRetryCount;
-  }
-
-  /**
-   * Advanced: set how many milliseconds to pause in between
-   * attempts to load the segments.gen file.
-   */
-  public static void setDefaultGenFileRetryPauseMsec(int msec) {
-    defaultGenFileRetryPauseMsec = msec;
-  }
-
-  /**
-   * @see #setDefaultGenFileRetryPauseMsec
-   */
-  public static int getDefaultGenFileRetryPauseMsec() {
-    return defaultGenFileRetryPauseMsec;
-  }
-
-  /**
    * Advanced: set how many times to try incrementing the
    * gen when loading the segments file.  This only runs if
    * the primary (listing directory) and secondary (opening
    * segments.gen file) methods fail to find the segments
    * file.
+   *
+   * @lucene.experimental
    */
   public static void setDefaultGenLookaheadCount(int count) {
     defaultGenLookaheadCount = count;
   }
   /**
    * @see #setDefaultGenLookaheadCount
+   *
+   * @lucene.experimental
    */
   public static int getDefaultGenLookahedCount() {
     return defaultGenLookaheadCount;
@@ -599,52 +569,40 @@ public final class SegmentInfos implemen
           // a stale cache (NFS) we have a better chance of
           // getting the right generation.
           long genB = -1;
-          for(int i=0;i<defaultGenFileRetryCount;i++) {
-            IndexInput genInput = null;
-            try {
-              genInput = directory.openInput(IndexFileNames.SEGMENTS_GEN, IOContext.READONCE);
-            } catch (FileNotFoundException e) {
-              if (infoStream != null) {
-                message("segments.gen open: FileNotFoundException " + e);
-              }
-              break;
-            } catch (IOException e) {
-              if (infoStream != null) {
-                message("segments.gen open: IOException " + e);
-              }
+          IndexInput genInput = null;
+          try {
+            genInput = directory.openInput(IndexFileNames.SEGMENTS_GEN, IOContext.READONCE);
+          } catch (FileNotFoundException e) {
+            if (infoStream != null) {
+              message("segments.gen open: FileNotFoundException " + e);
             }
+          } catch (IOException e) {
+            if (infoStream != null) {
+              message("segments.gen open: IOException " + e);
+            }
+          }
   
-            if (genInput != null) {
-              try {
-                int version = genInput.readInt();
-                if (version == FORMAT_SEGMENTS_GEN_CURRENT) {
-                  long gen0 = genInput.readLong();
-                  long gen1 = genInput.readLong();
-                  if (infoStream != null) {
-                    message("fallback check: " + gen0 + "; " + gen1);
-                  }
-                  if (gen0 == gen1) {
-                    // The file is consistent.
-                    genB = gen0;
-                    break;
-                  }
-                } else {
-                  /* TODO: Investigate this! 
-                  throw new IndexFormatTooNewException(genInput, version, FORMAT_SEGMENTS_GEN_CURRENT, FORMAT_SEGMENTS_GEN_CURRENT);
-                  */
+          if (genInput != null) {
+            try {
+              int version = genInput.readInt();
+              if (version == FORMAT_SEGMENTS_GEN_CURRENT) {
+                long gen0 = genInput.readLong();
+                long gen1 = genInput.readLong();
+                if (infoStream != null) {
+                  message("fallback check: " + gen0 + "; " + gen1);
                 }
-              } catch (IOException err2) {
-                // rethrow any format exception
-                if (err2 instanceof CorruptIndexException) throw err2;
-                // else will retry
-              } finally {
-                genInput.close();
+                if (gen0 == gen1) {
+                  // The file is consistent.
+                  genB = gen0;
+                }
+              } else {
+                throw new IndexFormatTooNewException(genInput, version, FORMAT_SEGMENTS_GEN_CURRENT, FORMAT_SEGMENTS_GEN_CURRENT);
               }
-            }
-            try {
-              Thread.sleep(defaultGenFileRetryPauseMsec);
-            } catch (InterruptedException ie) {
-              throw new ThreadInterruptedException(ie);
+            } catch (IOException err2) {
+              // rethrow any format exception
+              if (err2 instanceof CorruptIndexException) throw err2;
+            } finally {
+              genInput.close();
             }
           }
 
@@ -881,12 +839,19 @@ public final class SegmentInfos implemen
         genOutput.writeLong(generation);
       } finally {
         genOutput.close();
+        dir.sync(Collections.singleton(IndexFileNames.SEGMENTS_GEN));
       }
     } catch (ThreadInterruptedException t) {
       throw t;
     } catch (Throwable t) {
       // It's OK if we fail to write this file since it's
       // used only as one of the retry fallbacks.
+      try {
+        dir.deleteFile(IndexFileNames.SEGMENTS_GEN);
+      } catch (Throwable t2) {
+        // Ignore; this file is only used in a retry
+        // fallback on init.
+      }
     }
   }
 

Modified: lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/store/MockDirectoryWrapper.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/store/MockDirectoryWrapper.java?rev=1222368&r1=1222367&r2=1222368&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/store/MockDirectoryWrapper.java (original)
+++ lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/store/MockDirectoryWrapper.java Thu Dec 22 17:39:33 2011
@@ -550,7 +550,6 @@ public class MockDirectoryWrapper extend
         if (LuceneTestCase.VERBOSE) {
           System.out.println("\nNOTE: MockDirectoryWrapper: now crash");
         }
-        unSyncedFiles.remove("segments.gen"); // otherwise we add minutes to the tests: LUCENE-3605
         crash(); // corrumpt any unsynced-files
         if (LuceneTestCase.VERBOSE) {
           System.out.println("\nNOTE: MockDirectoryWrapper: now run CheckIndex");