Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a6fc64b

Browse files
committed
Fix race in TAP test 002_archiving.pl when restoring history file
This test, introduced in df86e52, uses a second standby to check that it is able to remove correctly RECOVERYHISTORY and RECOVERYXLOG at the end of recovery. This standby uses the archives of the primary to restore its contents, with some of the archive's contents coming from the first standby previously promoted. In slow environments, it was possible that the test did not check what it should, as the history file generated by the promotion of the first standby may not be stored yet on the archives the second standby feeds on. So, it could be possible that the second standby selects an incorrect timeline, without restoring a history file at all. This commits adds a wait phase to make sure that the history file required by the second standby is archived before this cluster is created. This relies on poll_query_until() with pg_stat_file() and an absolute path, something not supported in REL_10_STABLE. While on it, this adds a new test to check that the history file has been restored by looking at the logs of the second standby. This ensures that a RECOVERYHISTORY, whose removal needs to be checked, is created in the first place. This should make the test more robust. This test has been introduced by df86e52, but it came in light as an effect of the bug fixed by acf1dd4, where the extra restore_command calls made the test much slower. Reported-by: Andres Freund Discussion: https://postgr.es/m/YlT23IvsXkGuLzFi@paquier.xyz Backpatch-through: 11
1 parent b404513 commit a6fc64b

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

src/test/recovery/t/002_archiving.pl

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use warnings;
44
use PostgresNode;
55
use TestLib;
6-
use Test::More tests => 3;
6+
use Test::More tests => 4;
77
use File::Copy;
88

99
# Initialize master node, doing archives
@@ -21,6 +21,8 @@
2121

2222
# Initialize standby node from backup, fetching WAL from archives
2323
my $node_standby = get_new_node('standby');
24+
# Note that this makes the standby store its contents on the archives
25+
# of the primary.
2426
$node_standby->init_from_backup($node_master, $backup_name,
2527
has_restoring => 1);
2628
$node_standby->append_conf('postgresql.conf',
@@ -55,19 +57,39 @@
5557
# file, switch to a timeline large enough to allow a standby to recover
5658
# a history file from an archive. As this requires at least two timeline
5759
# switches, promote the existing standby first. Then create a second
58-
# standby based on the promoted one. Finally, the second standby is
59-
# promoted.
60+
# standby based on the primary, using its archives. Finally, the second
61+
# standby is promoted.
6062
$node_standby->promote;
6163

64+
# Wait until the history file has been stored on the archives of the
65+
# primary once the promotion of the standby completes. This ensures that
66+
# the second standby created below will be able to restore this file,
67+
# creating a RECOVERYHISTORY.
68+
my $primary_archive = $node_master->archive_dir;
69+
$caughtup_query =
70+
"SELECT size IS NOT NULL FROM pg_stat_file('$primary_archive/00000002.history')";
71+
$node_master->poll_query_until('postgres', $caughtup_query)
72+
or die "Timed out while waiting for archiving of 00000002.history";
73+
6274
my $node_standby2 = get_new_node('standby2');
6375
$node_standby2->init_from_backup($node_master, $backup_name,
6476
has_restoring => 1);
6577
$node_standby2->start;
6678

79+
my $log_location = -s $node_standby2->logfile;
80+
6781
# Now promote standby2, and check that temporary files specifically
6882
# generated during archive recovery are removed by the end of recovery.
6983
$node_standby2->promote;
84+
85+
# Check the logs of the standby to see that the commands have failed.
86+
my $log_contents = slurp_file($node_standby2->logfile, $log_location);
7087
my $node_standby2_data = $node_standby2->data_dir;
88+
89+
like(
90+
$log_contents,
91+
qr/restored log file "00000002.history" from archive/s,
92+
"00000002.history retrieved from the archives");
7193
ok( !-f "$node_standby2_data/pg_wal/RECOVERYHISTORY",
7294
"RECOVERYHISTORY removed after promotion");
7395
ok( !-f "$node_standby2_data/pg_wal/RECOVERYXLOG",

0 commit comments

Comments
 (0)