Return-Path: Delivered-To: apmail-lucene-java-commits-archive@www.apache.org Received: (qmail 23756 invoked from network); 17 Nov 2006 22:34:52 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 17 Nov 2006 22:34:52 -0000 Received: (qmail 36512 invoked by uid 500); 17 Nov 2006 22:35:03 -0000 Delivered-To: apmail-lucene-java-commits-archive@lucene.apache.org Received: (qmail 36498 invoked by uid 500); 17 Nov 2006 22:35:02 -0000 Mailing-List: contact java-commits-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: java-dev@lucene.apache.org Delivered-To: mailing list java-commits@lucene.apache.org Received: (qmail 36486 invoked by uid 99); 17 Nov 2006 22:35:02 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 17 Nov 2006 14:35:02 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 17 Nov 2006 14:34:51 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id A654C1A9846; Fri, 17 Nov 2006 14:34:18 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: java-commits@lucene.apache.org From: mikemccand@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20061117223418.A654C1A9846@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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) { + } + } + } +}