pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alexander Korotkov <akorotkov@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Refactor WaitForLSNReplay() to return the result of waiting
Date: Thu, 24 Oct 2024 12:04:14 +0000
Message-ID: <E1t3wZa-002Dte-Oy@gemulon.postgresql.org> (raw)

Refactor WaitForLSNReplay() to return the result of waiting

Currently, WaitForLSNReplay() immediately throws an error if waiting for LSN
replay is not successful.  This commit teaches  WaitForLSNReplay() to return
the result of waiting, while making pg_wal_replay_wait() responsible for
throwing an appropriate error.

This is preparation to adding 'no_error' argument to pg_wal_replay_wait() and
new function pg_wal_replay_wait_status(), which returns the last wait result
status.

Additionally, we stop distinguishing situations when we find our instance to
be not in a recovery state before entering the waiting loop and inside
the waiting loop.  Standby promotion may happen at any moment, even between
issuing a procedure call statement and pg_wal_replay_wait() doing a first
check of recovery status.  Thus, there is no pointing distinguishing these
situations.

Also, since we may exit the waiting loop and see our instance not in recovery
without throwing an error, we need to deleteLSNWaiter() in that case. We do
this unconditionally for the sake of simplicity, even if standby was already
promoted after reaching the target LSN, the startup process surely already
deleted us.

Reported-by: Michael Paquier
Discussion: https://postgr.es/m/ZtUF17gF0pNpwZDI%40paquier.xyz
Reviewed-by: Michael Paquier, Pavel Borisov

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/73da6b8d1b3e8b7541961c3534e584243cb0470e

Modified Files
--------------
src/backend/access/transam/xlogfuncs.c | 31 ++++++++++++++++++++++++++++++-
src/backend/access/transam/xlogwait.c  | 33 +++++++++++----------------------
src/include/access/xlogwait.h          | 13 ++++++++++++-
src/tools/pgindent/typedefs.list       |  1 +
4 files changed, 54 insertions(+), 24 deletions(-)



Message-ID: <E1t3wZa-002Dte-Oy@gemulon.postgresql.org>
Permalink:  ../E1t3wZa-002Dte-Oy@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1t3wZa-002Dte-Oy@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: akorotkov@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Refactor WaitForLSNReplay() to return the result of waiting
  In-Reply-To: <E1t3wZa-002Dte-Oy@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox