RE: Newly created replication slot may be invalidated by checkpoint - Mailing list pgsql-hackers

From Hayato Kuroda (Fujitsu)
Subject RE: Newly created replication slot may be invalidated by checkpoint
Date
Msg-id OSCPR01MB14966FC74C1C617559345930BF51FA@OSCPR01MB14966.jpnprd01.prod.outlook.com
Whole thread Raw
In response to RE: Newly created replication slot may be invalidated by checkpoint  ("Vitaly Davydov" <v.davydov@postgrespro.ru>)
List pgsql-hackers
Dear Vitaly,

> I propose to apply this patch and then to think how to resolve this race
> condition, which seems to take place in 18 and master as well.

No, I think this invalidation can't happen in PG18/HEAD.
This is because in CheckpointGuts()->CheckPointReplicationSlots()->
ReplicationSlotsComputeRequiredLSN(), slots are examined one by one to determine
whether their restart_lsn has advanced since the last check. If any slot has
advanced, protection is applied starting from the oldest restart_lsn.
Crucially, this check is performed before WAL removal. The function call was
introduced in commit ca307d5cec.
 
Further analysis shows that it is also safe if a slot is being created and WAL
advances after CheckpointGuts() but before the removal segments are determined.
In this case the restart_lsn points the CHECKPOINT_REDO generated by the current
CHECKPOINT. This and later records won't be discarded.

Best regards,
Hayato Kuroda
FUJITSU LIMITED


pgsql-hackers by date:

Previous
From: Dilip Kumar
Date:
Subject: Re: Proposal: Conflict log history table for Logical Replication
Next
From: Konstantin Knizhnik
Date:
Subject: Re: Orphan page in _bt_split