You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2015/05/29 19:51:59 UTC
svn commit: r1682523 - in /lucene/dev/branches/lucene6508/lucene/core/src:
java/org/apache/lucene/store/ test/org/apache/lucene/index/
Author: rmuir
Date: Fri May 29 17:51:58 2015
New Revision: 1682523
URL: http://svn.apache.org/r1682523
Log:
LUCENE-6508: add back LockObtainFailedException but in a simpler way
Added:
lucene/dev/branches/lucene6508/lucene/core/src/java/org/apache/lucene/store/LockObtainFailedException.java (with props)
Modified:
lucene/dev/branches/lucene6508/lucene/core/src/java/org/apache/lucene/store/Directory.java
lucene/dev/branches/lucene6508/lucene/core/src/java/org/apache/lucene/store/NativeFSLockFactory.java
lucene/dev/branches/lucene6508/lucene/core/src/java/org/apache/lucene/store/SimpleFSLockFactory.java
lucene/dev/branches/lucene6508/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterWithThreads.java
Modified: lucene/dev/branches/lucene6508/lucene/core/src/java/org/apache/lucene/store/Directory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6508/lucene/core/src/java/org/apache/lucene/store/Directory.java?rev=1682523&r1=1682522&r2=1682523&view=diff
==============================================================================
--- lucene/dev/branches/lucene6508/lucene/core/src/java/org/apache/lucene/store/Directory.java (original)
+++ lucene/dev/branches/lucene6508/lucene/core/src/java/org/apache/lucene/store/Directory.java Fri May 29 17:51:58 2015
@@ -112,7 +112,9 @@ public abstract class Directory implemen
/**
* Returns an obtained {@link Lock}.
* @param name the name of the lock file
- * @throws IOException if the lock could not be obtained
+ * @throws LockObtainFailedException (optional specific exception) if the lock could
+ * not be obtained because it is currently held elsewhere.
+ * @throws IOException if any i/o error occurs attempting to gain the lock
*/
public abstract Lock obtainLock(String name) throws IOException;
Added: lucene/dev/branches/lucene6508/lucene/core/src/java/org/apache/lucene/store/LockObtainFailedException.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6508/lucene/core/src/java/org/apache/lucene/store/LockObtainFailedException.java?rev=1682523&view=auto
==============================================================================
--- lucene/dev/branches/lucene6508/lucene/core/src/java/org/apache/lucene/store/LockObtainFailedException.java (added)
+++ lucene/dev/branches/lucene6508/lucene/core/src/java/org/apache/lucene/store/LockObtainFailedException.java Fri May 29 17:51:58 2015
@@ -0,0 +1,37 @@
+/*
+ * 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 acquired. This
+ * happens when a writer tries to open an index
+ * that another writer already has open.
+ * @see LockFactory#obtainLock(Directory, String)
+ */
+public class LockObtainFailedException extends IOException {
+ public LockObtainFailedException(String message) {
+ super(message);
+ }
+
+ public LockObtainFailedException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
Modified: lucene/dev/branches/lucene6508/lucene/core/src/java/org/apache/lucene/store/NativeFSLockFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6508/lucene/core/src/java/org/apache/lucene/store/NativeFSLockFactory.java?rev=1682523&r1=1682522&r2=1682523&view=diff
==============================================================================
--- lucene/dev/branches/lucene6508/lucene/core/src/java/org/apache/lucene/store/NativeFSLockFactory.java (original)
+++ lucene/dev/branches/lucene6508/lucene/core/src/java/org/apache/lucene/store/NativeFSLockFactory.java Fri May 29 17:51:58 2015
@@ -115,7 +115,7 @@ public final class NativeFSLockFactory e
if (lock != null) {
return new NativeFSLock(lock, channel, realPath, creationTime);
} else {
- throw new IOException("Lock held by another program: " + realPath);
+ throw new LockObtainFailedException("Lock held by another program: " + realPath);
}
} finally {
if (lock == null) { // not successful - clear up and move out
@@ -124,7 +124,7 @@ public final class NativeFSLockFactory e
}
}
} else {
- throw new IOException("Lock held by this virtual machine: " + realPath);
+ throw new LockObtainFailedException("Lock held by this virtual machine: " + realPath);
}
}
Modified: lucene/dev/branches/lucene6508/lucene/core/src/java/org/apache/lucene/store/SimpleFSLockFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6508/lucene/core/src/java/org/apache/lucene/store/SimpleFSLockFactory.java?rev=1682523&r1=1682522&r2=1682523&view=diff
==============================================================================
--- lucene/dev/branches/lucene6508/lucene/core/src/java/org/apache/lucene/store/SimpleFSLockFactory.java (original)
+++ lucene/dev/branches/lucene6508/lucene/core/src/java/org/apache/lucene/store/SimpleFSLockFactory.java Fri May 29 17:51:58 2015
@@ -19,6 +19,7 @@ package org.apache.lucene.store;
import java.io.File;
import java.io.IOException;
+import java.nio.file.FileAlreadyExistsException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
@@ -82,7 +83,12 @@ public final class SimpleFSLockFactory e
Path lockFile = lockDir.resolve(lockName);
// create the file: this will fail if it already exists
- Files.createFile(lockFile);
+ try {
+ Files.createFile(lockFile);
+ } catch (FileAlreadyExistsException e) {
+ // convert optional specific exception to our optional specific exception
+ throw new LockObtainFailedException("Lock held elsewhere: " + lockFile, e);
+ }
// used as a best-effort check, to see if the underlying file has changed
final FileTime creationTime = Files.readAttributes(lockFile, BasicFileAttributes.class).creationTime();
Modified: lucene/dev/branches/lucene6508/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterWithThreads.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6508/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterWithThreads.java?rev=1682523&r1=1682522&r2=1682523&view=diff
==============================================================================
--- lucene/dev/branches/lucene6508/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterWithThreads.java (original)
+++ lucene/dev/branches/lucene6508/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterWithThreads.java Fri May 29 17:51:58 2015
@@ -34,7 +34,6 @@ import org.apache.lucene.search.DocIdSet
import org.apache.lucene.store.AlreadyClosedException;
import org.apache.lucene.store.BaseDirectoryWrapper;
import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.LockObtainFailedException;
import org.apache.lucene.store.MockDirectoryWrapper;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.BytesRef;