Re: IPC/MultixactCreation on the Standby server

From: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
To: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Cc: Álvaro Herrera <alvherre(at)kurilemu(dot)de>, pgsql-hackers(at)lists(dot)postgresql(dot)org, Andrey Borodin <x4mmm(at)yandex-team(dot)ru>, Ivan Bykov <i(dot)bykov(at)modernsys(dot)ru>, Kirill Reshke <reshkekirill(at)gmail(dot)com>
Subject: Re: IPC/MultixactCreation on the Standby server
Date: 2025-11-27 07:24:51
Message-ID: d37cede1-d3e9-4792-ba29-a2802c1961c2@iki.fi
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 27/11/2025 05:39, Chao Li wrote:
>> <v11-0001-Avoid-multixact-edge-case-2-by-writing-the-next-.patch>
>
> 1
> ```
> + if (*offptr != offset)
> + {
> + /* should already be set to the correct value, or not at all */
> + Assert(*offptr == 0);
> + *offptr = offset;
> + MultiXactOffsetCtl->shared->page_dirty[slotno] = true;
> + }
> ```
>
> This is a more like a question. Since pre-write should always happen, in theory *offptr != offset should never be true, why do we still need to handle the case instead of just assert(false)?

No, *offptr == 0 can happen, if multiple backends are generating
multixids concurrently. It's possible that we get here before the
RecordNewMultiXact() call for the previous multixid.

Similarly, the *next_offptr != 0 case can happen if another backend
calls RecordNewMultiXact() concurrently for the next multixid.

> 2
> ```
> + next = multi + 1;
> + if (next < FirstMultiXactId)
> + next = FirstMultiXactId;
> ```
>
> next < FirstMultiXactId will only be true when next wraps around to 0, maybe deserve one-line comment to explain that.

This is a common pattern used in many places in the file.

> 3
> ```
> + if (*next_offptr != offset + nmembers)
> + {
> + /* should already be set to the correct value, or not at all */
> + Assert(*next_offptr == 0);
> + *next_offptr = offset + nmembers;
> + MultiXactMemberCtl->shared->page_dirty[slotno] = true;
> + }
> ```
>
> Should MultiXactMemberCtl be MultiXactOffsetCtl? As we are writing to the offset SLRU.

Good catch! Yes, it should be MultiXactOffsetCtl.

- Heikki

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Heikki Linnakangas 2025-11-27 07:35:14 Re: Move WAL/RMGR sequence code into its own file and header
Previous Message Heikki Linnakangas 2025-11-27 07:20:24 Re: IPC/MultixactCreation on the Standby server