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

Commite61efaf

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 parent42e44f3 commite61efaf

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

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

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
# Initialize standby node from backup, fetching WAL from archives
2626
my$node_standby = PostgreSQL::Test::Cluster->new('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',
@@ -81,10 +83,20 @@
8183
# file, switch to a timeline large enough to allow a standby to recover
8284
# a history file from an archive. As this requires at least two timeline
8385
# switches, promote the existing standby first. Then create a second
84-
# standby based on thepromoted one. Finally, the second standby is
85-
# promoted.
86+
# standby based on theprimary, using its archives. Finally, the second
87+
#standby ispromoted.
8688
$node_standby->promote;
8789

90+
# Wait until the history file has been stored on the archives of the
91+
# primary once the promotion of the standby completes. This ensures that
92+
# the second standby created below will be able to restore this file,
93+
# creating a RECOVERYHISTORY.
94+
my$primary_archive =$node_primary->archive_dir;
95+
$caughtup_query =
96+
"SELECT size IS NOT NULL FROM pg_stat_file('$primary_archive/00000002.history')";
97+
$node_primary->poll_query_until('postgres',$caughtup_query)
98+
ordie"Timed out while waiting for archiving of 00000002.history";
99+
88100
# recovery_end_command should have been triggered on promotion.
89101
ok(-f"$data_dir/$recovery_end_command_file",
90102
'recovery_end_command executed after promotion');
@@ -108,14 +120,19 @@
108120
# Now promote standby2, and check that temporary files specifically
109121
# generated during archive recovery are removed by the end of recovery.
110122
$node_standby2->promote;
123+
124+
# Check the logs of the standby to see that the commands have failed.
125+
my$log_contents = slurp_file($node_standby2->logfile,$log_location);
111126
my$node_standby2_data =$node_standby2->data_dir;
127+
128+
like(
129+
$log_contents,
130+
qr/restored log file "00000002.history" from archive/s,
131+
"00000002.history retrieved from the archives");
112132
ok( !-f"$node_standby2_data/pg_wal/RECOVERYHISTORY",
113133
"RECOVERYHISTORY removed after promotion");
114134
ok( !-f"$node_standby2_data/pg_wal/RECOVERYXLOG",
115135
"RECOVERYXLOG removed after promotion");
116-
117-
# Check the logs of the standby to see that the commands have failed.
118-
my$log_contents = slurp_file($node_standby2->logfile,$log_location);
119136
like(
120137
$log_contents,
121138
qr/WARNING:.*recovery_end_command/s,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp