Skip to content

Apache Lucene open-source search software

LUCENE-1050 and LUCENE-1138 fixes for lock problem

Grant Ingersolled9fdba60173
diff --git a/contrib/spellchecker/src/java/org/apache/lucene/search/spell/SpellChecker.java b/contrib/spellchecker/src/java/org/apache/lucene/search/spell/SpellChecker.java
index 051687977aa..3c77b7a684b 100755
--- a/contrib/spellchecker/src/java/org/apache/lucene/search/spell/SpellChecker.java
+++ b/contrib/spellchecker/src/java/org/apache/lucene/search/spell/SpellChecker.java
@@ -284,7 +284,9 @@ public class SpellChecker {
* @throws IOException
*/
public void clearIndex() throws IOException {
- IndexReader.unlock(spellIndex);
+ if (IndexReader.isLocked(spellIndex)){
+ IndexReader.unlock(spellIndex);
+ }
IndexWriter writer = new IndexWriter(spellIndex, null, true);
writer.close();
}
@@ -308,7 +310,9 @@ public class SpellChecker {
* @throws IOException
*/
public void indexDictionary(Dictionary dict) throws IOException {
- IndexReader.unlock(spellIndex);
+ if (IndexReader.isLocked(spellIndex)){
+ IndexReader.unlock(spellIndex);
+ }
IndexWriter writer = new IndexWriter(spellIndex, new WhitespaceAnalyzer(),
!IndexReader.indexExists(spellIndex));
writer.setMergeFactor(300);
diff --git a/src/java/org/apache/lucene/store/SimpleFSLockFactory.java b/src/java/org/apache/lucene/store/SimpleFSLockFactory.java
index 68ef6a99512..60da6f35150 100755
--- a/src/java/org/apache/lucene/store/SimpleFSLockFactory.java
+++ b/src/java/org/apache/lucene/store/SimpleFSLockFactory.java
@@ -145,7 +145,7 @@ class SimpleFSLock extends Lock {
}
public void release() throws LockReleaseFailedException {
- if (!lockFile.delete())
+ if (lockFile.exists() && !lockFile.delete())
throw new LockReleaseFailedException("failed to delete " + lockFile);
}
diff --git a/src/test/org/apache/lucene/store/TestLockFactory.java b/src/test/org/apache/lucene/store/TestLockFactory.java
index e512a0f2908..7c521b4373d 100755
--- a/src/test/org/apache/lucene/store/TestLockFactory.java
+++ b/src/test/org/apache/lucene/store/TestLockFactory.java
@@ -190,9 +190,9 @@ public class TestLockFactory extends LuceneTestCase {
if (writer2 != null) {
try {
writer2.close();
- fail("writer2.close() should have hit LockReleaseFailedException");
- } catch (LockReleaseFailedException e) {
// expected
+ } catch (LockReleaseFailedException e) {
+ fail("writer2.close() should not have hit LockReleaseFailedException");
}
}