Index: CHANGES.txt =================================================================== --- CHANGES.txt (revision 593780) +++ CHANGES.txt (working copy) @@ -144,6 +144,10 @@ timeout argument is very large (eg Long.MAX_VALUE). Also added Lock.LOCK_OBTAIN_WAIT_FOREVER constant to never timeout. (Nikolay Diakov via Mike McCandless) + +23. LUCENE-1050: Throw LockReleaseFailedException in + Simple/NativeFSLockFactory if we fail to delete the lock file when + releasing the lock. (Nikolay Diakov via Mike McCandless) New features Index: src/test/org/apache/lucene/store/TestLockFactory.java =================================================================== --- src/test/org/apache/lucene/store/TestLockFactory.java (revision 593780) +++ src/test/org/apache/lucene/store/TestLockFactory.java (working copy) @@ -188,7 +188,12 @@ writer.close(); if (writer2 != null) { + try { writer2.close(); + fail("writer2.close() should have hit LockReleaseFailedException"); + } catch (LockReleaseFailedException e) { + // expected + } } // Cleanup Index: src/java/org/apache/lucene/index/IndexWriter.java =================================================================== --- src/java/org/apache/lucene/index/IndexWriter.java (revision 593780) +++ src/java/org/apache/lucene/index/IndexWriter.java (working copy) @@ -1220,11 +1220,6 @@ if (infoStream != null) message("at close: " + segString()); - if (writeLock != null) { - writeLock.release(); // release write lock - writeLock = null; - } - closed = true; docWriter = null; synchronized(this) { @@ -1233,6 +1228,13 @@ if (closeDir) directory.close(); + + if (writeLock != null) { + writeLock.release(); // release write lock + writeLock = null; + } + closed = true; + } finally { synchronized(this) { if (!closed) Index: src/java/org/apache/lucene/store/VerifyingLockFactory.java =================================================================== --- src/java/org/apache/lucene/store/VerifyingLockFactory.java (revision 593780) +++ src/java/org/apache/lucene/store/VerifyingLockFactory.java (working copy) @@ -85,7 +85,7 @@ return lock.isLocked(); } - public synchronized void release() { + public synchronized void release() throws IOException { if (isLocked()) { verify((byte) 0); lock.release(); Index: src/java/org/apache/lucene/store/LockReleaseFailedException.java =================================================================== --- src/java/org/apache/lucene/store/LockReleaseFailedException.java (revision 0) +++ src/java/org/apache/lucene/store/LockReleaseFailedException.java (revision 0) @@ -0,0 +1,31 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.lucene.store; + +import java.io.IOException; + +/** + * This exception is thrown when the write.lock + * could not be released. + * @see Lock#release(). + */ +public class LockReleaseFailedException extends IOException { + public LockReleaseFailedException(String message) { + super(message); + } +} Property changes on: src/java/org/apache/lucene/store/LockReleaseFailedException.java ___________________________________________________________________ Name: svn:eol-style + native Index: src/java/org/apache/lucene/store/NativeFSLockFactory.java =================================================================== --- src/java/org/apache/lucene/store/NativeFSLockFactory.java (revision 593780) +++ src/java/org/apache/lucene/store/NativeFSLockFactory.java (working copy) @@ -287,33 +287,28 @@ return isLocked(); } - public synchronized void release() { - try { - if (isLocked()) { + public synchronized void release() throws IOException { + if (isLocked()) { + try { + lock.release(); + } finally { + lock = null; try { - lock.release(); + channel.close(); } finally { - lock = null; + channel = null; try { - channel.close(); + f.close(); } finally { - channel = null; - try { - f.close(); - } finally { - f = null; - synchronized(LOCK_HELD) { - LOCK_HELD.remove(path.getCanonicalPath()); - } + f = null; + synchronized(LOCK_HELD) { + LOCK_HELD.remove(path.getCanonicalPath()); } } } - path.delete(); } - } catch (IOException e) { - // Not sure how to better message/handle this without - // changing API? - throw new RuntimeException(e); + if (!path.delete()) + throw new LockReleaseFailedException("failed to delete " + path); } } Index: src/java/org/apache/lucene/store/SimpleFSLockFactory.java =================================================================== --- src/java/org/apache/lucene/store/SimpleFSLockFactory.java (revision 593780) +++ src/java/org/apache/lucene/store/SimpleFSLockFactory.java (working copy) @@ -144,8 +144,9 @@ return lockFile.createNewFile(); } - public void release() { - lockFile.delete(); + public void release() throws LockReleaseFailedException { + if (!lockFile.delete()) + throw new LockReleaseFailedException("failed to delete " + lockFile); } public boolean isLocked() { Index: src/java/org/apache/lucene/store/Lock.java =================================================================== --- src/java/org/apache/lucene/store/Lock.java (revision 593780) +++ src/java/org/apache/lucene/store/Lock.java (working copy) @@ -99,7 +99,7 @@ } /** Releases exclusive access. */ - public abstract void release(); + public abstract void release() throws IOException; /** Returns true if the resource is currently locked. Note that one must * still call {@link #obtain()} before using the resource. */