Re: IPC/MultixactCreation on the Standby server

Heikki Linnakangas <hlinnaka@iki.fi>

From: Heikki Linnakangas <hlinnaka@iki.fi>
To: Chao Li <li.evan.chao@gmail.com>
Cc: Álvaro Herrera <alvherre@kurilemu.de>, pgsql-hackers@lists.postgresql.org, Andrey Borodin <x4mmm@yandex-team.ru>, Ivan Bykov <i.bykov@modernsys.ru>, Kirill Reshke <reshkekirill@gmail.com>
Date: 2025-11-27T07:24:51Z
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




Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Fix test to work with non-8kB block sizes

  2. Fix setting next multixid's offset at offset wraparound

  3. Add test for multixid wraparound

  4. Set next multixid's offset when creating a new multixid

  5. psql: Improve tab completion for large objects.

  6. Refactor some repetitive SLRU code

  7. Transaction IDs wrap around, per my proposal of 13-Aug-01. More