Web / Apache Lucene Interview questions
Explain the lifecycle of an IndexWriter commit?
A commit is what makes indexing changes durable and visible to newly opened readers. Understanding the stages helps explain why a commit is more expensive than a plain flush.
- Documents are buffered in memory as they're added.
- A flush writes the buffered documents to disk as a new segment, but this alone isn't durable or guaranteed visible.
- commit() fsyncs all relevant files and writes a new
segments_Nfile pointing to the current set of segments - this is the actual durable commit point. - Only after commit (or via a SearcherManager refresh for NRT) do new readers see the changes.
Because fsync is relatively expensive, applications batch many documents between commits rather than committing after every single add.
More Related questions...