lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rm...@apache.org
Subject svn commit: r1222367 - in /lucene/dev/trunk/lucene/src: java/org/apache/lucene/index/IndexWriter.java test/org/apache/lucene/index/TestIndexWriterExceptions.java
Date Thu, 22 Dec 2011 17:36:24 GMT
Author: rmuir
Date: Thu Dec 22 17:36:24 2011
New Revision: 1222367

URL: http://svn.apache.org/viewvc?rev=1222367&view=rev
Log:
LUCENE-3660: release write lock if IW hits a non-ioexception from IR.indexExists

Modified:
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexWriter.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexWriter.java?rev=1222367&r1=1222366&r2=1222367&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexWriter.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexWriter.java Thu Dec 22 17:36:24
2011
@@ -862,22 +862,23 @@ public class IndexWriter implements Clos
     if (!writeLock.obtain(conf.getWriteLockTimeout())) // obtain write lock
       throw new LockObtainFailedException("Index locked for write: " + writeLock);
 
-    OpenMode mode = conf.getOpenMode();
-    boolean create;
-    if (mode == OpenMode.CREATE) {
-      create = true;
-    } else if (mode == OpenMode.APPEND) {
-      create = false;
-    } else {
-      // CREATE_OR_APPEND - create only if an index does not exist
-      create = !IndexReader.indexExists(directory);
-    }
     boolean success = false;
-
-    // If index is too old, reading the segments will throw
-    // IndexFormatTooOldException.
-    segmentInfos = new SegmentInfos();
     try {
+      OpenMode mode = conf.getOpenMode();
+      boolean create;
+      if (mode == OpenMode.CREATE) {
+        create = true;
+      } else if (mode == OpenMode.APPEND) {
+        create = false;
+      } else {
+        // CREATE_OR_APPEND - create only if an index does not exist
+        create = !IndexReader.indexExists(directory);
+      }
+
+      // If index is too old, reading the segments will throw
+      // IndexFormatTooOldException.
+      segmentInfos = new SegmentInfos();
+
       if (create) {
         // Try to read first.  This is to allow create
         // against an index that's currently open for

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java?rev=1222367&r1=1222366&r2=1222367&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java
(original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java
Thu Dec 22 17:36:24 2011
@@ -37,6 +37,7 @@ import org.apache.lucene.search.DocIdSet
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.PhraseQuery;
 import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.IOContext;
 import org.apache.lucene.store.IndexInput;
 import org.apache.lucene.store.IndexOutput;
 import org.apache.lucene.store.MockDirectoryWrapper;
@@ -1459,4 +1460,38 @@ public class TestIndexWriterExceptions e
     r.close();
     dir.close();
   }
+  
+  static class UOEDirectory extends RAMDirectory {
+    boolean doFail = false;
+
+    @Override
+    public IndexInput openInput(String name, IOContext context) throws IOException {
+      if (doFail && name.startsWith("segments_")) {
+        StackTraceElement[] trace = new Exception().getStackTrace();
+        for (int i = 0; i < trace.length; i++) {
+          if ("indexExists".equals(trace[i].getMethodName())) {
+            throw new UnsupportedOperationException("expected UOE");
+          }
+        }
+      }
+      return super.openInput(name, context);
+    }
+  }
+  
+  public void testExceptionOnCtor() throws Exception {
+    UOEDirectory uoe = new UOEDirectory();
+    Directory d = new MockDirectoryWrapper(random, uoe);
+    IndexWriter iw = new IndexWriter(d, newIndexWriterConfig(TEST_VERSION_CURRENT, null));
+    iw.addDocument(new Document());
+    iw.close();
+    uoe.doFail = true;
+    try {
+      new IndexWriter(d, newIndexWriterConfig(TEST_VERSION_CURRENT, null));
+      fail("should have gotten a UOE");
+    } catch (UnsupportedOperationException expected) {
+      
+    }
+    uoe.doFail = false;
+    d.close();
+  }
 }



Mime
View raw message