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

Commit54a16df

Browse files
committed
Make the pg_rewind regression tests more robust on slow systems.
There were a couple of hard-coded sleeps in the tests: to wait for standbyto catch up with master, and to wait for promotion with "pg_ctl promote"to complete. Instead of a fixed, hard-coded sleep, poll the server with aquery once a second. This isn't ideal either, and I wish we had a bettersolution for real-world applications too, but this should fix theimmediate problem.Patch by Michael Paquier, with some editing by me.
1 parentcef939c commit54a16df

File tree

1 file changed

+41
-5
lines changed

1 file changed

+41
-5
lines changed

‎src/bin/pg_rewind/RewindTest.pm

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,37 @@ sub check_query
125125
}
126126
}
127127

128+
# Run a query once a second, until it returns 't' (i.e. SQL boolean true).
129+
subpoll_query_until
130+
{
131+
my ($query,$connstr) =@_;
132+
133+
my$max_attempts = 30;
134+
my$attempts = 0;
135+
my ($stdout,$stderr);
136+
137+
while ($attempts <$max_attempts)
138+
{
139+
my$cmd = ['psql','-At','-c',"$query",'-d',"$connstr" ];
140+
my$result = run$cmd,'>', \$stdout,'2>', \$stderr;
141+
142+
chomp($stdout);
143+
if ($stdouteq"t")
144+
{
145+
return 1;
146+
}
147+
148+
# Wait a second before retrying.
149+
sleep 1;
150+
$attempts++;
151+
}
152+
153+
# The query result didn't change in 30 seconds. Give up. Print the stderr
154+
# from the last attempt, hopefully that's useful for debugging.
155+
diag$stderr;
156+
return 0;
157+
}
158+
128159
subappend_to_file
129160
{
130161
my($filename,$str) =@_;
@@ -185,16 +216,19 @@ sub create_standby
185216
# Base backup is taken with xlog files included
186217
system_or_bail("pg_basebackup -D$test_standby_datadir -p$port_master -x >>$log_path 2>&1");
187218
append_to_file("$test_standby_datadir/recovery.conf",qq(
188-
primary_conninfo='$connstr_master'
219+
primary_conninfo='$connstr_master application_name=rewind_standby'
189220
standby_mode=on
190221
recovery_target_timeline='latest'
191222
));
192223

193224
# Start standby
194225
system_or_bail("pg_ctl -w -D$test_standby_datadir -o\"-k$tempdir_short --listen-addresses='' -p$port_standby\" start >>$log_path 2>&1");
195226

196-
# sleep a bit to make sure the standby has caught up.
197-
sleep 1;
227+
# Wait until the standby has caught up with the primary, by polling
228+
# pg_stat_replication.
229+
my$caughtup_query ="SELECT pg_current_xlog_location() = replay_location FROM pg_stat_replication WHERE application_name = 'rewind_standby';";
230+
poll_query_until($caughtup_query,$connstr_master)
231+
ordie"Timed out while waiting for standby to catch up";
198232
}
199233

200234
subpromote_standby
@@ -203,9 +237,11 @@ sub promote_standby
203237
# up standby
204238

205239
# Now promote slave and insert some new data on master, this will put
206-
# the master out-of-sync with the standby.
240+
# the master out-of-sync with the standby. Wait until the standby is
241+
# out of recovery mode, and is ready to accept read-write connections.
207242
system_or_bail("pg_ctl -w -D$test_standby_datadir promote >>$log_path 2>&1");
208-
sleep 2;
243+
poll_query_until("SELECT NOT pg_is_in_recovery()",$connstr_standby)
244+
ordie"Timed out while waiting for promotion of standby";
209245
}
210246

211247
subrun_pg_rewind

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp