pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Ensure that a standby is able to follow a primary on a newer tim
7+ messages / 4 participants
[nested] [flat]

Commits from this thread:
  2021-01-14 424d7a9b27 8523a0971b  Stabilize timeline switch regression test.
* pgsql: Ensure that a standby is able to follow a primary on a newer tim
@ 2021-01-14 03:32  Fujii Masao <fujii@postgresql.org>
  0 siblings, 0 replies; 7+ messages in thread

From: Fujii Masao @ 2021-01-14 03:32 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Ensure that a standby is able to follow a primary on a newer timeline.

Commit 709d003fbd refactored WAL-reading code, but accidentally caused
WalSndSegmentOpen() to fail to follow a timeline switch while reading from
a historic timeline. This issue caused a standby to fail to follow a primary
on a newer timeline when WAL archiving is enabled.

If there is a timeline switch within the segment, WalSndSegmentOpen() should
read from the WAL segment belonging to the new timeline. But previously
since it failed to follow a timeline switch, it tried to read the WAL segment
with old timeline. When WAL archiving is enabled, that WAL segment with
old timeline doesn't exist because it's renamed to .partial. This leads
a primary to have tried to read non-existent WAL segment, and which caused
replication to faill with the error "ERROR:  requested WAL segment ... has
 already been removed".

This commit fixes WalSndSegmentOpen() so that it's able to follow a timeline
switch, to ensure that a standby is able to follow a primary on a newer
timeline even when WAL archiving is enabled.

This commit also adds the regression test to check whether a standby is
able to follow a primary on a newer timeline when WAL archiving is enabled.

Back-patch to v13 where the bug was introduced.

Reported-by: Kyotaro Horiguchi
Author: Kyotaro Horiguchi, tweaked by Fujii Masao
Reviewed-by:  Alvaro Herrera, Fujii Masao
Discussion: https://postgr.es/m/20201209.174314.282492377848029776.horikyota.ntt@gmail.com

Branch
------
REL_13_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/94f52929a0c4e92c271c5a03bae782ddb0b086bd

