KKcorps commented on PR #20321:
URL: https://github.com/apache/pinot/pull/20321#issuecomment-7034185950
This comes from a model of upsert thread orders that StarTree runs on upsert
PRs.
**The rollback fixes the leak a failed replace causes today, where moved
keys stay on a copy no query reads. The model found two orders it still misses,
and today's code also serves wrong rows in both, so neither is a regression.**
I replayed the model's 124 known bad orders with and without the change, and
none changed, because none has a failed replace. Then a 61 minute search, 560
runs over 15 table shapes, made replaces throw partway on both versions.
**A key removed during the rollback keeps its old doc.** Under NONE,
`revertReplacedKeys` invalidates the old doc inside `computeIfPresent`, so
nothing runs when the key is gone. Here the next consumer takes A and is
offloaded first, and a deletedKeysTTL cleanup or a second failed replace can
remove A the same way. The old segment then serves a stale A, and the next A
adds a duplicate. Invalidating the old doc when the key is absent would close
it.
```mermaid
sequenceDiagram
participant R as Commit N0
participant C as Consumer N1
participant M as Upsert metadata
R->>M: A moves to the N0 copy, the N0 consuming bitmap is kept
R->>R: replaceSegment throws
C->>M: addRecord(A), A points at N1
C->>M: offload N1, removeSegment drops A
R->>M: revertReplacedKeys(A), key absent, nothing runs
Note over M: the old N0 doc for A stays valid with no key, so queries
see a stale A
```
<details><summary>Model history</summary>
```
assign_consumer N0', acquire N0', append A@0, append A@1, consume N0' A@0
commit_local N0' at 0, release the slot early, assign_consumer N1'
replace N0': start, add A@0
acquire N1', fail_replace N0', offload N1' queued, consume N1' A@1
replace N0': revert_failed_replace
offload N1': stop, close_consumer, begin_remove, remove A
replace N0': revert_replaced A, remove_added, restore_old_segment
```
</details>
**A revert can put a key back on the copy after the rollback's snapshot.**
On a partial upsert table, the previous location of A can be the new copy. If
the consumer holding A is offloaded during the rollback, its revert restores A
into the copy after `revertFailedReplace` read the copy's valid docs. The copy
is released with A still pointing at it, so the next merge on A reads a
destroyed segment. This needs a consumer that read past its end offset, so it
is rarer.
```mermaid
sequenceDiagram
participant O as Offload N0
participant R as Replace N1
participant M as Upsert metadata
R->>M: A from the N1 copy loses to the newer A in N0
M->>M: previous location of A is the N1 copy
R->>R: replaceSegment throws
R->>M: snapshot of N1 valid docs is empty
O->>M: revertAndRemoveSegment(N0) restores A into the N1 copy
R->>R: removeSegment walks the empty snapshot, then releaseSegment(N1)
Note over M: A points at a destroyed segment
```
<details><summary>Model history</summary>
```
assign_consumer N0', acquire N0', append A@0, append A@1, offload N0' queued
consume N0' A@0, append A@2 with a larger comparison value, consume N0' A@1
commit_remote N0 at 0, assign_consumer N1', commit_remote N1 at 1,
observe_commit N1' (download)
consume N0' A@2, offload N0': stop, close_consumer, begin_remove
replace N1': start, add A@1 (loses, previous location of A is now N1)
fail_replace N1', offload N0': revert A begins
replace N1': revert_failed_replace, remove_added (empty)
offload N0': restore A into N1, replace N1': restore_old_segment
```
</details>
The model covers one replica and the ConcurrentMap manager on one partition,
and it does not throw inside a purge, a refresh or the leftover removal.
<!-- upsert-model-check head=12f6b233e35682e5f4b3225954931c7d43b07a0d -->
--
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]