You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2011/12/22 18:54:10 UTC
svn commit: r1222376 - in /lucene/dev/branches/branch_3x: ./ lucene/
lucene/src/java/org/apache/lucene/index/IndexWriter.java
lucene/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java
Author: rmuir
Date: Thu Dec 22 17:54:10 2011
New Revision: 1222376
URL: http://svn.apache.org/viewvc?rev=1222376&view=rev
Log:
LUCENE-3660: release write lock if IW hits a non-ioexception from IR.indexExists
Modified:
lucene/dev/branches/branch_3x/ (props changed)
lucene/dev/branches/branch_3x/lucene/ (props changed)
lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/IndexWriter.java
lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java
Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/IndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/IndexWriter.java?rev=1222376&r1=1222375&r2=1222376&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/IndexWriter.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/IndexWriter.java Thu Dec 22 17:54:10 2011
@@ -1099,26 +1099,26 @@ public class IndexWriter implements Clos
if (!writeLock.obtain(writeLockTimeout)) // 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;
+ 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);
+ }
- // TODO: we should check whether this index is too old,
- // and throw an IndexFormatTooOldExc up front, here,
- // instead of later when merge, applyDeletes, getReader
- // is attempted. I think to do this we should store the
- // oldest segment's version in segments_N.
+ // TODO: we should check whether this index is too old,
+ // and throw an IndexFormatTooOldExc up front, here,
+ // instead of later when merge, applyDeletes, getReader
+ // is attempted. I think to do this we should store the
+ // oldest segment's version in segments_N.
- try {
if (create) {
// Try to read first. This is to allow create
// against an index that's currently open for
Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java?rev=1222376&r1=1222375&r2=1222376&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java Thu Dec 22 17:54:10 2011
@@ -1294,4 +1294,38 @@ public class TestIndexWriterExceptions e
r.close();
dir.close();
}
+
+ static class UOEDirectory extends RAMDirectory {
+ boolean doFail = false;
+
+ @Override
+ public IndexInput openInput(String name) 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);
+ }
+ }
+
+ 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();
+ }
}