lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r476345 - in /lucene/java/trunk: CHANGES.txt src/java/org/apache/lucene/index/IndexWriter.java src/test/org/apache/lucene/index/TestIndexWriterLockRelease.java
Date Fri, 17 Nov 2006 22:34:18 GMT
Author: mikemccand
Date: Fri Nov 17 14:34:17 2006
New Revision: 476345

URL: http://svn.apache.org/viewvc?view=rev&rev=476345
Log:
make sure to release write lock in IndexWriter if we hit IOException during construction

Added:
    lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriterLockRelease.java
Modified:
    lucene/java/trunk/CHANGES.txt
    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=476345&r1=476344&r2=476345
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Fri Nov 17 14:34:17 2006
@@ -171,6 +171,11 @@
 
 20. LUCENE-706: Updated fileformats.xml|html concerning the docdelta value in the frequency
file. (Johan Stuyts, Doron Cohen via Grant Ingersoll)
 
+21. LUCENE-715: Fixed private constructor in IndexWriter.java to
+    properly release the acquired write lock if there is an
+    IOException after acquiring the write lock but before finishing
+    instantiation (Matthew Bogosian via Mike McCandless)
+
 Optimizations
 
   1. LUCENE-586: TermDocs.skipTo() is now more efficient for

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=476345&r1=476344&r2=476345
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java Fri Nov 17 14:34:17
2006
@@ -259,16 +259,23 @@
         throw new IOException("Index locked for write: " + writeLock);
       this.writeLock = writeLock;                   // save it
 
-      synchronized (directory) {        // in- & inter-process sync
-        new Lock.With(directory.makeLock(IndexWriter.COMMIT_LOCK_NAME), commitLockTimeout)
{
-            public Object doBody() throws IOException {
-              if (create)
-                segmentInfos.write(directory);
-              else
-                segmentInfos.read(directory);
-              return null;
-            }
-          }.run();
+      try {
+        synchronized (directory) {        // in- & inter-process sync
+          new Lock.With(directory.makeLock(IndexWriter.COMMIT_LOCK_NAME), commitLockTimeout)
{
+              public Object doBody() throws IOException {
+                if (create)
+                  segmentInfos.write(directory);
+                else
+                  segmentInfos.read(directory);
+                return null;
+              }
+            }.run();
+        }
+      } catch (IOException e) {
+        // the doBody method failed
+        this.writeLock.release();
+        this.writeLock = null;
+        throw e;
       }
   }
 

Added: lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriterLockRelease.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriterLockRelease.java?view=auto&rev=476345
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriterLockRelease.java (added)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriterLockRelease.java Fri
Nov 17 14:34:17 2006
@@ -0,0 +1,67 @@
+package org.apache.lucene.index;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import junit.framework.TestCase;
+import org.apache.lucene.index.IndexModifier;
+
+/**
+ * This tests the patch for issue #LUCENE-715 (IndexWriter does not
+ * release its write lock when trying to open an index which does not yet
+ * exist).
+ *
+ * @author mbogosian
+ * @version $Id$
+ */
+
+public class TestIndexWriterLockRelease extends TestCase {
+    private java.io.File __test_dir;
+
+    public void setUp() throws IOException {
+        if (this.__test_dir == null) {
+            String tmp_dir = System.getProperty("java.io.tmpdir", "tmp");
+            this.__test_dir = new File(tmp_dir, "testIndexWriter");
+
+            if (this.__test_dir.exists()) {
+                throw new IOException("test directory \"" + this.__test_dir.getPath() + "\"
already exists (please remove by hand)");
+            }
+
+            if (!this.__test_dir.mkdirs()
+                && !this.__test_dir.isDirectory()) {
+                throw new IOException("unable to create test directory \"" + this.__test_dir.getPath()
+ "\"");
+            }
+        }
+    }
+
+    public void tearDown() throws IOException {
+        if (this.__test_dir != null) {
+            File[] files = this.__test_dir.listFiles();
+
+            for (int i = 0;
+                i < files.length;
+                ++i) {
+                if (!files[i].delete()) {
+                    throw new IOException("unable to remove file in test directory \"" +
this.__test_dir.getPath() + "\" (please remove by hand)");
+                }
+            }
+
+            if (!this.__test_dir.delete()) {
+                throw new IOException("unable to remove test directory \"" + this.__test_dir.getPath()
+ "\" (please remove by hand)");
+            }
+        }
+    }
+
+    public void testIndexWriterLockRelease() throws IOException {
+        IndexModifier im;
+
+        try {
+            im = new IndexModifier(this.__test_dir, new org.apache.lucene.analysis.standard.StandardAnalyzer(),
false);
+        } catch (FileNotFoundException e) {
+            try {
+                im = new IndexModifier(this.__test_dir, new org.apache.lucene.analysis.standard.StandardAnalyzer(),
false);
+            } catch (FileNotFoundException e1) {
+            }
+        }
+    }
+}



Mime
View raw message