Shortening the Scope of Critical Section in Creation of New MultiXacts

From: "Bagga, Rishu" <bagrishu(at)amazon(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Cc: "Manjunath, Naveen" <manjuzna(at)amazon(dot)com>, "Debnath, Shawn" <sdn(at)amazon(dot)com>, "Paquier, Michael" <paquier(at)amazon(dot)co(dot)jp>, Thomas Munro <thomas(dot)munro(at)gmail(dot)com>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
Subject: Shortening the Scope of Critical Section in Creation of New MultiXacts
Date: 2022-12-14 00:14:34
Message-ID: DEEB7863-5D47-4A5B-9974-DB70BC24E512@amazon.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi all,

I have been going through the multixact code over the last few
weeks, and noticed a potential discrepancy between the need for critical
sections in the creation of new multixacts and the current code.

As per the comment in GetNewMultiXact:

/*
* Critical section from here until caller has written the data into the
* just-reserved SLRU space; we don't want to error out with a partly
* written MultiXact structure. (In particular, failing to write our
* start offset after advancing nextMXact would effectively corrupt the
* previous MultiXact.)
*/
START_CRIT_SECTION()

This makes sense, as we need the multixact state and multixact offset
data to be consistent, but once we write data into the offsets, we can
end the critical section. Currently we wait until the members data is
also written before we end the critical section.

I’ve attached a patch that moves the end of the critical section into
RecordNewMultiXact, right after we finish writing data into the offsets
cache.

This passes regression tests, as well as some custom testing around
injecting random failures while writing multixact members, and
restarting.

I would appreciate any feedback on this.

Sincerely,

Rishu Bagga, Amazon Web Services (AWS)

Attachment Content-Type Size
move_multixact_critical_section.patch application/octet-stream 1.2 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2022-12-14 00:20:14 Re: wake up logical workers after ALTER SUBSCRIPTION
Previous Message Ian Lawrence Barwick 2022-12-14 00:09:51 Re: Proposal for internal Numeric to Uint64 conversion function.