From ed9fdba6017351594de9f8e3ded3357c396eb04b Mon Sep 17 00:00:00 2001 From: Grant Ingersoll Date: Thu, 17 Jan 2008 17:00:43 +0000 Subject: [PATCH] LUCENE-1050 and LUCENE-1138 fixes for lock problem git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@612868 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/lucene/search/spell/SpellChecker.java | 8 ++++++-- src/java/org/apache/lucene/store/SimpleFSLockFactory.java | 2 +- src/test/org/apache/lucene/store/TestLockFactory.java | 4 ++-- 3 files changed, 9 insertions(+), 5 deletions(-) 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"); } }