postgresql/src/backend/replication/logical
Amit Kapila db08e8c6fa Post-commit review fixes for slot synchronization.
Allow pg_sync_replication_slots() to error out during promotion of standby.
This makes the behavior of the SQL function consistent with the slot sync
worker. We also ensured that pg_sync_replication_slots() cannot be
executed if sync_replication_slots is enabled and the slotsync worker is
already running to perform the synchronization of slots. Previously, it
would have succeeded in cases when the worker is idle and failed when it
is performing sync which could confuse users.

This patch fixes another issue in the slot sync worker where
SignalHandlerForShutdownRequest() needs to be registered *before* setting
SlotSyncCtx->pid, otherwise, the slotsync worker could miss handling
SIGINT sent by the startup process(ShutDownSlotSync) if it is sent before
worker could register SignalHandlerForShutdownRequest(). To be consistent,
all signal handlers' registration is moved to a prior location before we
set the worker's pid.

Ensure that we clean up synced temp slots at the end of
pg_sync_replication_slots() to avoid such slots being left over after
promotion.

Ensure that ShutDownSlotSync() captures SlotSyncCtx->pid under spinlock to
avoid accessing invalid value as it can be reset by concurrent slot sync
exit due to an error.

Author: Shveta Malik
Reviewed-by: Hou Zhijie, Bertrand Drouvot, Amit Kapila, Masahiko Sawada
Discussion: https://postgr.es/m/CAJpy0uBefXUS_TSz=oxmYKHdg-fhxUT0qfjASW3nmqnzVC3p6A@mail.gmail.com
2024-04-25 14:01:44 +05:30
..
Makefile Add a slot synchronization function. 2024-02-14 09:45:36 +05:30
applyparallelworker.c Replace BackendIds with 0-based ProcNumbers 2024-03-03 19:38:22 +02:00
decode.c Merge prune, freeze and vacuum WAL record formats 2024-03-25 14:59:58 +02:00
launcher.c Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
logical.c Ensure that the sync slots reach a consistent state after promotion without losing data. 2024-04-03 14:04:59 +05:30
logicalfuncs.c Introduce a new GUC 'standby_slot_names'. 2024-03-08 08:10:45 +05:30
meson.build Add a slot synchronization function. 2024-02-14 09:45:36 +05:30
message.c Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
origin.c Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
proto.c Remove unused 'countincludesself' argument to pq_sendcountedtext() 2024-03-04 12:56:05 +02:00
relation.c Admit deferrable PKs into rd_pkindex, but flag them as such 2024-03-08 16:32:29 +01:00
reorderbuffer.c Revert indexed and enlargable binary heap implementation. 2024-04-11 17:18:05 +09:00
slotsync.c Post-commit review fixes for slot synchronization. 2024-04-25 14:01:44 +05:30
snapbuild.c Ensure that the sync slots reach a consistent state after promotion without losing data. 2024-04-03 14:04:59 +05:30
tablesync.c Fix the missing table sync due to improper invalidation handling. 2024-04-25 10:40:52 +05:30
worker.c Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00