diwu-sf opened a new pull request, #16996:
URL: https://github.com/apache/lucene/pull/16996

   ### Description
   
   A writer can be opened on an NRT reader's commit, with 
`IndexWriterConfig#setIndexCommit(reader.getIndexCommit())`. With hard deletes, 
the new writer starts with exactly the documents the reader saw. Deletes that 
weren't written yet are carried over, and the next commit writes them. Soft 
deletes should work the same way, but they didn't: the new writer got its 
delete counts wrong. With assertions on, opening the writer failed with 
`softDeleteCount doesn't match 1 != 0`. With assertions off, the writer 
reported wrong document counts: in the new test, `getDocStats().numDocs` was -3 
instead of 4.
   
   **Cause.** For hard deletes, the new writer starts from the reader's live 
docs. `PendingSoftDeletes(field, reader, info)` did the same for soft deletes, 
but an NRT reader's live docs already include its soft deletes. So:
   1. `onNewReader` applied the soft deletes from the doc values a second time. 
`applySoftDeletes` only counts documents it newly deletes, so it counted 0, 
while the segment info counts them.
   2. The hard deletes started from the same live docs, so the soft deletes 
were also counted as pending hard deletes.
   
   **Fix.** Soft deletes now start the same way as hard deletes: the writer 
keeps the reader's live docs, and takes the hard deletes from 
`reader.getHardLiveDocs()`. It doesn't apply the soft deletes again, because an 
NRT reader only sees soft deletes that are already written: `getReader` writes 
all doc values updates first.
   
   **Tests.** `TestIndexWriterFromReader#testSoftDeletes` covers a soft update 
that was written to disk, a document that is soft deleted when it is added, 
hard deletes that aren't written yet, and a hard delete of a soft deleted 
document. It checks that the new writer, its first reader, its commit, and a 
merge all have the documents the NRT reader saw. It fails without the fix, with 
and without assertions. We found this bug while adding soft deletes to the 
randomized `TestIndexVersionInvariants` in #16923, which skips this case for 
now. With this fix and that skip removed, the test passed 700 runs. `./gradlew 
:lucene:core:check` passes.
   
   Related: #9431 hit the same assertion when the writer reopened a segment 
reader with its latest live docs. This is a different code path: a writer 
opened from an NRT reader.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to