Commit 3c85013
committed
Mirror::createDocuments: re-fetch source after skipDuplicates insert
Addresses Greptile #3084293974. The captureOnNext-based forwarding
was structurally broken post-pre-filter-removal: SQL adapters return
the full input batch from createDocuments regardless of how many rows
INSERT IGNORE actually inserted, so onNext fired for every document
including skipped duplicates. captureOnNext buffered all of them and
flushed the full buffer (carrying the caller's would-be values) to
destination, diverging destination from source whenever source had a
pre-existing row the caller tried to overwrite.
Fix: instead of trying to distinguish inserted vs skipped at insert
time, re-fetch source's authoritative state via find() after the
adapter write settles, then forward that to destination. Race-free
regardless of concurrent writers — destination always receives a
faithful snapshot of whatever source holds, because the query runs
after source's write has resolved.
Cost: one extra SELECT per batch against source when skipDuplicates
is active AND Mirror has an upgraded destination. Zero cost on the
non-skip path. Memory remains O(batch_size).
Net ~47 lines smaller than the previous capture-based approach:
- captureOnNext closure removed
- flushBuffer closure removed
- bounded-buffer machinery removed
- shouldMirror upfront-snapshot removed (inlined as eligibility check)
Test: testCreateDocumentsSkipDuplicatesDoesNotDivergeDestination now
asserts destination holds source's 'Original' value rather than the
caller's 'WouldBe' input, per Greptile's suggested assertion.1 parent 9baaa04 commit 3c85013
2 files changed
Lines changed: 74 additions & 72 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
601 | 601 | | |
602 | 602 | | |
603 | 603 | | |
604 | | - | |
605 | 604 | | |
606 | | - | |
607 | | - | |
608 | | - | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
609 | 614 | | |
610 | | - | |
611 | | - | |
612 | | - | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
613 | 620 | | |
614 | 621 | | |
615 | | - | |
616 | | - | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
617 | 626 | | |
618 | | - | |
619 | | - | |
620 | | - | |
621 | | - | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
622 | 639 | | |
623 | 640 | | |
624 | | - | |
625 | | - | |
626 | | - | |
627 | | - | |
628 | | - | |
629 | | - | |
630 | | - | |
631 | | - | |
632 | | - | |
633 | | - | |
634 | | - | |
635 | | - | |
636 | | - | |
637 | | - | |
638 | | - | |
639 | | - | |
640 | | - | |
641 | | - | |
642 | | - | |
643 | | - | |
644 | | - | |
645 | | - | |
646 | | - | |
647 | | - | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
648 | 647 | | |
649 | | - | |
650 | | - | |
651 | | - | |
652 | | - | |
653 | | - | |
654 | | - | |
655 | | - | |
656 | | - | |
657 | | - | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
658 | 658 | | |
659 | | - | |
660 | | - | |
| 659 | + | |
661 | 660 | | |
662 | 661 | | |
663 | | - | |
664 | | - | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
665 | 671 | | |
666 | | - | |
667 | | - | |
668 | | - | |
669 | | - | |
670 | | - | |
671 | | - | |
672 | | - | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
673 | 681 | | |
674 | | - | |
675 | | - | |
676 | | - | |
677 | | - | |
678 | | - | |
679 | | - | |
680 | | - | |
681 | | - | |
682 | | - | |
683 | | - | |
684 | | - | |
685 | | - | |
686 | | - | |
687 | | - | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
688 | 685 | | |
689 | 686 | | |
690 | 687 | | |
691 | 688 | | |
692 | | - | |
693 | 689 | | |
694 | 690 | | |
695 | 691 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
378 | 378 | | |
379 | 379 | | |
380 | 380 | | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
381 | 387 | | |
382 | 388 | | |
383 | 389 | | |
| |||
0 commit comments