Backing up a Lucene hot index using IndexReader instead of IndexWriter / SnapshotDeletionPolicy

Should the following lines of code be followed that are acceptable for getting a hot backup of the lucene index or IndexWriter / SnapshotDeletionPolicy as described in the Lucene index backup ?

Directory dir = ...; IndexReader reader = IndexReader.open(dir); IndexCommit commit = reader.getIndexCommit(); Collection<String> fileNames = commit.getFileNames(); //copy the files reader.close(); 

Even with a locked index, you can open the reader at the commit point, while the writer can still change the index.

+7
source share
2 answers

If you don't have an IndexWriter pointer for the index, then the above code is fine.

But an open IndexWriter against the index can easily delete the files referenced / still used by this IndexReader (for example, when the merge is completed), and then your backup will fail.

+2
source

You need to use SnapshotDeletionPolicy.

If you have an unreleased picture, the writer will have the right to delete files at his discretion. This will only happen with a flush / close, so you can leave with it most of the time, but it will not always work.

Note that the policy belongs to the writer, so if you try to somehow use one process for backup and another write process, this will not work.

+1
source

All Articles