Doris-Breakwater commented on issue #70873:
URL: https://github.com/apache/doris/issues/70873#issuecomment-7095001198

   Breakwater-GitHub-Analysis-Slot: slot_eafc23d81a16
   
   **Triage — Unique Key merge-on-write correctness.** The attached output 
shows two visible rows for `id=1` after C publishes, then only `(1, NULL, NULL, 
20)` after cumulative compaction, with no intervening writes. The duplicate 
already exists before compaction. The table should expose one row per key and 
preserve the query result across compaction. I reviewed the attached DDL, exact 
2PC requests, visibility checks, reported results from all three replicas, and 
the source at `7126cf65d96`. Runtime observations come from the reporter’s run. 
[Reproducer and observed 
output](https://github.com/user-attachments/files/35264900/doris-partial-update-repro.zip)
   
   **Verified in the source**
   
   - A lower explicit sequence can be written into a physical rowset with its 
row marked in the delete bitmap, which explains how D can exist in storage 
while only A is visible. At publish, `BaseTablet::update_delete_bitmap` checks 
rowsets added since the load’s snapshot, newest version first. [Flush-time 
bitmap 
marking](https://github.com/apache/doris/blob/7126cf65d96ebc43fce0906f51e92c1a2ccf24a6/be/src/storage/segment/vertical_segment_writer.cpp#L409-L470)
 · [Rowset 
order](https://github.com/apache/doris/blob/7126cf65d96ebc43fce0906f51e92c1a2ccf24a6/be/src/storage/tablet/base_tablet.cpp#L484-L497)
 · [Publish-time rowset 
selection](https://github.com/apache/doris/blob/7126cf65d96ebc43fce0906f51e92c1a2ccf24a6/be/src/storage/tablet/base_tablet.cpp#L1538-L1562)
   - `calc_segment_delete_bitmap` probes using the encoded sequence in the 
prepared segment. `Segment::lookup_row_key` can return `KEY_ALREADY_EXISTS` for 
a physical match with a higher sequence. `BaseTablet::lookup_row_key` checks 
visibility in the delete bitmap only on `OK`, so it can return a bitmap-deleted 
match before reaching an older, visible rowset. Flexible alignment uses the 
skip bitmap to fill omitted columns, including the sequence, from the returned 
row. [Publish 
probe](https://github.com/apache/doris/blob/7126cf65d96ebc43fce0906f51e92c1a2ccf24a6/be/src/storage/tablet/base_tablet.cpp#L788-L798)
 · [Sequence 
comparison](https://github.com/apache/doris/blob/7126cf65d96ebc43fce0906f51e92c1a2ccf24a6/be/src/storage/segment/segment.cpp#L909-L925)
 · [Visibility 
guard](https://github.com/apache/doris/blob/7126cf65d96ebc43fce0906f51e92c1a2ccf24a6/be/src/storage/tablet/base_tablet.cpp#L596-L624)
 · [Flexible 
alignment](https://github.com/apache/doris/blob/7126cf65d96ebc43fce0906f
 51e92c1a2ccf24a6/be/src/storage/tablet/base_tablet.cpp#L1285-L1334)
   - The `OK`-only guard is also present in the inspected upstream `branch-4.1` 
and `master` revisions. Reproduction on those builds is still pending. 
[branch-4.1](https://github.com/apache/doris/blob/91e2204ae4605a4537c7290b2d75107bc88fdb6c/be/src/storage/tablet/base_tablet.cpp#L611-L639)
 · 
[master](https://github.com/apache/doris/blob/3dcb76856be63e3a10c422177a672b31581ce5b4/be/src/storage/tablet/base_tablet.cpp#L628-L653)
   
   **Likely execution path.** B was prepared while the key was absent. If its 
publish probe returns `KEY_ALREADY_EXISTS` against bitmap-deleted D (`seq=10`), 
B can inherit `10` and leave A (`seq=20`) visible, since the alignment marks 
only the returned prior row and B’s prepared row for deletion. C can then align 
against B’s newly visible row, preserving `blue` and adding `sample` at 
sequence `10`. Normal merge-on-write scans rely on the delete bitmap for 
visibility. If A and C’s aligned row are both inputs to the cumulative merge, 
the same-key sequence comparison explains why only the `20` row survives. The 
selected publish row locations and compaction input range would confirm this 
chain. [Alignment bitmap 
writes](https://github.com/apache/doris/blob/7126cf65d96ebc43fce0906f51e92c1a2ccf24a6/be/src/storage/tablet/base_tablet.cpp#L832-L874)
 · [Scan bitmap 
handling](https://github.com/apache/doris/blob/7126cf65d96ebc43fce0906f51e92c1a2ccf24a6/be/src/storage/rowset/beta_rowset_r
 eader.cpp#L172-L188) · [Compaction sequence 
ordering](https://github.com/apache/doris/blob/7126cf65d96ebc43fce0906f51e92c1a2ccf24a6/be/src/storage/iterator/vertical_merge_iterator.cpp#L297-L318)
   
   **Next steps**
   
   1. On the next run, capture one replica’s tablet ID, A/D/B/C transaction IDs 
and published versions, the query result immediately after B, and 
`/api/compaction/show` before and after the merge. Include matching BE publish 
and compaction log lines. The decisive trace on B’s publish is the selected 
rowset/segment/row ID, the lookup status, and whether that location is already 
in the tablet delete bitmap at B’s lookup version. Trace C’s source row the 
same way. The hypothesis predicts B selects D despite that bitmap entry, and C 
selects B’s aligned row.
   2. Re-run the attached case on current `branch-4.1` or `master`. Use the 
existing flexible sequence publish suite as a starting point for a regression 
case that includes D’s bitmap-deleted row. Assert one row after D, `(1, blue, 
NULL, 20)` after B, and `(1, blue, sample, 20)` after C and after compaction. 
If the trace confirms the hypothesis, make the publish probe validate candidate 
visibility before acting on the sequence result. Cover an explicitly supplied 
lower sequence against a **visible** higher-sequence row to preserve that 
rejection behavior. [Existing regression 
suite](https://github.com/apache/doris/blob/7126cf65d96ebc43fce0906f51e92c1a2ccf24a6/regression-test/suites/unique_with_mow_p0/flexible/publish/test_fleixble_partial_update_publish_conflict_seq.groovy)
   


-- 
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