]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Improve timeout handling of pg_promote()
authorMichael Paquier <michael@paquier.xyz>
Thu, 26 Mar 2026 01:39:40 +0000 (10:39 +0900)
committerMichael Paquier <michael@paquier.xyz>
Thu, 26 Mar 2026 01:39:40 +0000 (10:39 +0900)
commit4287c50fc21e6d1c7798955020f8438ae2327472
tree0078b5cd356affb8b4b909d62414dc0df233da47
parente9d723487b262e8d2bb883e4f8e799c3774265c7
Improve timeout handling of pg_promote()

Previously, pg_promote() looped a fixed number of times, calculated from
the specified timeout, and waited 100ms on a latch, once per iteration,
for the promotion of a standby to complete.  However, unrelated signals
to the backend could set the latch and wake up the backend early,
resulting in a faster consumption of the loops and an execution time of
the function that does not match with the timeout input given in input.
This could be confusing for the function caller, especially if some
backend-side timeout is aggressive, because the function would return
much earlier than expected and report that the promote request has not
completed within the time requested.

This commit refines the logic to track the time actually elapsed, by
looping until the requested duration has truly passed.  The code
calculates the end time we expect, then uses it when looping.

Author: Robert Pang <robertpang@google.com>
Reviewed-by: Tiancheng Ge <getiancheng_2012@163.com>
Discussion: https://postgr.es/m/CAJhEC07OK8J7tLUbyiccnuOXRE7UKxBNqD2-pLfeFXa=tBoWtw@mail.gmail.com
src/backend/access/transam/xlogfuncs.c