pgsql: Fix crash decoding a change to a partition pending detach.

Started by Amit Kapila17 days ago1 messagescommitters
Jump to latest
#1Amit Kapila
akapila@postgresql.org

Fix crash decoding a change to a partition pending detach.

ALTER TABLE ... DETACH PARTITION ... CONCURRENTLY leaves the partition
marked as detach-pending if its wait is interrupted by a lock timeout, a
cancel, a disconnect. Only DETACH PARTITION ... FINALIZE clears that mark.
In that state pg_class still says relispartition, while
get_partition_ancestors() already reports nothing which
get_rel_sync_entry() was not ready for. It read relispartition as meaning
that the ancestor list is not empty, and asked for its last element, which
is an assertion failure, and a NULL pointer dereference without
assertions. Decoding any change to such a partition for a FOR ALL TABLES
publication gets there, and as the change is never confirmed, a
subscription turns that into a crash loop.

Fetch the ancestors once, up front, and treat a partition with no
ancestors as a standalone table, which is how it is published once the
detach completes.

The crash is reachable since v14 (71f4c8c6f74b) for FOR ALL TABLES
publications with publish_via_partition_root, and since v19
(fd366065e06a) for any FOR ALL TABLES publication.

Author: Mikhail Nikalayeu <mihailnikalayeu@gmail.com>
Author: Zhijie Hou <houzhijie22@gmail.com>
Reviewed-by: shveta malik <shveta.malik@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Reviewed-by: Nisha Moond <nisha.moond412@gmail.com>
Discussion: /messages/by-id/CADzfLwWoFPT+a73=A=bsNWRMZQ98NpBEMgE=t1FS4O4_=QVLfA@mail.gmail.com
Discussion: /messages/by-id/CABdArM64ZSat=dB094U8OCBzp1m8_Y85m6T+xPEgpLVJb60_rA@mail.gmail.com
Backpatch-through: 15

Branch
------
REL_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/1b72026d4143b55511d7fc15508819d3d750aa62

Modified Files
--------------
.../test_decoding/expected/concurrent_ddl_dml.out | 38 ++++++++++++++++++++++
.../test_decoding/specs/concurrent_ddl_dml.spec | 17 ++++++++++
src/backend/catalog/partition.c | 5 +++
src/backend/replication/pgoutput/pgoutput.c | 20 ++++++++----
4 files changed, 74 insertions(+), 6 deletions(-)