Re: Improve WALRead() to suck data directly from WAL buffers when possible
Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
From: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
To: Jeff Davis <pgsql@j-davis.com>
Cc: Andres Freund <andres@anarazel.de>,
Alvaro Herrera <alvherre@alvh.no-ip.org>, Dilip Kumar <dilipbalaut@gmail.com>,
Kyotaro Horiguchi <horikyota.ntt@gmail.com>, pgsql-hackers@lists.postgresql.org,
Nathan Bossart <nathandbossart@gmail.com>, Masahiko Sawada <sawada.mshk@gmail.com>
Date: 2024-02-16T07:38:45Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Add XLogCtl->logInsertResult
- f3ff7bf83bce 17.0 cited
-
Add assert to WALReadFromBuffers().
- 9ecbf54075a9 17.0 landed
-
Read WAL directly from WAL buffers.
- 91f2cae7a4e6 17.0 landed
-
Additional write barrier in AdvanceXLInsertBuffer().
- 766571be1659 17.0 landed
-
Use 64-bit atomics for xlblocks array elements.
- c3a8e2a7cb16 17.0 landed
-
Don't trust unvalidated xl_tot_len.
- bae868caf222 17.0 cited
Attachments
- v23-0002-Add-test-module-for-verifying-read-from-WAL-buff.patch (application/x-patch) patch v23-0002
- v23-0004-Do-away-with-zero-padding-assumption-before-WALR.patch (application/x-patch) patch v23-0004
- v23-0003-Use-WALReadFromBuffers-in-more-places.patch (application/x-patch) patch v23-0003
- v23-0001-Add-check-in-WALReadFromBuffers-against-requeste.patch (application/x-patch) patch v23-0001
- v23-0005-Demonstrate-page_read-callback-for-reading-from-.patch (application/x-patch) patch v23-0005
On Wed, Feb 14, 2024 at 6:59 AM Jeff Davis <pgsql@j-davis.com> wrote: > > Attached 2 patches. > > Per Andres's suggestion, 0001 adds an: > Assert(startptr + count <= LogwrtResult.Write) > > Though if we want to allow the caller (e.g. in an extension) to > determine the valid range, perhaps using WaitXLogInsertionsToFinish(), > then the check is wrong. Right. > Maybe we should just get rid of that code > entirely and trust the caller to request a reasonable range? I'd suggest we strike a balance here - error out in assert builds if startptr+count is past the current insert position and trust the callers for production builds. It has a couple of advantages over doing just Assert(startptr + count <= LogwrtResult.Write): 1) It allows the caller to read unflushed WAL directly from WAL buffers, see the attached 0005 for an example. 2) All the existing callers where WALReadFromBuffers() is thought to be used are ensuring WAL availability by reading upto the flush position so no problem with it. Also, a note before WALRead() stating the caller must request the WAL at least that's written out (upto LogwrtResult.Write). I'm not so sure about this, perhaps, we don't need this comment at all. Here, I'm with v23 patch set: 0001 - Adds assertion in WALReadFromBuffers() to ensure the requested WAL isn't beyond the current insert position. 0002 - Adds a new test module to demonstrate how one can use WALReadFromBuffers() ensuring WaitXLogInsertionsToFinish() if need be. 0003 - Uses WALReadFromBuffers in more places like logical walsenders and backends. 0004 - Removes zero-padding related stuff as discussed in https://www.postgresql.org/message-id/CALj2ACWBRFac2TingD3PE3w2EBHXUHY3=AEEZPJmqhpEOBGExg@mail.gmail.com. This is needed in this patch set otherwise the assertion added in 0001 fails after 0003. 0005 - Adds a page_read callback for reading from WAL buffers in the new test module added in 0002. Also, adds tests. Thoughts? -- Bharath Rupireddy PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com