Misuse of TimestampDifference() in the autoprewarm feature of pg_prewarm
Alexey Kondratov <a.kondratov@postgrespro.ru>
From: Alexey Kondratov <a.kondratov@postgrespro.ru>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Cc: Robert Haas <robertmhaas@gmail.com>
Date: 2020-11-09T16:45:18Z
Lists: pgsql-hackers
Attachments
- v1-0003-pg_prewarm-refactor-autoprewarm-waits.patch (text/x-diff) patch v1-0003
- v1-0002-pg_prewarm-fix-autoprewarm_interval-behaviour.patch (text/x-diff) patch v1-0002
- v1-0001-pg_prewarm-add-tap-test-for-autoprewarm-feature.patch (text/x-diff) patch v1-0001
Hi Hackers, Today I have accidentally noticed that autoprewarm feature of pg_prewarm used TimestampDifference()'s results in a wrong way. First, it used *seconds* result from it as a *milliseconds*. It was causing it to make dump file autoprewarm.blocks ~every second with default setting of autoprewarm_interval = 300s. Here is a log part with debug output in this case: ``` 2020-11-09 19:09:00.162 MSK [85328] LOG: dumping autoprewarm.blocks 2020-11-09 19:09:01.161 MSK [85328] LOG: dumping autoprewarm.blocks 2020-11-09 19:09:02.160 MSK [85328] LOG: dumping autoprewarm.blocks 2020-11-09 19:09:03.159 MSK [85328] LOG: dumping autoprewarm.blocks ``` After fixing this issue I have noticed that it still dumps blocks twice at each timeout (here I set autoprewarm_interval to 15s): ``` 2020-11-09 19:18:59.692 MSK [85662] LOG: dumping autoprewarm.blocks 2020-11-09 19:18:59.700 MSK [85662] LOG: dumping autoprewarm.blocks 2020-11-09 19:19:14.694 MSK [85662] LOG: dumping autoprewarm.blocks 2020-11-09 19:19:14.704 MSK [85662] LOG: dumping autoprewarm.blocks ``` This happens because at timeout time we were using continue, but actually we still have to wait the entire autoprewarm_interval after successful dumping. I have fixed both issues in the attached patches and also added a minimalistic tap test as a first one to verify that this automatic damping still works after refactoring. I put Robert into CC, since he is an author of this feature. What do you think? Regards -- Alexey Kondratov Postgres Professional https://www.postgrespro.com Russian Postgres Company
Commits
-
Fix and simplify some usages of TimestampDifference().
- 210564a74409 9.5.25 landed
- e87139b43345 10.16 landed
- cd39c23a21ac 9.6.21 landed
- 3a89ea0eb64a 11.11 landed
- afce7908d706 13.2 landed
- 171c457cd060 12.6 landed
- ec29427ce2a4 14.0 landed