Skip to content

Commit eda4ef8

Browse files
committed
stats regression test's wait_for_stats() must check timestamp too.
pg_stat_get_snapshot_timestamp() returns the timestamp seen in the "global" stats file. Because pgstat_write_statsfiles() writes per-DB stats files before the global file (or at least before renaming it into place), there is a window where the test backend can see all the stats updates that wait_for_stats() was checking for (all of which come from the per-DB file) but also see the same global stats file it had seen at the start of the test script. This results in a failure in only the "snapshot_newer" query, as reported by a couple of buildfarm members recently. I suspect that this ought to be back-patched. Commit 4e37b3e has evidently increased the probability of this window getting hit, but it's not apparent why it could not have been hit before. I'll refrain for the moment though.
1 parent de7cca9 commit eda4ef8

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/test/regress/expected/stats.out

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ declare
3232
updated1 bool;
3333
updated2 bool;
3434
updated3 bool;
35+
updated4 bool;
3536
begin
3637
-- we don't want to wait forever; loop will exit after 30 seconds
3738
for i in 1 .. 300 loop
@@ -55,7 +56,13 @@ begin
5556
SELECT (n_tup_ins > 0) INTO updated3
5657
FROM pg_stat_user_tables WHERE relname='trunc_stats_test4';
5758

58-
exit when updated1 and updated2 and updated3;
59+
-- We must also check explicitly that pg_stat_get_snapshot_timestamp has
60+
-- advanced, because that comes from the global stats file which might
61+
-- be older than the per-DB stats file we got the other values from.
62+
SELECT (pr.snap_ts < pg_stat_get_snapshot_timestamp()) INTO updated4
63+
FROM prevstats AS pr;
64+
65+
exit when updated1 and updated2 and updated3 and updated4;
5966

6067
-- wait a little
6168
perform pg_sleep_for('100 milliseconds');

src/test/regress/sql/stats.sql

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ declare
3131
updated1 bool;
3232
updated2 bool;
3333
updated3 bool;
34+
updated4 bool;
3435
begin
3536
-- we don't want to wait forever; loop will exit after 30 seconds
3637
for i in 1 .. 300 loop
@@ -54,7 +55,13 @@ begin
5455
SELECT (n_tup_ins > 0) INTO updated3
5556
FROM pg_stat_user_tables WHERE relname='trunc_stats_test4';
5657

57-
exit when updated1 and updated2 and updated3;
58+
-- We must also check explicitly that pg_stat_get_snapshot_timestamp has
59+
-- advanced, because that comes from the global stats file which might
60+
-- be older than the per-DB stats file we got the other values from.
61+
SELECT (pr.snap_ts < pg_stat_get_snapshot_timestamp()) INTO updated4
62+
FROM prevstats AS pr;
63+
64+
exit when updated1 and updated2 and updated3 and updated4;
5865

5966
-- wait a little
6067
perform pg_sleep_for('100 milliseconds');

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy