Reputation: 8718
I need java lucene startup code to check if there is a locked write.lock
file that got left behind after a JVM crash, and if so, need to unlock it.
After a JVM crash, lucene doesn't get an opportunity to release the write.lock file correctly. What I need is java lucene code to check for this case in startup and handle it smoothly without throwing a big fat LockObtainFailedException
.
Lucene version 5 being used.
Upvotes: 2
Views: 7331
Reputation: 718926
This should be solved outside of Lucene by deleting the lock file.
The problem is that a new Lucene instance cannot safely delete the lock file because it can't tell if the lock file is there because an existing instance is still running.
What you need is an external application that can test to see if the instance still exists. You can build this with some simple scripting:
kill -0 <pid>
ps ... <pid>
.If your application is registered as a service (on Linux) the various "init" and service management services (System V init, upstart, systemd) allow you to stop and start services in a controlled fashion. You can even configure a service to relaunch on a service crash.
A third alternative is to use an existing HA (or similar) framework for restarting the Lucene automatically if it crashes. An existing framework will probably have advantages of something you develop from scratch for yourself.
Upvotes: 4