pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix and simplify some usages of TimestampDifference().
Date: Wed, 11 Nov 2020 03:52:19 +0000
Message-ID: <E1kchBD-0007el-Fc@gemulon.postgresql.org> (raw)

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

Branch
------
REL_13_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/afce7908d7062d94ac60fd4de5f98aaed134c2c7

Modified Files
--------------
contrib/pg_prewarm/autoprewarm.c           | 12 ++---
contrib/postgres_fdw/connection.c          |  9 +---
src/backend/access/transam/xlog.c          | 85 +++++++++++-------------------
src/backend/replication/walreceiverfuncs.c | 25 ++-------
src/backend/replication/walsender.c        |  8 +--
src/backend/utils/adt/timestamp.c          | 38 +++++++++++--
src/include/utils/timestamp.h              |  2 +
7 files changed, 80 insertions(+), 99 deletions(-)



view thread (7+ messages)  latest in thread

Message-ID: <E1kchBD-0007el-Fc@gemulon.postgresql.org>
Permalink:  ../E1kchBD-0007el-Fc@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1kchBD-0007el-Fc@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Fix and simplify some usages of TimestampDifference().
  In-Reply-To: <E1kchBD-0007el-Fc@gemulon.postgresql.org>
  References: <E1kchBD-0007el-Fc@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox