pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Amit Kapila <akapila@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Ensure that the sync slots reach a consistent state after promot
Date: Wed, 03 Apr 2024 08:49:20 +0000
Message-ID: <E1rrwJ6-000GHX-0a@gemulon.postgresql.org> (raw)

Ensure that the sync slots reach a consistent state after promotion without losing data.

We were directly copying the LSN locations while syncing the slots on the
standby. Now, it is possible that at some particular restart_lsn there are
some running xacts, which means if we start reading the WAL from that
location after promotion, we won't reach a consistent snapshot state at
that point. However, on the primary, we would have already been in a
consistent snapshot state at that restart_lsn so we would have just
serialized the existing snapshot.

To avoid this problem we will use the advance_slot functionality unless
the snapshot already exists at the synced restart_lsn location. This will
help us to ensure that snapbuilder/slot statuses are updated properly
without generating any changes. Note that the synced slot will remain as
RS_TEMPORARY till the decoding from corresponding restart_lsn can reach a
consistent snapshot state after which they will be marked as
RS_PERSISTENT.

Per buildfarm

Author: Hou Zhijie
Reviewed-by: Bertrand Drouvot, Shveta Malik, Bharath Rupireddy, Amit Kapila
Discussion: https://postgr.es/m/OS0PR01MB5716B3942AE49F3F725ACA92943B2@OS0PR01MB5716.jpnprd01.prod.outlook.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/2ec005b4e29740f0d36e6646d149af192328b2ff

Modified Files
--------------
src/backend/replication/logical/logical.c          | 147 ++++++++++++++++++++-
src/backend/replication/logical/slotsync.c         | 133 +++++++++++++------
src/backend/replication/logical/snapbuild.c        |  23 ++++
src/backend/replication/slotfuncs.c                | 118 +----------------
src/include/replication/logical.h                  |   2 +
src/include/replication/snapbuild.h                |   2 +
.../recovery/t/040_standby_failover_slots_sync.pl  |  97 +++++++++++---
7 files changed, 351 insertions(+), 171 deletions(-)



Message-ID: <E1rrwJ6-000GHX-0a@gemulon.postgresql.org>
Permalink:  ../E1rrwJ6-000GHX-0a@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1rrwJ6-000GHX-0a@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: akapila@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Ensure that the sync slots reach a consistent state after promot
  In-Reply-To: <E1rrwJ6-000GHX-0a@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