Misuse of TimestampDifference() in the autoprewarm feature of pg_prewarm - Mailing list pgsql-hackers

From Alexey Kondratov
Subject Misuse of TimestampDifference() in the autoprewarm feature of pg_prewarm
Date
Msg-id 3b1c053a21c07c1ed5e00be3b2b855ef@postgrespro.ru
Whole thread Raw
Responses Re: Misuse of TimestampDifference() in the autoprewarm feature of pg_prewarm  (Jeevan Ladhe <jeevan.ladhe@enterprisedb.com>)
Re: Misuse of TimestampDifference() in the autoprewarm feature of pg_prewarm  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
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
Attachment

pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: PATCH: Report libpq version and configuration
Next
From: "David G. Johnston"
Date:
Subject: Re: Disable WAL logging to speed up data loading