Re: XID formatting and SLRU refactorings (was: Add 64-bit XIDs into PostgreSQL 15) - Mailing list pgsql-hackers

From Alexander Korotkov
Subject Re: XID formatting and SLRU refactorings (was: Add 64-bit XIDs into PostgreSQL 15)
Date
Msg-id CAPpHfdu3YRGVvfFTLWoiVXGD5ZXSBY-MXqwmP1UErz9-Yf1CDQ@mail.gmail.com
Whole thread Raw
In response to Re: XID formatting and SLRU refactorings (was: Add 64-bit XIDs into PostgreSQL 15)  (Aleksander Alekseev <aleksander@timescale.com>)
List pgsql-hackers
On Mon, Nov 6, 2023 at 4:38 PM Aleksander Alekseev <aleksander@timescale.com> wrote:
> > > PFE the corrected patchset v58.
> >
> > I'd like to revive this thread.
>
> Many thanks for your comments and suggestions.
>
> > I think it worth adding asserts here to verify there is no overflow making us mapping different segments into the same files.
>
> Sorry, I didn't understand this one. Maybe you could provide the exact code?

I actually meant this.

static int  inline
SlruFileName(SlruCtl ctl, char *path, int64 segno)
{
    if (ctl->long_segment_names)
    {
        /*
         * We could use 16 characters here but the disadvantage would be that
         * the SLRU segments will be hard to distinguish from WAL segments.
         *
         * For this reason we use 15 characters. It is enough but also means
         * that in the future we can't decrease SLRU_PAGES_PER_SEGMENT easily.
         */
        Assert(segno >= 0 && segno <= 0x1000000000000000);
        return snprintf(path, MAXPGPATH, "%s/%015llX", ctl->Dir,
                        (long long) segno);
    }
    else
    {
        Assert(segno >= 0 && segno <= 0x10000);
        return snprintf(path, MAXPGPATH, "%s/%04X", (ctl)->Dir,
                        (unsigned int) segno);
    }
}

As I now get, snprintf() wouldn't just truncate the high signs, instead it will use more characters.  But I think assertions are useful anyway.

------
Regards,
Alexander Korotkov

pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Fix search_path for all maintenance commands
Next
From: Matthias van de Meent
Date:
Subject: Re: Optimizing nbtree ScalarArrayOp execution, allowing multi-column ordered scans, skip scan