summaryrefslogtreecommitdiff
path: root/src/backend/replication/walsender.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2020-11-10 22:51:19 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2020-11-10 22:51:55 -0500
commit171c457cd06051b5910cf357ea6a77643b69088a (patch)
treee9be6ac40eaaf181061b8dc5da22f50788fee8cf /src/backend/replication/walsender.c
parent1393acb3836d32e512801bb00f0cc6b4d2a58dc8 (diff)
Fix and simplify some usages of TimestampDifference().
Introduce TimestampDifferenceMilliseconds() to simplify callers that would rather have the difference in milliseconds, instead of the select()-oriented seconds-and-microseconds format. This gets rid of at least one integer division per call, and it eliminates some apparently-easy-to-mess-up arithmetic. Two of these call sites were in fact wrong: * pg_prewarm's autoprewarm_main() forgot to multiply the seconds by 1000, thus ending up with a delay 1000X shorter than intended. That doesn't quite make it a busy-wait, but close. * postgres_fdw's pgfdw_get_cleanup_result() thought it needed to compute microseconds not milliseconds, thus ending up with a delay 1000X longer than intended. Somebody along the way had noticed this problem but misdiagnosed the cause, and imposed an ad-hoc 60-second limit rather than fixing the units. This was relatively harmless in context, because we don't care that much about exactly how long this delay is; still, it's wrong. There are a few more callers of TimestampDifference() that don't have a direct need for seconds-and-microseconds, but can't use TimestampDifferenceMilliseconds() either because they do need microsecond precision or because they might possibly deal with intervals long enough to overflow 32-bit milliseconds. It might be worth inventing another API to improve that, but that seems outside the scope of this patch; so those callers are untouched here. Given the fact that we are fixing some bugs, and the likelihood that future patches might want to back-patch code that uses this new API, back-patch to all supported branches. Alexey Kondratov and Tom Lane Discussion: https://postgr.es/m/3b1c053a21c07c1ed5e00be3b2b855ef@postgrespro.ru
Diffstat (limited to 'src/backend/replication/walsender.c')
-rw-r--r--src/backend/replication/walsender.c8
1 files changed, 1 insertions, 7 deletions
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index dc4b86ba683..86e6f4e433b 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -2079,8 +2079,6 @@ WalSndComputeSleeptime(TimestampTz now)
if (wal_sender_timeout > 0 && last_reply_timestamp > 0)
{
TimestampTz wakeup_time;
- long sec_to_timeout;
- int microsec_to_timeout;
/*
* At the latest stop sleeping once wal_sender_timeout has been
@@ -2099,11 +2097,7 @@ WalSndComputeSleeptime(TimestampTz now)
wal_sender_timeout / 2);
/* Compute relative time until wakeup. */
- TimestampDifference(now, wakeup_time,
- &sec_to_timeout, &microsec_to_timeout);
-
- sleeptime = sec_to_timeout * 1000 +
- microsec_to_timeout / 1000;
+ sleeptime = TimestampDifferenceMilliseconds(now, wakeup_time);
}
return sleeptime;