forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit788baa9
committed
Fix crash in brininsertcleanup during logical replication.
Logical replication crashes if the subscriber's partitioned tablehas a BRIN index. There are two independently blamable causes,and this patch fixes both:1. brininsertcleanup fails if called twice for the same IndexInfo,because it half-destroys its BrinInsertState but leaves it stilllinked from ii_AmCache. brininsert would also fail in that state,so it's pretty hard to see any advantage to this coding. Fullyremove the BrinInsertState, instead, so that a new brininsertcall would create a new cache.2. A logical replication subscriber sometimes does ExecOpenIndicestwice on the same ResultRelInfo, followed by doing ExecCloseIndicestwice; the second call reaches the brininsertcleanup bug. Quiteaside from tickling unexpected cases in aminsertcleanup methods,this seems very wasteful, because the IndexInfos built in thefirst ExecOpenIndices call are just lost during the second call,and have to be rebuilt at possibly-nontrivial cost. We shouldestablish a coding rule that you don't do that.The problematic coding is that when the target table is partitioned,apply_handle_tuple_routing calls ExecFindPartition which doesExecOpenIndices (and expects that ExecCleanupTupleRouting willclose the indexes again). Using the ResultRelInfo made byExecFindPartition, it calls apply_handle_delete_internal orapply_handle_insert_internal, both of which think they need to doExecOpenIndices/ExecCloseIndices for themselves. They do in the mainnon-partitioned code paths, but not here. The simplest fix is to pulltheir ExecOpenIndices/ExecCloseIndices calls out and put them in thecall sites for the non-partitioned cases. (We could have refactoredapply_handle_update_internal similarly, but I did not do so todaybecause there's no bug there: the partitioned code path doesn'tcall it.)Also, remove the always-duplicative open/close calls withinapply_handle_tuple_routing itself.Since brininsertcleanup and indeed the whole aminsertcleanup mechanismare new in v17, there's no observable bug in older branches. A casecould be made for trying to avoid these duplicative open/close callsin the older branches, but for now it seems not worth the trouble andrisk of new bugs.Bug: #18815Reported-by: Sergey Belyashov <sergey.belyashov@gmail.com>Discussion:https://postgr.es/m/18815-2a0407cc7f40b327@postgresql.orgBackpatch-through: 171 parentf61769a commit788baa9
File tree
3 files changed
+32
-15
lines changed- src
- backend
- access/brin
- replication/logical
- test/subscription/t
3 files changed
+32
-15
lines changedLines changed: 5 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
505 | 505 |
| |
506 | 506 |
| |
507 | 507 |
| |
508 |
| - | |
| 508 | + | |
509 | 509 |
| |
510 | 510 |
| |
| 511 | + | |
| 512 | + | |
| 513 | + | |
511 | 514 |
| |
512 | 515 |
| |
513 | 516 |
| |
514 | 517 |
| |
515 | 518 |
| |
516 |
| - | |
517 |
| - | |
| 519 | + | |
518 | 520 |
| |
519 | 521 |
| |
520 | 522 |
| |
|
Lines changed: 23 additions & 12 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2432 | 2432 |
| |
2433 | 2433 |
| |
2434 | 2434 |
| |
2435 |
| - | |
2436 |
| - | |
| 2435 | + | |
| 2436 | + | |
| 2437 | + | |
| 2438 | + | |
| 2439 | + | |
| 2440 | + | |
| 2441 | + | |
2437 | 2442 |
| |
2438 | 2443 |
| |
2439 | 2444 |
| |
| |||
2460 | 2465 |
| |
2461 | 2466 |
| |
2462 | 2467 |
| |
2463 |
| - | |
2464 |
| - | |
| 2468 | + | |
| 2469 | + | |
| 2470 | + | |
| 2471 | + | |
2465 | 2472 |
| |
2466 | 2473 |
| |
2467 | 2474 |
| |
2468 | 2475 |
| |
2469 |
| - | |
2470 |
| - | |
2471 |
| - | |
2472 | 2476 |
| |
2473 | 2477 |
| |
2474 | 2478 |
| |
| |||
2767 | 2771 |
| |
2768 | 2772 |
| |
2769 | 2773 |
| |
2770 |
| - | |
| 2774 | + | |
| 2775 | + | |
| 2776 | + | |
| 2777 | + | |
| 2778 | + | |
2771 | 2779 |
| |
| 2780 | + | |
| 2781 | + | |
2772 | 2782 |
| |
2773 | 2783 |
| |
2774 | 2784 |
| |
| |||
2802 | 2812 |
| |
2803 | 2813 |
| |
2804 | 2814 |
| |
2805 |
| - | |
| 2815 | + | |
| 2816 | + | |
| 2817 | + | |
| 2818 | + | |
| 2819 | + | |
2806 | 2820 |
| |
2807 | 2821 |
| |
2808 | 2822 |
| |
| |||
2831 | 2845 |
| |
2832 | 2846 |
| |
2833 | 2847 |
| |
2834 |
| - | |
2835 | 2848 |
| |
2836 | 2849 |
| |
2837 | 2850 |
| |
| |||
3042 | 3055 |
| |
3043 | 3056 |
| |
3044 | 3057 |
| |
3045 |
| - | |
3046 | 3058 |
| |
3047 | 3059 |
| |
3048 | 3060 |
| |
3049 | 3061 |
| |
3050 | 3062 |
| |
3051 | 3063 |
| |
3052 |
| - | |
3053 | 3064 |
| |
3054 | 3065 |
| |
3055 | 3066 |
| |
|
Lines changed: 4 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
49 | 49 |
| |
50 | 50 |
| |
51 | 51 |
| |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
52 | 56 |
| |
53 | 57 |
| |
54 | 58 |
| |
|
0 commit comments
Comments
(0)