Re: BUG #17903: There is a bug in the KeepLogSeg() - Mailing list pgsql-bugs

From Nathan Bossart
Subject Re: BUG #17903: There is a bug in the KeepLogSeg()
Date
Msg-id 20230420220242.GB1435672@nathanxps13
Whole thread Raw
In response to Re: BUG #17903: There is a bug in the KeepLogSeg()  (Kyotaro Horiguchi <horikyota.ntt@gmail.com>)
Responses Re: BUG #17903: There is a bug in the KeepLogSeg()
List pgsql-bugs
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



pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: Assert failure with ICU support
Next
From: Tom Lane
Date:
Subject: Re: BUG #17898: Build failure when strip is LLVM's version