Re: Standby recovers records from wrong timeline

From: Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>
To: ants(at)cybertec(dot)at
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Standby recovers records from wrong timeline
Date: 2022-10-21 09:38:06
Message-ID: 20221021.183806.464695207279777677.horikyota.ntt@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

At Fri, 21 Oct 2022 17:44:40 +0900 (JST), Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com> wrote in
> At Fri, 21 Oct 2022 17:12:45 +0900 (JST), Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com> wrote in
> > latest works. It dones't consider the case of explict target timlines
> > so it's just a PoC. (So this doesn't work if recovery_target_timeline
> > is set to 2 for the "standby" in the repro.)
>
> So, finally I noticed that the function XLogFileReadAnyTLI is not
> needed at all if we are going this direction.
>
> Regardless of recvoery_target_timeline is latest or any explicit
> imeline id or checkpoint timeline, what we can do to reach the target
> timline is just to follow the history file's direction.
>
> If segments are partly gone while reading on a timeline, a segment on
> the older timelines is just a crap since it should be incompatible.
>
> So.. I'm at a loss about what the function is for.
>
> Please anyone tell me why do we need the behavior of
> XLogFileReadAnyTLI() at all?

It is introduced by 1bb2558046. And the behavior dates back to 2042b3428d.

Hmmm.. XLogFileRead() at the time did essentially the same thing to
the current XLogFileReadAnyTLI. At that time the expectedTL*I*s
contained only timeline IDs. Thus it seems to me, at that time,
recovery assumed that it is fine with reading the segment on the
greatest available timeline in the TLI list at every mement. (Mmm. I
cannot describe this precise enough....) In other words it did not
intend to use the segments on the older timelines than expected as the
replacement of the segment on the correct timelnie.

If this is correct (I hople the description above makes sense), now
that we can determine the exact TLI to read for the specified segno,
we don't need to descend to older timelines. In other words, the
current XLogFileReadAnyTLI() should be just XLogFileReadOnHistory(),
which reads a segment of the exact timeline calculated from the
expectedTLEs and the segno.

I'm going to work in this direction.

regards.

--
Kyotaro Horiguchi
NTT Open Source Software Center

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Ants Aasma 2022-10-21 09:48:36 Re: Standby recovers records from wrong timeline
Previous Message houzj.fnst@fujitsu.com 2022-10-21 09:32:20 RE: Perform streaming logical transactions by background workers and parallel apply