From: Bossart, Nathan <bossartn@amazon.com>
To: Andres Freund <andres@anarazel.de>
Cc: alvherre@alvh.no-ip.org <alvherre@alvh.no-ip.org>
Cc: Robert Haas <robertmhaas@gmail.com>
Cc: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Cc: x4mmm@yandex-team.ru <x4mmm@yandex-team.ru>
Cc: a.lubennikova@postgrespro.ru <a.lubennikova@postgrespro.ru>
Cc: hlinnaka@iki.fi <hlinnaka@iki.fi>
Cc: matsumura.ryo@fujitsu.com <matsumura.ryo@fujitsu.com>
Cc: masao.fujii@gmail.com <masao.fujii@gmail.com>
Cc: pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>
Subject: Re: archive status ".ready" files may be created too early
Date: Tue, 31 Aug 2021 17:01:31 +0000
Message-ID: <21D63383-9336-4B64-BF12-BFE33563D7A2@amazon.com> (raw)
In-Reply-To: <20210831074338.mt7hpaveuyvb723d@alap3.anarazel.de>
References: <20210829023722.cz6nbehyupp3hemk@alap3.anarazel.de>
<202108301951.x66z53s4lq6p@alvherre.pgsql>
<20210830210529.bd7wmqodt747xa2y@alap3.anarazel.de>
<C6234E05-6391-485F-92C3-10F7EE4D9612@amazon.com>
<20210831023839.7brycllwyyapbrfv@alap3.anarazel.de>
<282F96BA-948C-41DD-8A68-3E5ACE4D92C5@amazon.com>
<20210831074338.mt7hpaveuyvb723d@alap3.anarazel.de>
On 8/31/21, 12:44 AM, "Andres Freund" <andres@anarazel.de> wrote:
> If there's now a flush request including all of s3, we'll have the following
> sequence of notifies:
>
> NotifySegmentsReadyForArchive(s1)
> nothing happens, smaller than s1+10
>
> NotifySegmentsReadyForArchive(s2)
> earliestSegBoundary = s4
> earliestSegBoundaryEndPtr = s4+10
> latestSegBoundary = s4
> latestSegBoundaryEndPtr = s4 + 10
> latest_boundary_seg = s1
>
> NotifySegmentsReadyForArchive(s3)
> nothing happens, flush is smaller than s4
When earliestSegBoundary is set to s4, latestSegBoundary will be set
to MaxXLogSegNo.
> If the record ending at s4 + 10 isn't an async commit (and thus
> XLogCtl->asyncXactLSN is smaller), and there are no further records, we can
> end up waiting effectively forever for s2 (and s3) to be archived. If all
> other connections (and autovac etc) are idle, there will be no XLogFlush()
> calls, nor will XLogBackgroundFlush() do anything, because it'll hit the "If
> already known flushed" path, because the the first page in s4 is only
> partially filled.
I'm not following why s4 wouldn't be flushed in this example. Even if
the first page in s4 is only partially filled, that portion of the
record should still get flushed, and we'll create the .ready files for
s2 and s3 at that time. I tested this by adding some debug logging
and creating a small record that crossed segment boundaries but didn't
fill the first page on the next segment, and the .ready file was
created as expected. Is there a case where we wouldn't flush the end
of the record to disk?
During my testing, I did find an obvious bug. We probably shouldn't
be calling NotifySegmentsReadyForArchive() when archiving isn't
enabled.
inline patch 1: src/backend/postmaster/walwriter.c (+2/-1 lines) download inline-1.patchdiff --git a/src/backend/postmaster/walwriter.c b/src/backend/postmaster/walwriter.cindex 6a1e16edc2..8ca0d8e616 100644--- a/src/backend/postmaster/walwriter.c+++ b/src/backend/postmaster/walwriter.c@@ -253,7 +253,8 @@ WalWriterMain(void)
* here to handle a race condition where WAL is flushed to disk prior
* to registering the segment boundary.
*/
- NotifySegmentsReadyForArchive(GetFlushRecPtr());+ if (XLogArchivingActive())+ NotifySegmentsReadyForArchive(GetFlushRecPtr());
/*
* Do what we're here for; then, if XLogBackgroundFlush() found useful
Nathan
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-hackers@postgresql.org
Cc: bossartn@amazon.com, andres@anarazel.de, alvherre@alvh.no-ip.org, robertmhaas@gmail.com, horikyota.ntt@gmail.com, x4mmm@yandex-team.ru, a.lubennikova@postgrespro.ru, hlinnaka@iki.fi, matsumura.ryo@fujitsu.com, masao.fujii@gmail.com
Subject: Re: archive status ".ready" files may be created too early
In-Reply-To: <21D63383-9336-4B64-BF12-BFE33563D7A2@amazon.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