Commit 6c5068a
authored
fix: Resolve pending shapes in FlushTracker when consumer process receives commit fragment with no relevant changes (#4064)
## Summary
Fix #4063
When a `{Storage, :flushed, offset}` message arrives at a Consumer
process while it's in the middle of processing a multi-fragment
transaction, the flush notification could be lost. This caused the
FlushTracker in ShapeLogCollector to get stuck waiting for a flush that
was already completed.
### Changes
**Consumer (`consumer.ex`, `consumer/state.ex`):**
- Defer flush notifications that arrive during a pending transaction by
storing the max flushed offset in `pending_flush_offset`
- Process deferred flush notifications when the pending transaction
completes (commit, skip, or no relevant changes)
**FlushTracker (`flush_tracker.ex`):**
- Simplify to commit-only tracking: remove non-commit fragment handling
since Consumer now defers flush notifications during pending
transactions
- Remove `shapes_with_changes` parameter from `handle_txn_fragment/3` —
all affected shapes are tracked uniformly at commit time
**ShapeLogCollector (`shape_log_collector.ex`):**
- Only call `FlushTracker.handle_txn_fragment/3` on commit fragments
- Remove `shapes_with_changes` computation that is no longer needed
## Test plan
- [x] New regression test for stuck flush tracker scenario
- [x] Stricter assertions in EventRouterTest for txn fragment reslicing
- [x] Updated Consumer tests for deferred flush notification behavior
- [x] Existing test suite passes1 parent 64a89a0 commit 6c5068a
8 files changed
Lines changed: 330 additions & 291 deletions
File tree
- .changeset
- packages/sync-service
- lib/electric
- replication
- shape_log_collector
- shapes
- consumer
- test/electric
- replication/shape_log_collector
- shapes
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
Lines changed: 11 additions & 27 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
465 | 465 | | |
466 | 466 | | |
467 | 467 | | |
468 | | - | |
469 | | - | |
470 | | - | |
471 | | - | |
472 | | - | |
473 | | - | |
474 | | - | |
475 | | - | |
476 | | - | |
477 | | - | |
478 | | - | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
479 | 476 | | |
480 | 477 | | |
481 | 478 | | |
| |||
578 | 575 | | |
579 | 576 | | |
580 | 577 | | |
581 | | - | |
582 | | - | |
583 | | - | |
584 | | - | |
585 | | - | |
586 | | - | |
587 | | - | |
588 | | - | |
589 | | - | |
590 | | - | |
591 | | - | |
592 | | - | |
593 | | - | |
594 | | - | |
595 | | - | |
596 | | - | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
597 | 581 | | |
598 | 582 | | |
599 | 583 | | |
| |||
Lines changed: 5 additions & 38 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
| 98 | + | |
116 | 99 | | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
| 100 | + | |
121 | 101 | | |
122 | 102 | | |
123 | 103 | | |
124 | | - | |
125 | | - | |
| 104 | + | |
126 | 105 | | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
| 106 | + | |
133 | 107 | | |
134 | 108 | | |
135 | 109 | | |
| |||
211 | 185 | | |
212 | 186 | | |
213 | 187 | | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
| 188 | + | |
222 | 189 | | |
223 | 190 | | |
224 | 191 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
270 | 270 | | |
271 | 271 | | |
272 | 272 | | |
273 | | - | |
274 | | - | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
275 | 286 | | |
276 | | - | |
277 | 287 | | |
278 | 288 | | |
279 | 289 | | |
| |||
567 | 577 | | |
568 | 578 | | |
569 | 579 | | |
570 | | - | |
| 580 | + | |
571 | 581 | | |
572 | 582 | | |
573 | 583 | | |
| |||
597 | 607 | | |
598 | 608 | | |
599 | 609 | | |
| 610 | + | |
600 | 611 | | |
601 | 612 | | |
602 | 613 | | |
| |||
747 | 758 | | |
748 | 759 | | |
749 | 760 | | |
750 | | - | |
751 | | - | |
| 761 | + | |
| 762 | + | |
752 | 763 | | |
| 764 | + | |
753 | 765 | | |
754 | 766 | | |
755 | 767 | | |
| |||
1006 | 1018 | | |
1007 | 1019 | | |
1008 | 1020 | | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
1009 | 1046 | | |
1010 | 1047 | | |
1011 | 1048 | | |
| |||
Lines changed: 7 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
46 | 50 | | |
47 | 51 | | |
48 | 52 | | |
| |||
393 | 397 | | |
394 | 398 | | |
395 | 399 | | |
396 | | - | |
397 | | - | |
| 400 | + | |
| 401 | + | |
398 | 402 | | |
0 commit comments