Commit 3a483f2
committed
Mirror: forward only docs the source actually inserted
Previously Mirror::createDocuments built its destination payload from
the original input ($documents), not from the docs the source actually
persisted. In skipDuplicates mode that lets the destination diverge from
the source whenever the source no-ops a write:
source has id=a, name='Original'
dest missing id=a
caller skipDuplicates(createDocuments([{id: a, name: 'Duplicate'}]))
The source skips a (already present) but the Mirror still forwards
{id: a, name: 'Duplicate'} to the destination, which inserts it — the
two replicas now hold different values for the same row.
The same code path also throws "All documents must have an sequence if
one is set" inside Database::createDocuments when a partially-skipped
batch reaches the destination, because the inserted doc has a sequence
assigned by the source adapter while the skipped doc does not. Mirror
catches and silently logs that exception, so the destination ends up
missing both rows.
Fix: wrap the user's onNext to capture the docs the source actually
persisted, then forward only those to the destination. Skipped docs
are now correctly never mirrored.
Adds testCreateDocumentsSkipDuplicatesDoesNotDivergeDestination —
seeds a row in the source only (bypassing the mirror), then calls
skipDuplicates(createDocuments(...)) with a different value for that
id plus a new row. Asserts source keeps its original value, destination
ends up with only the new row, and the skipped value never reaches
either side.1 parent 3b783af commit 3a483f2
2 files changed
Lines changed: 109 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
601 | 601 | | |
602 | 602 | | |
603 | 603 | | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
604 | 617 | | |
605 | 618 | | |
606 | 619 | | |
607 | 620 | | |
608 | 621 | | |
609 | | - | |
| 622 | + | |
610 | 623 | | |
611 | 624 | | |
612 | 625 | | |
| |||
624 | 637 | | |
625 | 638 | | |
626 | 639 | | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
627 | 645 | | |
628 | 646 | | |
629 | 647 | | |
630 | | - | |
| 648 | + | |
631 | 649 | | |
632 | 650 | | |
633 | 651 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
313 | 313 | | |
314 | 314 | | |
315 | 315 | | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
316 | 405 | | |
317 | 406 | | |
318 | 407 | | |
| |||
0 commit comments