Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8bcf90c

Browse files
committed
Fix race in TAP test 002_archiving.pl when restoring history file
This test, introduced indf86e52, uses a second standby to check thatit is able to remove correctly RECOVERYHISTORY and RECOVERYXLOG at theend of recovery. This standby uses the archives of the primary torestore its contents, with some of the archive's contents coming fromthe first standby previously promoted. In slow environments, it waspossible that the test did not check what it should, as the history filegenerated by the promotion of the first standby may not be stored yet onthe archives the second standby feeds on. So, it could be possible thatthe second standby selects an incorrect timeline, without restoring ahistory file at all.This commits adds a wait phase to make sure that the history filerequired by the second standby is archived before this cluster iscreated. This relies on poll_query_until() with pg_stat_file() and anabsolute path, something not supported in REL_10_STABLE.While on it, this adds a new test to check that the history file hasbeen restored by looking at the logs of the second standby. Thisensures 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 bydf86e52, but it came in light as aneffect of the bug fixed byacf1dd4, where the extra restore_commandcalls made the test much slower.Reported-by: Andres FreundDiscussion:https://postgr.es/m/YlT23IvsXkGuLzFi@paquier.xyzBackpatch-through: 11
1 parentacd0eb6 commit8bcf90c

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
@@ -6,7 +6,7 @@
66
use warnings;
77
use PostgresNode;
88
use TestLib;
9-
use Test::Moretests=>3;
9+
use Test::Moretests=>4;
1010
use File::Copy;
1111

1212
# Initialize primary node, doing archives
@@ -24,6 +24,8 @@
2424

2525
# Initialize standby node from backup, fetching WAL from archives
2626
my$node_standby = get_new_node('standby');
27+
# Note that this makes the standby store its contents on the archives
28+
# of the primary.
2729
$node_standby->init_from_backup($node_primary,$backup_name,
2830
has_restoring=> 1);
2931
$node_standby->append_conf('postgresql.conf',
@@ -58,19 +60,39 @@
5860
# file, switch to a timeline large enough to allow a standby to recover
5961
# a history file from an archive. As this requires at least two timeline
6062
# switches, promote the existing standby first. Then create a second
61-
# standby based on thepromoted one. Finally, the second standby is
62-
# promoted.
63+
# standby based on theprimary, using its archives. Finally, the second
64+
#standby ispromoted.
6365
$node_standby->promote;
6466

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

82+
my$log_location =-s$node_standby2->logfile;
83+
7084
# Now promote standby2, and check that temporary files specifically
7185
# generated during archive recovery are removed by the end of recovery.
7286
$node_standby2->promote;
87+
88+
# Check the logs of the standby to see that the commands have failed.
89+
my$log_contents = slurp_file($node_standby2->logfile,$log_location);
7390
my$node_standby2_data =$node_standby2->data_dir;
91+
92+
like(
93+
$log_contents,
94+
qr/restored log file "00000002.history" from archive/s,
95+
"00000002.history retrieved from the archives");
7496
ok( !-f"$node_standby2_data/pg_wal/RECOVERYHISTORY",
7597
"RECOVERYHISTORY removed after promotion");
7698
ok( !-f"$node_standby2_data/pg_wal/RECOVERYXLOG",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp