From: Fujii Masao <masao.fujii@oss.nttdata.com>
To: Alvaro Herrera <alvherre@2ndquadrant.com>
Cc: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Cc: pgsql-hackers@lists.postgresql.org
Subject: Re: Review for GetWALAvailability()
Date: Thu, 25 Jun 2020 14:35:34 +0900
Message-ID: <a9c65f68-8ea5-5bb3-349d-6d909fff38bc@oss.nttdata.com> (raw)
In-Reply-To: <20200625035718.GA28721@alvherre.pgsql>
References: <20200625035718.GA28721@alvherre.pgsql>
On 2020/06/25 12:57, Alvaro Herrera wrote:
> On 2020-Jun-25, Fujii Masao wrote:
>
>> /*
>> * Find the oldest extant segment file. We get 1 until checkpoint removes
>> * the first WAL segment file since startup, which causes the status being
>> * wrong under certain abnormal conditions but that doesn't actually harm.
>> */
>> oldestSeg = XLogGetLastRemovedSegno() + 1;
>>
>> I see the point of the above comment, but this can cause wal_status to be
>> changed from "lost" to "unreserved" after the server restart. Isn't this
>> really confusing? At least it seems better to document that behavior.
>
> Hmm.
>
>> Or if we *can ensure* that the slot with invalidated_at set always means
>> "lost" slot, we can judge that wal_status is "lost" without using fragile
>> XLogGetLastRemovedSegno(). Thought?
>
> Hmm, this sounds compelling -- I think it just means we need to ensure
> we reset invalidated_at to zero if the slot's restart_lsn is set to a
> correct position afterwards.
Yes.
> I don't think we have any operation that
> does that, so it should be safe -- hopefully I didn't overlook anything?
We need to call ReplicationSlotMarkDirty() and ReplicationSlotSave()
just after setting invalidated_at and restart_lsn in InvalidateObsoleteReplicationSlots()?
Otherwise, restart_lsn can go back to the previous value after the restart.
inline patch 1: src/backend/replication/slot.c (+7/-0 lines) download inline-1.patchdiff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.cindex e8761f3a18..5584e5dd2c 100644--- a/src/backend/replication/slot.c+++ b/src/backend/replication/slot.c@@ -1229,6 +1229,13 @@ restart:
s->data.invalidated_at = s->data.restart_lsn;
s->data.restart_lsn = InvalidXLogRecPtr;
SpinLockRelease(&s->mutex);
++ /*+ * Save this invalidated slot to disk, to ensure that the slot+ * is still invalid even after the server restart.+ */+ ReplicationSlotMarkDirty();+ ReplicationSlotSave();
ReplicationSlotRelease();
/* if we did anything, start from scratch */
Maybe we don't need to do this if the slot is temporary?
> Neither copy nor advance seem to work with a slot that has invalid
> restart_lsn.
>
>> Or XLogGetLastRemovedSegno() should be fixed so that it returns valid
>> value even after the restart?
>
> This seems more work to implement.
Yes.
Regards,
--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: masao.fujii@oss.nttdata.com, alvherre@2ndquadrant.com, horikyota.ntt@gmail.com
Subject: Re: Review for GetWALAvailability()
In-Reply-To: <a9c65f68-8ea5-5bb3-349d-6d909fff38bc@oss.nttdata.com>
References: <20200625035718.GA28721@alvherre.pgsql> <a9c65f68-8ea5-5bb3-349d-6d909fff38bc@oss.nttdata.com>
* 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