pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Questionable ping logic in LogicalRepApplyLoop
3+ messages / 2 participants
[nested] [flat]

Commits from this thread:
  2020-09-05 9b47ee6e7c 7156a0eac3 9b8a8516ed c8746f999e 9b81a30f92  Fix over-eager ping'ing in logical replication receiver.
* Questionable ping logic in LogicalRepApplyLoop
@ 2020-09-04 19:41  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 3+ messages in thread

From: Tom Lane @ 2020-09-04 19:41 UTC (permalink / raw)
  To: pgsql-hackers@lists.postgresql.org

While playing around with clang's scan-build I noticed this warning:

worker.c:2281:7: warning: Value stored to 'ping_sent' is never read
                                                ping_sent = true;
                                                ^           ~~~~

At first I thought it was a harmless unnecessary update, but looking
closer I wonder whether it isn't telling us there is a logic bug here.
Specifically, I wonder why the "ping_sent" variable is local to the
loop starting at line 2084, rather than having the same lifespan as
"last_recv_timestamp".  Do we really want to forget that we sent a
ping anytime we have to wait for more data?

In fact, looking closer, it appears to me that

(1) The "ping_sent = false" at line 2124 is also dead code, because
ping_sent could never be anything but false at this point;

(2) The "if (!ping_sent)" at line 2274 is also dead code, because
ping_sent is still never anything but false at that point.

In short, we could remove the ping_sent variable entirely without
changing this code's behavior.  I'm not 100% sure what semantics
it's trying to achieve, but I don't think it's achieving them.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Questionable ping logic in LogicalRepApplyLoop
@ 2020-09-04 20:41  Alvaro Herrera <alvherre@2ndquadrant.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 3+ messages in thread

From: Alvaro Herrera @ 2020-09-04 20:41 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-hackers@lists.postgresql.org, Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; Petr Jelinek <petr@2ndquadrant.com>

On 2020-Sep-04, Tom Lane wrote:

> While playing around with clang's scan-build I noticed this warning:
> 
> worker.c:2281:7: warning: Value stored to 'ping_sent' is never read
>                                                 ping_sent = true;
>                                                 ^           ~~~~
> 
> At first I thought it was a harmless unnecessary update, but looking
> closer I wonder whether it isn't telling us there is a logic bug here.
> Specifically, I wonder why the "ping_sent" variable is local to the
> loop starting at line 2084, rather than having the same lifespan as
> "last_recv_timestamp".  Do we really want to forget that we sent a
> ping anytime we have to wait for more data?

Ah ... maybe this bug is the reason why the bug fixed by 470687b4a5bb
did not affect logical replication.

> In short, we could remove the ping_sent variable entirely without
> changing this code's behavior.  I'm not 100% sure what semantics
> it's trying to achieve, but I don't think it's achieving them.

I imagine that moving the variable one block-scope outwards (together
with last_recv_timestamp) is what was intended.

... oh look!  commit 3f60f690fac1 moved last_recv_timestamp without
realizing that ping_sent had to get the same treatment.

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Questionable ping logic in LogicalRepApplyLoop
@ 2020-09-04 21:41  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Alvaro Herrera <alvherre@2ndquadrant.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Tom Lane @ 2020-09-04 21:41 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: pgsql-hackers@lists.postgresql.org, Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; Petr Jelinek <petr@2ndquadrant.com>

Alvaro Herrera <alvherre@2ndquadrant.com> writes:
> ... oh look!  commit 3f60f690fac1 moved last_recv_timestamp without
> realizing that ping_sent had to get the same treatment.

Hah, I wondered if something like that had happened, but I didn't
get around to excavating in the git history yet.  Thanks for doing so.

Will push a fix later.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2020-09-04 21:41 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-09-04 19:41 Questionable ping logic in LogicalRepApplyLoop Tom Lane <tgl@sss.pgh.pa.us>
2020-09-04 20:41 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2020-09-04 21:41   ` Tom Lane <tgl@sss.pgh.pa.us>

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