LUCENE-1050: detect errors on releasing the lock (if delete of the lock file fails)s

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@595448 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2007-11-15 20:42:54 +00:00
parent 5992c5a1cf
commit c5c1913410
8 changed files with 66 additions and 28 deletions

View File

@ -145,6 +145,10 @@ Bug fixes
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
1. LUCENE-906: Elision filter for French.

View File

@ -1220,11 +1220,6 @@ public class IndexWriter {
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 @@ public class IndexWriter {
if (closeDir)
directory.close();
if (writeLock != null) {
writeLock.release(); // release write lock
writeLock = null;
}
closed = true;
} finally {
synchronized(this) {
if (!closed)

View File

@ -99,7 +99,7 @@ public abstract class Lock {
}
/** 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. */

View File

@ -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 <code>write.lock</code>
* could not be released.
* @see Lock#release().
*/
public class LockReleaseFailedException extends IOException {
public LockReleaseFailedException(String message) {
super(message);
}
}

View File

@ -287,33 +287,28 @@ class NativeFSLock extends Lock {
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);
}
}

View File

@ -144,8 +144,9 @@ class SimpleFSLock extends Lock {
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() {

View File

@ -85,7 +85,7 @@ public class VerifyingLockFactory extends LockFactory {
return lock.isLocked();
}
public synchronized void release() {
public synchronized void release() throws IOException {
if (isLocked()) {
verify((byte) 0);
lock.release();

View File

@ -188,7 +188,12 @@ public class TestLockFactory extends LuceneTestCase {
writer.close();
if (writer2 != null) {
try {
writer2.close();
fail("writer2.close() should have hit LockReleaseFailedException");
} catch (LockReleaseFailedException e) {
// expected
}
}
// Cleanup