pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Nathan Bossart <nathandbossart@gmail.com>
To: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Cc: zhjwpku@gmail.com
Cc: xu.xw2008@163.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #17903: There is a bug in the KeepLogSeg()
Date: Thu, 20 Apr 2023 15:02:42 -0700
Message-ID: <20230420220242.GB1435672@nathanxps13> (raw)
In-Reply-To: <20230420.175814.1157027125103997227.horikyota.ntt@gmail.com>
References: <17903-4288d439dee856c6@postgresql.org>
	<20230420.120417.1609083651022565895.horikyota.ntt@gmail.com>
	<CAEG8a3L2BB5k9USO4fC_wQjULGX-1rqaX2JSHn1_0vco8KB28Q@mail.gmail.com>
	<20230420.175814.1157027125103997227.horikyota.ntt@gmail.com>

On Thu, Apr 20, 2023 at 05:58:14PM +0900, Kyotaro Horiguchi wrote:
> +		/*
> +		 * Slot minimum LSN could be greater than recptr. In such cases, no
> +		 * segments are protected by slots but we still need to keep segno in a
> +		 * reasonable range for subsequent calculations to avoid underflow.
> +		 */
> +		if (segno > currSegNo)
> +			segno = currSegNo;
> +

I wonder if it'd be better to instead change

	if (currSegNo - segno > slot_keep_segs)
to
	if (currSegNo > segno + slot_keep_segs)

and

	if (currSegNo - segno < keep_segs)
to
	if (currSegNo < segNo + keep_segs)

If segno > currSegNo, the first conditional would be false as expected, and
the second would be true as expected.  We could also use
pg_sub_u64_overflow() to detect underflow, but that might be excessive in
this case.

-- 
Nathan Bossart
Amazon Web Services: https://aws.amazon.com





view thread (13+ messages)  latest in thread

Message-ID: <20230420220242.GB1435672@nathanxps13>
Permalink:  ../20230420220242.GB1435672@nathanxps13/
Also on:    postgresql.org/message-id/20230420220242.GB1435672@nathanxps13

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: nathandbossart@gmail.com, horikyota.ntt@gmail.com, zhjwpku@gmail.com, xu.xw2008@163.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #17903: There is a bug in the KeepLogSeg()
  In-Reply-To: <20230420220242.GB1435672@nathanxps13>

* 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