IndexWriter.isLocked() fails on a read-only directory [LUCENE-2607]
- Dominant language
- Java
- Stars
- 3.6k
- Forks
- 1.4k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 88
Description
This appears to be a regression of some sort because the issue was only discovered by us some time after upgrading to the 2.9 series, and was not present when we were using 2.3 (big gap between those two, though.)
We had some code like:
```Java
if (IndexWriter.isLocked(directory))
{
IndexWriter.unlock(directory);
}
```
And now we get an exception when this code runs on a read-only location:
```
java.lang.RuntimeException: Failed to acquire random test lock; please verify filesystem for lock directory 'X:\Data\Index' supports locking at
org.apache.lucene.store.NativeFSLockFactory.acquireTestLock(NativeFSLockFactory.java:99) at
org.apache.lucene.store.NativeFSLockFactory.makeLock(NativeFSLockFactory.java:137) at
org.apache.lucene.store.Directory.makeLock(Directory.java:131) at
org.apache.lucene.index.IndexWriter.isLocked(IndexWriter.java:5672) at
```
I think it makes more logical sense to return **false** - if locking is not possible then it cannot be locked, therefore isLocked should always return false.
---
Migrated from [LUCENE-2607](https://issues.apache.org/jira/browse/LUCENE-2607) by Trejkaz, updated Sep 24 2010
Contributor guide
Research direction
Start at IndexWriter.isLocked and follow the lock creation path through Directory.makeLock and NativeFSLockFactory.makeLock, using the reported NativeFSLockFactory.java stack trace as the entry point. Reproduce the call against a read-only directory and verify that isLocked returns false rather than raising the lock-acquisition exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- search
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100