问题
When an application server exits unexpectedly, Hibernate Search can not do a graceful shutdown of Lucene. Leaving write.lock files behind in each index directory. That is of course quite normal. But - the lock files also remain after restarting the application. Which causes lock timeout exceptions at some time.
My question is whether there is a usual way to handle the recovery.
What comes first at mind would be to check for the presence of write.lock files. If one is found, they are removed and all indices are rebuilt. But maybe Hibernate-Search does this automatically when properly configured ?
回答1:
if Hibernate Search were to remove lock files at boot, it might risk to destroy your index if by mistake you configured two applications to run on the same index. Hence not deleting the lock file is the purpose of the lock.
Still, we realized this was annoying: if you can use the Native LockFactory ( http://docs.jboss.org/hibernate/search/4.1/reference/en-US/html_single/#search-configuration-directory-lockfactories ) even a crashed / killed JVM will release the lock files.
If you upgrade to latest versions, Native is used by default if the detected platform is considered safe enough.
来源:https://stackoverflow.com/questions/9771127/how-to-handle-hibernate-search-index-recovery