Commit c37e5c6
[OPIK-7891] [BE] fix: count distinct item ids when sizing a dataset version
insertItems returned items.size() -- the raw list length, deliberately
not a DB row count, because ClickHouse async inserts report 0 rows
before commit. Reads collapse a repeated dataset_item_id to one row via
LIMIT 1 BY, so a stable id appearing twice in one batch made the version
total one higher than the rows the version actually holds.
Every version total flows through this value: createFirstVersion feeds it
straight to itemsTotal, and applyDelta sums added + edited + copied. So
the fix belongs at the source -- count distinct stable ids, matching what
the storage engine keeps.
This corrects the mechanism recorded on the ticket. The reported cause
was asynchronous ClickHouse visibility racing concurrent batches on the
append path; it is neither a race nor on the append path. One
single-threaded request reproduces it, and the appending path already
classifies a cross-batch duplicate correctly via countExistingItemIds --
verified by a test that passes with and without this change. num_threads
was a red herring: the SDK's content-hash dedup drops same-content
duplicates before batching, so a duplicate id only survives into a
request when the content differs.
Tests cover both shapes: a duplicate inside the version-creating batch
(fails without this fix) and a duplicate spanning two batches in one
batch_group_id (passes either way, pinning the append path's behaviour).
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent 7ad36cf commit c37e5c6
2 files changed
Lines changed: 99 additions & 1 deletion
File tree
- apps/opik-backend/src
- main/java/com/comet/opik/domain
- test/java/com/comet/opik/api/resources/v1/priv
Lines changed: 9 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3499 | 3499 | | |
3500 | 3500 | | |
3501 | 3501 | | |
3502 | | - | |
| 3502 | + | |
| 3503 | + | |
| 3504 | + | |
| 3505 | + | |
| 3506 | + | |
| 3507 | + | |
| 3508 | + | |
| 3509 | + | |
| 3510 | + | |
3503 | 3511 | | |
3504 | 3512 | | |
3505 | 3513 | | |
| |||
Lines changed: 90 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3557 | 3557 | | |
3558 | 3558 | | |
3559 | 3559 | | |
| 3560 | + | |
| 3561 | + | |
| 3562 | + | |
| 3563 | + | |
| 3564 | + | |
| 3565 | + | |
| 3566 | + | |
| 3567 | + | |
| 3568 | + | |
| 3569 | + | |
| 3570 | + | |
| 3571 | + | |
| 3572 | + | |
| 3573 | + | |
| 3574 | + | |
| 3575 | + | |
| 3576 | + | |
| 3577 | + | |
| 3578 | + | |
| 3579 | + | |
| 3580 | + | |
| 3581 | + | |
| 3582 | + | |
| 3583 | + | |
| 3584 | + | |
| 3585 | + | |
| 3586 | + | |
| 3587 | + | |
| 3588 | + | |
| 3589 | + | |
| 3590 | + | |
| 3591 | + | |
| 3592 | + | |
| 3593 | + | |
| 3594 | + | |
| 3595 | + | |
| 3596 | + | |
| 3597 | + | |
| 3598 | + | |
| 3599 | + | |
| 3600 | + | |
| 3601 | + | |
| 3602 | + | |
| 3603 | + | |
| 3604 | + | |
| 3605 | + | |
| 3606 | + | |
| 3607 | + | |
| 3608 | + | |
| 3609 | + | |
| 3610 | + | |
| 3611 | + | |
| 3612 | + | |
| 3613 | + | |
| 3614 | + | |
| 3615 | + | |
| 3616 | + | |
| 3617 | + | |
| 3618 | + | |
| 3619 | + | |
| 3620 | + | |
| 3621 | + | |
| 3622 | + | |
| 3623 | + | |
| 3624 | + | |
| 3625 | + | |
| 3626 | + | |
| 3627 | + | |
| 3628 | + | |
| 3629 | + | |
| 3630 | + | |
| 3631 | + | |
| 3632 | + | |
| 3633 | + | |
| 3634 | + | |
| 3635 | + | |
| 3636 | + | |
| 3637 | + | |
| 3638 | + | |
| 3639 | + | |
| 3640 | + | |
| 3641 | + | |
| 3642 | + | |
| 3643 | + | |
| 3644 | + | |
| 3645 | + | |
| 3646 | + | |
| 3647 | + | |
| 3648 | + | |
| 3649 | + | |
3560 | 3650 | | |
3561 | 3651 | | |
3562 | 3652 | | |
| |||
0 commit comments