Modified Files
--------------
src/backend/replication/walsender.c        |  2 +-
src/test/recovery/t/004_timeline_switch.pl | 42 +++++++++++++++++++++++++++---
2 files changed, 40 insertions(+), 4 deletions(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Ensure that a standby is able to follow a primary on a newer tim
@ 2021-01-14 03:32  Fujii Masao <fujii@postgresql.org>
  0 siblings, 1 reply; 7+ messages in thread

From: Fujii Masao @ 2021-01-14 03:32 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Ensure that a standby is able to follow a primary on a newer timeline.

Commit 709d003fbd refactored WAL-reading code, but accidentally caused
WalSndSegmentOpen() to fail to follow a timeline switch while reading from
a historic timeline. This issue caused a standby to fail to follow a primary
on a newer timeline when WAL archiving is enabled.

If there is a timeline switch within the segment, WalSndSegmentOpen() should
read from the WAL segment belonging to the new timeline. But previously
since it failed to follow a timeline switch, it tried to read the WAL segment
with old timeline. When WAL archiving is enabled, that WAL segment with
old timeline doesn't exist because it's renamed to .partial. This leads
a primary to have tried to read non-existent WAL segment, and which caused
replication to faill with the error "ERROR:  requested WAL segment ... has
 already been removed".

This commit fixes WalSndSegmentOpen() so that it's able to follow a timeline
switch, to ensure that a standby is able to follow a primary on a newer
timeline even when WAL archiving is enabled.

This commit also adds the regression test to check whether a standby is
able to follow a primary on a newer timeline when WAL archiving is enabled.

Back-patch to v13 where the bug was introduced.

Reported-by: Kyotaro Horiguchi
Author: Kyotaro Horiguchi, tweaked by Fujii Masao
Reviewed-by:  Alvaro Herrera, Fujii Masao
Discussion: https://postgr.es/m/20201209.174314.282492377848029776.horikyota.ntt@gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/fef5b47f6bfc9bfec619bb2e6e66b027e7ff21a3

Modified Files
--------------
src/backend/replication/walsender.c        |  2 +-
src/test/recovery/t/004_timeline_switch.pl | 42 +++++++++++++++++++++++++++---
2 files changed, 40 insertions(+), 4 deletions(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: pgsql: Ensure that a standby is able to follow a primary on a newer tim
@ 2021-01-14 04:59  Michael Paquier <michael@paquier.xyz>
  parent: Fujii Masao <fujii@postgresql.org>
  0 siblings, 1 reply; 7+ messages in thread

From: Michael Paquier @ 2021-01-14 04:59 UTC (permalink / raw)
  To: Fujii Masao <fujii@postgresql.org>; +Cc: pgsql-committers@lists.postgresql.org

Hi Fujii-san,

On Thu, Jan 14, 2021 at 03:32:52AM +0000, Fujii Masao wrote:
> Ensure that a standby is able to follow a primary on a newer timeline.
> 
> Commit 709d003fbd refactored WAL-reading code, but accidentally caused
> WalSndSegmentOpen() to fail to follow a timeline switch while reading from
> a historic timeline. This issue caused a standby to fail to follow a primary
> on a newer timeline when WAL archiving is enabled.

florican is telling that this test has some stability problems:
https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=florican&dt=2021-01-14%2003%3A55%3A45

Here I can see that replication keeps asking for a segment that's
already gone:
2021-01-13 23:34:52.104 EST [64611:1] LOG:  started streaming WAL from
primary at 0/3000000 on timeline 1
2021-01-13 23:34:52.104 EST [64611:2] FATAL:  could not receive data
from WAL stream: ERROR:  requested WAL segment
000000010000000000000003 has already been removed

At quick glance, it seems to be an issue after the promotion of
primary_2 before starting standby_3.
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: pgsql: Ensure that a standby is able to follow a primary on a newer tim
@ 2021-01-14 05:14  Fujii Masao <masao.fujii@oss.nttdata.com>
  parent: Michael Paquier <michael@paquier.xyz>
  0 siblings, 1 reply; 7+ messages in thread

From: Fujii Masao @ 2021-01-14 05:14 UTC (permalink / raw)
  To: Michael Paquier <michael@paquier.xyz>; Fujii Masao <fujii@postgresql.org>; +Cc: pgsql-committers@lists.postgresql.org



On 2021/01/14 13:59, Michael Paquier wrote:
> Hi Fujii-san,
> 
> On Thu, Jan 14, 2021 at 03:32:52AM +0000, Fujii Masao wrote:
>> Ensure that a standby is able to follow a primary on a newer timeline.
>>
>> Commit 709d003fbd refactored WAL-reading code, but accidentally caused
>> WalSndSegmentOpen() to fail to follow a timeline switch while reading from
>> a historic timeline. This issue caused a standby to fail to follow a primary
>> on a newer timeline when WAL archiving is enabled.
> 
> florican is telling that this test has some stability problems:
> https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=florican&dt=2021-01-14%2003%3A55%3A45
> 
> Here I can see that replication keeps asking for a segment that's
> already gone:
> 2021-01-13 23:34:52.104 EST [64611:1] LOG:  started streaming WAL from
> primary at 0/3000000 on timeline 1
> 2021-01-13 23:34:52.104 EST [64611:2] FATAL:  could not receive data
> from WAL stream: ERROR:  requested WAL segment
> 000000010000000000000003 has already been removed

Thanks for reporting this! I'm looking at this issue.

My guess is that the requested WAL file was removed unfortunately by
checkpoint because no replication slot is used and wal_keep_size is not set.
So easy fix is to set wal_keep_size to 512MB or other in that test. Thought?

Regards,

-- 
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION





^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: pgsql: Ensure that a standby is able to follow a primary on a newer tim
@ 2021-01-14 05:23  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Fujii Masao <masao.fujii@oss.nttdata.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Tom Lane @ 2021-01-14 05:23 UTC (permalink / raw)
  To: Fujii Masao <masao.fujii@oss.nttdata.com>; +Cc: Michael Paquier <michael@paquier.xyz>; Fujii Masao <fujii@postgresql.org>; pgsql-committers@lists.postgresql.org

Fujii Masao <masao.fujii@oss.nttdata.com> writes:
> On 2021/01/14 13:59, Michael Paquier wrote:
>> florican is telling that this test has some stability problems:
>> https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=florican&dt=2021-01-14%2003%3A55%3A45

> My guess is that the requested WAL file was removed unfortunately by
> checkpoint because no replication slot is used and wal_keep_size is not set.
> So easy fix is to set wal_keep_size to 512MB or other in that test. Thought?

florican did pass this test on the v13 branch, so I agree it's probably
a timing issue not any deeper bug.  Your theory seems plausible.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: pgsql: Ensure that a standby is able to follow a primary on a newer tim
@ 2021-01-14 06:19  Fujii Masao <masao.fujii@oss.nttdata.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 7+ messages in thread

From: Fujii Masao @ 2021-01-14 06:19 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Michael Paquier <michael@paquier.xyz>; Fujii Masao <fujii@postgresql.org>; pgsql-committers@lists.postgresql.org



On 2021/01/14 14:23, Tom Lane wrote:
> Fujii Masao <masao.fujii@oss.nttdata.com> writes:
>> On 2021/01/14 13:59, Michael Paquier wrote:
>>> florican is telling that this test has some stability problems:
>>> https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=florican&dt=2021-01-14%2003%3A55%3A45
> 
>> My guess is that the requested WAL file was removed unfortunately by
>> checkpoint because no replication slot is used and wal_keep_size is not set.
>> So easy fix is to set wal_keep_size to 512MB or other in that test. Thought?
> 
> florican did pass this test on the v13 branch, so I agree it's probably
> a timing issue not any deeper bug.  Your theory seems plausible.

Thanks for the check!

So, barring any objection, I will push the attached patch that sets
wal_keep_size in the test.

BTW, I included the URL to Michael's report [1] in the commit log. But this
URL doesn't seem to work fine maybe because <message-id> part includes
a slash character.

[1]
https://postgr.es/m/X//PsenxcC50jDzX@paquier.xyz

Regards,

-- 
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION

Attachments: download all (2 files, .tar.gz)

0001-Stabilize-timeline-switch-regression-test_v13.patch (text/plain, 1.5K) download From 2ed9eed25bfd7b6e22eade23e2c602af7123c731 Mon Sep 17 00:00:00 2001 From: Fujii Masao <fujii@postgresql.org> Date: Thu, 14 Jan 2021 14:37:01 +0900 Subject: [PATCH] Stabilize timeline switch regression test. Commit fef5b47f6b added the regression test to check whether a standby is able to follow a primary on a newer timeline when WAL archiving is enabled. But the buildfarm member florican reported that this test failed because the requested WAL segment was removed and replication failed. This is a timing issue. Since neither replication slot is used nor wal_keep_size is set in the test, checkpoint could remove the WAL segment that's still necessary for replication. This commit stabilizes the test by setting wal_keep_size. Back-patch to v13 where the regression test that this commit stabilizes was added. Author: Fujii Masao Discussion: https://postgr.es/m/X//PsenxcC50jDzX@paquier.xyz --- src/test/recovery/t/004_timeline_switch.pl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/test/recovery/t/004_timeline_switch.pl b/src/test/recovery/t/004_timeline_switch.pl index edadab790f..91a63f4e58 100644 --- a/src/test/recovery/t/004_timeline_switch.pl +++ b/src/test/recovery/t/004_timeline_switch.pl @@ -75,6 +75,10 @@ is($result, qq(2000), 'check content of standby 2'); # Initialize master node my $node_master_2 = get_new_node('master_2'); $node_master_2->init(allows_streaming => 1, has_archiving => 1); +$node_master_2->append_conf( + 'postgresql.conf', qq( +wal_keep_size = 512MB +)); $node_master_2->start; # Take backup -- 2.27.0
0001-Stabilize-timeline-switch-regression-test.patch (text/plain, 1.5K) download From c7680a8a59218b78a71b5dc1a91d935576369735 Mon Sep 17 00:00:00 2001 From: Fujii Masao <fujii@postgresql.org> Date: Thu, 14 Jan 2021 14:37:01 +0900 Subject: [PATCH] Stabilize timeline switch regression test. Commit fef5b47f6b added the regression test to check whether a standby is able to follow a primary on a newer timeline when WAL archiving is enabled. But the buildfarm member florican reported that this test failed because the requested WAL segment was removed and replication failed. This is a timing issue. Since neither replication slot is used nor wal_keep_size is set in the test, checkpoint could remove the WAL segment that's still necessary for replication. This commit stabilizes the test by setting wal_keep_size. Back-patch to v13 where the regression test that this commit stabilizes was added. Author: Fujii Masao Discussion: https://postgr.es/m/X//PsenxcC50jDzX@paquier.xyz --- src/test/recovery/t/004_timeline_switch.pl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/test/recovery/t/004_timeline_switch.pl b/src/test/recovery/t/004_timeline_switch.pl index 8dad044db4..c8dbd8f9df 100644 --- a/src/test/recovery/t/004_timeline_switch.pl +++ b/src/test/recovery/t/004_timeline_switch.pl @@ -75,6 +75,10 @@ is($result, qq(2000), 'check content of standby 2'); # Initialize primary node my $node_primary_2 = get_new_node('primary_2'); $node_primary_2->init(allows_streaming => 1, has_archiving => 1); +$node_primary_2->append_conf( + 'postgresql.conf', qq( +wal_keep_size = 512MB +)); $node_primary_2->start; # Take backup -- 2.27.0
^ permalink raw reply [nested|flat] 7+ messages in thread

* Re: pgsql: Ensure that a standby is able to follow a primary on a newer tim
@ 2021-01-15 02:50  Michael Paquier <michael@paquier.xyz>
  parent: Fujii Masao <masao.fujii@oss.nttdata.com>
  0 siblings, 0 replies; 7+ messages in thread

From: Michael Paquier @ 2021-01-15 02:50 UTC (permalink / raw)
  To: Fujii Masao <masao.fujii@oss.nttdata.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; Fujii Masao <fujii@postgresql.org>; pgsql-committers@lists.postgresql.org

On Thu, Jan 14, 2021 at 03:19:02PM +0900, Fujii Masao wrote:
> BTW, I included the URL to Michael's report [1] in the commit log. But this
> URL doesn't seem to work fine maybe because <message-id> part includes
> a slash character.

Sorry about that.  This is related to mutt that has changed its logic
to generate message-ids in a recent release to be more random, and
maybe Debian is in play here with some custom patch, but I am not
sure.  That's not configurable, but I'll try to investigate more if
there is something I can do about it :/ 
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2021-01-15 02:50 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-01-14 03:32 pgsql: Ensure that a standby is able to follow a primary on a newer tim Fujii Masao <fujii@postgresql.org>
2021-01-14 03:32 pgsql: Ensure that a standby is able to follow a primary on a newer tim Fujii Masao <fujii@postgresql.org>
2021-01-14 04:59 ` Michael Paquier <michael@paquier.xyz>
2021-01-14 05:14   ` Fujii Masao <masao.fujii@oss.nttdata.com>
2021-01-14 05:23     ` Tom Lane <tgl@sss.pgh.pa.us>
2021-01-14 06:19       ` Fujii Masao <masao.fujii@oss.nttdata.com>
2021-01-15 02:50         ` Michael Paquier <michael@paquier.xyz>

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