mirror of https://github.com/apache/lucene.git
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:
parent
5992c5a1cf
commit
c5c1913410
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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. */
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -287,8 +287,7 @@ class NativeFSLock extends Lock {
|
|||
return isLocked();
|
||||
}
|
||||
|
||||
public synchronized void release() {
|
||||
try {
|
||||
public synchronized void release() throws IOException {
|
||||
if (isLocked()) {
|
||||
try {
|
||||
lock.release();
|
||||
|
@ -308,12 +307,8 @@ class NativeFSLock extends Lock {
|
|||
}
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue