From: Fujii Masao <masao.fujii@oss.nttdata.com>
To: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Cc: dilipbalaut@gmail.com
Cc: michael@paquier.xyz
Cc: pgsql-hackers@postgresql.org
Subject: Re: pg_get_wal_replay_pause_state() should not return 'paused' while a promotion is ongoing.
Date: Wed, 19 May 2021 19:24:09 +0900
Message-ID: <63ad1368-18e2-8900-8443-524bdfb1bef5@oss.nttdata.com> (raw)
In-Reply-To: <20210519.164352.1786666023204393975.horikyota.ntt@gmail.com>
References: <CAFiTN-vgo9VnNDq2EaPfFBzpmUt=DjwzyY8xaC9ss3Pz9Y3OMw@mail.gmail.com>
<20210519.152529.1656496447023808157.horikyota.ntt@gmail.com>
<25396c69-9f70-ca3e-5de3-f3a108ae2a26@oss.nttdata.com>
<20210519.164352.1786666023204393975.horikyota.ntt@gmail.com>
On 2021/05/19 16:43, Kyotaro Horiguchi wrote:
> +1 for adding some tests for pg_wal_replay_pause() but the test seems
> like checking only that pg_get_wal_replay_pause_state() returns the
> expected state value. Don't we need to check that the recovery is
> actually paused and that the promotion happens at expected LSN?
Sounds good. Attached is the updated version of the patch.
I added such checks into the test.
BTW, while reading some recovery regression tests, I found that
013_crash_restart.pl has "use Time::HiRes qw(usleep)" but it seems
not necessary. We can safely remove that? Patch attached.
Regards,
--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
Attachments:download all (2 files, .tar.gz)recovery_pause_test_v2.patch (text/plain, 3.2K) downloaddiff --git a/src/test/recovery/t/005_replay_delay.pl b/src/test/recovery/t/005_replay_delay.plindex 7f177afaed..496fa40fe1 100644--- a/src/test/recovery/t/005_replay_delay.pl+++ b/src/test/recovery/t/005_replay_delay.pl@@ -1,13 +1,13 @@
# Copyright (c) 2021, PostgreSQL Global Development Group
-# Checks for recovery_min_apply_delay+# Checks for recovery_min_apply_delay and recovery pause
use strict;
use warnings;
use PostgresNode;
use TestLib;
-use Test::More tests => 1;+use Test::More tests => 3;
# Initialize primary node
my $node_primary = get_new_node('primary');
@@ -55,3 +55,58 @@ $node_standby->poll_query_until('postgres',
# the configured apply delay.
ok(time() - $primary_insert_time >= $delay,
"standby applies WAL only after replication delay");
+++# Check that recovery can be paused or resumed expectedly.+my $node_standby2 = get_new_node('standby2');+$node_standby2->init_from_backup($node_primary, $backup_name,+ has_streaming => 1);+$node_standby2->start;++# Recovery is not yet paused.+is($node_standby2->safe_psql('postgres',+ "SELECT pg_get_wal_replay_pause_state()"),+ 'not paused', 'pg_get_wal_replay_pause_state() reports not paused');++# Request to pause recovery and wait until it's actually paused.+$node_standby2->safe_psql('postgres', "SELECT pg_wal_replay_pause()");+$node_primary->safe_psql('postgres',+ "INSERT INTO tab_int VALUES (generate_series(21,30))");+$node_standby2->poll_query_until('postgres',+ "SELECT pg_get_wal_replay_pause_state() = 'paused'")+ or die "Timed out while waiting for recovery to be paused";++# Even if new WAL records are streamed from the primary,+# recovery in the paused state doesn't replay them.+my $receive_lsn = $node_standby2->safe_psql('postgres',+ "SELECT pg_last_wal_receive_lsn()");+my $replay_lsn = $node_standby2->safe_psql('postgres',+ "SELECT pg_last_wal_replay_lsn()");+$node_primary->safe_psql('postgres',+ "INSERT INTO tab_int VALUES (generate_series(31,40))");+$node_standby2->poll_query_until('postgres',+ "SELECT '$receive_lsn'::pg_lsn < pg_last_wal_receive_lsn()")+ or die "Timed out while waiting for new WAL to be streamed";+is($node_standby2->safe_psql('postgres',+ "SELECT pg_last_wal_replay_lsn()"),+ qq($replay_lsn), 'no WAL is replayed in the paused state');++# Request to resume recovery and wait until it's actually resumed.+$node_standby2->safe_psql('postgres', "SELECT pg_wal_replay_resume()");+$node_standby2->poll_query_until('postgres',+ "SELECT pg_get_wal_replay_pause_state() = 'not paused' AND pg_last_wal_replay_lsn() > '$replay_lsn'::pg_lsn")+ or die "Timed out while waiting for recovery to be resumed";++# Check that the paused state ends and promotion continues if a promotion+# is triggered while recovery is paused.+$node_standby2->safe_psql('postgres', "SELECT pg_wal_replay_pause()");+$node_primary->safe_psql('postgres',+ "INSERT INTO tab_int VALUES (generate_series(41,50))");+$node_standby2->poll_query_until('postgres',+ "SELECT pg_get_wal_replay_pause_state() = 'paused'")+ or die "Timed out while waiting for recovery to be paused";++$node_standby2->promote;+$node_standby2->poll_query_until('postgres',+ "SELECT NOT pg_is_in_recovery()")+ or die "Timed out while waiting for promotion to finish";remove_unnecessary_hires_usleep_v1.patch (text/plain, 359B) downloaddiff --git a/src/test/recovery/t/013_crash_restart.pl b/src/test/recovery/t/013_crash_restart.plindex 66e43ffbe8..e1c36abe97 100644--- a/src/test/recovery/t/013_crash_restart.pl+++ b/src/test/recovery/t/013_crash_restart.pl@@ -17,7 +17,6 @@ use PostgresNode;
use TestLib;
use Test::More;
use Config;
-use Time::HiRes qw(usleep);
plan tests => 18;
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: masao.fujii@oss.nttdata.com, horikyota.ntt@gmail.com, dilipbalaut@gmail.com, michael@paquier.xyz
Subject: Re: pg_get_wal_replay_pause_state() should not return 'paused' while a promotion is ongoing.
In-Reply-To: <63ad1368-18e2-8900-8443-524bdfb1bef5@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