Unlock at startup using SimpleFSLockFactory

Description

I'm using SimpleFSLockFactory and I'm getting this exception after an unexpected shutdown of the application during indexation:

org.apache.lucene.store.LockObtainFailedException: Lock obtain timed out

The workaround consists in executing this code at startup in order to unlock the indexes:

FullTextSession fullTextSession = Search.getFullTextSession(hbSession);

MutableSearchFactory searchFactory = (MutableSearchFactory) fullTextSession
.getSearchFactory();

IndexReader indexReader = fullTextSession.getSearchFactory()
.getIndexReaderAccessor().open("");

Map<Class<?>, EntityIndexBinder> indexBindingsForEntity = searchFactory
.getIndexBindingForEntity();

for (EntityIndexBinder eib : indexBindingsForEntity.values()) {
IndexManager[] indexManagers = eib.getIndexManagers();
DirectoryBasedIndexManager indexManager = (DirectoryBasedIndexManager) indexManagers[0];

Directory indexDirectory = indexManager.getDirectoryProvider()
.getDirectory();

if (IndexWriter.isLocked(indexDirectory)) {
IndexWriter.unlock(indexDirectory);
}
}

I have a single application that executes this code at startup so I think it's safe to unlock the Directory at this time.

I'm doing this because I'm using SimpleFSLockFactory and it leaves write.lock files.
I need to unlock at startup because I think using NativeFSLockFactory is not an option for me (I'm using NFS).

It will be a good thing if Hibernate Search have an "unlock at startup" option. It could be used only in cases like this (not all cases!).

In Solr there is an option:

<unlockOnStartup>true</unlockOnStartup>

Environment

Java 1.6, Hibernate Search 4.0.0.CR2 on Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bits

Status

Assignee

Unassigned

Reporter

DavidD

Suitable for new contributors

Yes, likely

Pull Request

None

Feedback Requested

None

Components

Priority

Major
Configure