Skip to content

Commit ea18eb7

Browse files
committed
Revise pg_walsummary's 002_blocks test to avoid spurious failures.
Analysis of buildfarm results showed that the code that was intended to wait for the inserts performed by this test to complete did not actually do so. Try to make that logic more robust. Improve error checking elsewhere in the script, too, so that we don't miss things like poll_query_until failing. Along the way, fix a bit of pgindent damage introduced by commit 5ddf997, which aimed to help us debug the failures that this commit is trying to fix. It's making the buildfarm sad. Discussion: http://postgr.es/m/CA+TgmobWFb8NqyfC31YnKAbZiXf9tLuwmyuvx=iYMXMniPQ4nw@mail.gmail.com
1 parent d028338 commit ea18eb7

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

src/backend/backup/walsummary.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ RemoveWalSummaryIfOlderThan(WalSummaryFile *ws, time_t cutoff_time)
258258
#else
259259
ereport(LOG,
260260
(errmsg_internal("removing file \"%s\" cutoff_time=%llu", path,
261-
(unsigned long long) cutoff_time)));
261+
(unsigned long long) cutoff_time)));
262262
#endif
263263
}
264264

src/bin/pg_walsummary/t/002_blocks.pl

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@
1313
$node1->append_conf('postgresql.conf', 'summarize_wal = on');
1414
$node1->start;
1515

16-
# See what's been summarized up until now.
17-
my $progress = $node1->safe_psql('postgres', <<EOM);
18-
SELECT summarized_tli, summarized_lsn FROM pg_get_wal_summarizer_state()
19-
EOM
20-
my ($summarized_tli, $summarized_lsn) = split(/\|/, $progress);
21-
note("before insert, summarized TLI $summarized_tli through $summarized_lsn");
22-
2316
# Create a table and insert a few test rows into it. VACUUM FREEZE it so that
2417
# autovacuum doesn't induce any future modifications unexpectedly. Then
2518
# trigger a checkpoint.
@@ -31,22 +24,33 @@
3124
FROM
3225
generate_series(1, 400) g;
3326
VACUUM FREEZE;
27+
EOM
28+
29+
# Record the current WAL insert LSN.
30+
my $base_lsn = $node1->safe_psql('postgres', <<EOM);
31+
SELECT pg_current_wal_insert_lsn()
32+
EOM
33+
note("just after insert, WAL insert LSN is $base_lsn");
34+
35+
# Now perform a CHECKPOINT.
36+
$node1->safe_psql('postgres', <<EOM);
3437
CHECKPOINT;
3538
EOM
3639

37-
# Wait for a new summary to show up.
38-
$node1->poll_query_until('postgres', <<EOM);
40+
# Wait for a new summary to show up, one that includes the inserts we just did.
41+
my $result = $node1->poll_query_until('postgres', <<EOM);
3942
SELECT EXISTS (
4043
SELECT * from pg_available_wal_summaries()
41-
WHERE tli = $summarized_tli AND end_lsn > '$summarized_lsn'
44+
WHERE end_lsn >= '$base_lsn'
4245
)
4346
EOM
47+
ok($result, "WAL summarization caught up after insert");
4448

45-
# Again check the progress of WAL summarization.
46-
$progress = $node1->safe_psql('postgres', <<EOM);
49+
# Get a list of what summaries we now have.
50+
my $progress = $node1->safe_psql('postgres', <<EOM);
4751
SELECT summarized_tli, summarized_lsn FROM pg_get_wal_summarizer_state()
4852
EOM
49-
($summarized_tli, $summarized_lsn) = split(/\|/, $progress);
53+
my ($summarized_tli, $summarized_lsn) = split(/\|/, $progress);
5054
note("after insert, summarized TLI $summarized_tli through $summarized_lsn");
5155
note_wal_summary_dir("after insert", $node1);
5256

@@ -56,20 +60,23 @@
5660
CHECKPOINT;
5761
EOM
5862

59-
# Again wait for a new summary to show up.
60-
$node1->poll_query_until('postgres', <<EOM);
63+
# Wait for a new summary to show up.
64+
$result = $node1->poll_query_until('postgres', <<EOM);
6165
SELECT EXISTS (
6266
SELECT * from pg_available_wal_summaries()
6367
WHERE tli = $summarized_tli AND end_lsn > '$summarized_lsn'
6468
)
6569
EOM
70+
ok($result, "got new WAL summary after update");
6671

6772
# Figure out the exact details for the new summary file.
6873
my $details = $node1->safe_psql('postgres', <<EOM);
6974
SELECT tli, start_lsn, end_lsn from pg_available_wal_summaries()
7075
WHERE tli = $summarized_tli AND end_lsn > '$summarized_lsn'
7176
EOM
72-
my ($tli, $start_lsn, $end_lsn) = split(/\|/, $details);
77+
my @lines = split(/\n/, $details);
78+
is(0+@lines, 1, "got exactly one new WAL summary");
79+
my ($tli, $start_lsn, $end_lsn) = split(/\|/, $lines[0]);
7380
note("examining summary for TLI $tli from $start_lsn to $end_lsn");
7481
note_wal_summary_dir("after new summary", $node1);
7582

@@ -81,12 +88,14 @@
8188
ok(-f $filename, "WAL summary file exists");
8289
note_wal_summary_dir("after existence check", $node1);
8390

84-
# Run pg_walsummary on it. We expect block 0 to be modified, but depending
85-
# on where the new tuple ends up, block 1 might also be modified, so we
86-
# pass -i to pg_walsummary to make sure we don't end up with a 0..1 range.
91+
# Run pg_walsummary on it. We expect exactly two blocks to be modified,
92+
# block 0 and one other.
8793
my ($stdout, $stderr) = run_command([ 'pg_walsummary', '-i', $filename ]);
94+
note($stdout);
95+
@lines = split(/\n/, $stdout);
8896
like($stdout, qr/FORK main: block 0$/m, "stdout shows block 0 modified");
8997
is($stderr, '', 'stderr is empty');
98+
is(0+@lines, 2, "UPDATE modified 2 blocks");
9099
note_wal_summary_dir("after pg_walsummary run", $node1);
91100

92101
done_testing();

0 commit comments

Comments
 (0)