diwu-sf opened a new pull request, #17003:
URL: https://github.com/apache/lucene/pull/17003
### Description
With soft deletes, updating a document's soft deletes field to no value
undeletes it. If the document is hard deleted before that update is written,
the soft delete count goes negative. With assertions on this fails with
`illegal pending delete count: -1`. With assertions off, the next flush, commit
or NRT reopen throws `IllegalArgumentException: invalid softDelCount=-1
(maxDoc=2)`.
It needs only public APIs. With `maxBufferedDocs=2` and the soft deletes
field `soft_delete`:
1. Add two docs, `id:0` and `id:1`. They are flushed to a segment.
2. `updateDocValues(new Term("id", "0"), new
NumericDocValuesField("soft_delete", null))`. The doc is live, so this changes
nothing, but it buffers a doc values update.
3. Add two more docs. This auto flush resolves the update but does not write
it yet.
4. `deleteDocuments(new Term("id", "0"))`.
5. Open an NRT reader or commit. It fails.
The same happens with `IndexWriter#tryUpdateDocValue` with a null value on a
soft deleted doc, followed by a hard delete of that doc.
**Cause.** When a doc values update for the soft deletes field is written,
`PendingSoftDeletes#applySoftDeletes` handles a doc with no value by setting
its live bit and lowering the soft delete count. It does not check whether the
doc is hard deleted. The hard delete already cleared the live bit, so the doc
is counted twice and the count drops below zero.
**Fix.** `applySoftDeletes` now takes the hard live docs and only revives a
doc that is not hard deleted. `onDocValuesUpdate` and `onNewReader` pass the
hard live docs, and `SoftDeletesDirectoryReaderWrapper` passes `null`.
`onNewReader` and `SoftDeletesDirectoryReaderWrapper` pass a reader's doc
values iterator. That iterator only has docs with a value, so it never revives
a doc, and their behavior is unchanged.
**Interaction with #16996.** This fix relies on the hard live docs holding
only hard deletes. That is not true yet for a writer opened from an NRT reader:
on main, `PendingSoftDeletes` builds its hard deletes from the reader's live
docs, which also include the soft deletes. On such a writer,
`tryUpdateDocValue` with a null value would not undelete a soft deleted doc,
because the doc looks hard deleted. This path is already broken on main before
any undelete happens: opening the writer fails the soft delete count assertion,
and with assertions off the writer reports the wrong doc counts. #16996 fixes
the hard live docs on that path. With both changes, undeleting a soft deleted
doc on a writer opened from an NRT reader works and the committed counts are
correct. Whichever of the two PRs merges last should add a test for this: open
a writer from an NRT reader that has a soft deleted doc, undelete the doc with
`tryUpdateDocValue`, and check the reader's doc counts and the committed so
ft and hard delete counts.
**Tests.** `TestSoftDeletesRetentionMergePolicy#testUndeleteThenHardDelete`
covers the steps above. `testTryUndeleteThenHardDelete` does the same with
`tryUpdateDocValue`. Both check the reader's doc counts and the committed soft
and hard delete counts. Without the fix both failed 20 of 20 runs, with and
without assertions. With the fix both passed 100 of 100 runs.
`TestPendingSoftDeletes`, `TestSoftDeletesRetentionMergePolicy`,
`TestSoftDeletesDirectoryReaderWrapper` and the doc values update tests pass,
and `./gradlew :lucene:core:check` passes with Error Prone on.
--
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]