Re: Improve WALRead() to suck data directly from WAL buffers when possible
Jeff Davis <pgsql@j-davis.com>
From: Jeff Davis <pgsql@j-davis.com>
To: Andres Freund <andres@anarazel.de>
Cc: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>, 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-14T01:29:47Z
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
- 0001-Add-assert-to-WALReadFromBuffers.patch (text/x-patch) patch 0001
- 0002-WALReadFromBuffers-read-end-of-the-requested-range.patch (text/x-patch) patch 0002
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. Maybe we should just get rid of that code entirely and trust the caller to request a reasonable range? On Mon, 2024-02-12 at 17:33 -0800, Jeff Davis wrote: > That makes me wonder whether my previous idea[1] might matter: when > some buffers have been evicted, should WALReadFromBuffers() keep > going > through the loop and return the end portion of the requested data > rather than the beginning? > [1] > https://www.postgresql.org/message-id/2b36bf99e762e65db0dafbf8d338756cf5fa6ece.camel@j-davis.com 0002 is to illustrate the above idea. It's a strange API so I don't intend to commit it in this form, but I think we will ultimately need to do something like it when we want to replicate unflushed data. The idea is that data past the Write pointer is always (and only) available in the WAL buffers, so WALReadFromBuffers() should always return it. That way we can always safely fall through to ordinary WALRead(), which can only see before the Write pointer. There's also data before the Write pointer that could be in the WAL buffers, and we might as well copy that, too, if it's not evicted. If some buffers are evicted, it will fill in the *end* of the buffer, leaving a gap at the beginning. The nice thing is that if there is any gap, it will be before the Write pointer, so we can always fall back to WALRead() to fill the gap and it should always succeed. Regards, Jeff Davis