I think it is correct to say that "if the result of ir.numDeletedDocs() is N, then calling ir.undeleteAll() will undelete exactly N documents"... or am I missing it?
Because if a merge was invoked for the segments seen by this reader, I see two options:
- A merge is on going, or the merge is done but uncommitted yet.
This means that an index writer has a lock on the index, hence ir.undeleteAll() will fail to get the lock.
- The merge was already committed.
This means that the index reader will fail to get write permission for being Stale.
So I think this method behaves deterministically - perhaps its jdoc should say something like:
Undeletes all #numDeletedDocs() documents currently marked as deleted in this index. ?