On 13/02/2017 20:44, Serkan Mulayim wrote:
1- How do we check that the index is healthy for SEARCHING (e.g. creating a
searcher) without a crash? As I see there is no problem in creating a Searcher
even if there is a lock (write.lock or merge.lock)
First of all, Lucy should never "crash" in the sense of a segfault. If it
does, this is a bug that should be reported.
Unless your index is on a shared volume like NFS, it can always be searched.
2- How do we check that the index is healthy for INDEXING (e.g. creating a new
indexer). I believe if the index is healthy(answer to the first question) and
there is no LOCK file (e.g. write.lock or merge.lock), then we can assume that
index is healthy and we can create a new indexer, right. (Assuming that there
is no write permission issues or no disk space issues)
You can always create a new Indexer. The worst that can happen is that a
LockErr exception is thrown after the Indexer failed to acquire a lock. Note
that by default, Indexer retries to get a lock for 1000 ms (one second). This
can be configured with IndexManager:
https://lucy.apache.org/docs/c/Lucy/Index/IndexManager.html
3- What are the lock types? As far as I see there are only write.lock and
merge.lock. Are there any others?
This is explained in the documentation:
https://lucy.apache.org/docs/c/Lucy/Docs/FileLocking.html
If we close the application calling Lucy before the indexer is destroyed, is
there an index recovery strategy.
Lucy uses an atomic rename operation when committing data so a crashing
Indexer should never corrupt the index.
What would the implications of simply deleting write.lock and merge.lock be?
In most cases, this shouldn't be necessary. Lucy stores the PID of the process
that created a lock and tries to clear stale lock files from crashed
processes. But this won't work if another processes reuses the PID. If you're
absolutely sure that a lock doesn't belong to an active Indexer, you can
delete the lock directories manually.
Side note: This could be improved by supporting locking mechanisms that
release locks automatically if a process crashes. But these are OS-dependent
and aren't guaranteed to work reliably over NFS:
- `fcntl(F_SETLK)` or `lockf` on POSIX (unsuitable for multi-threaded
operation).
- `flock` on BSD, Linux.
- `CreateFile` with a 0 sharing mode on Windows.
Nick