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: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>, Andres
Freund <andres@anarazel.de>
Cc: 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: 2023-10-25T00:15:19Z
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
On Sat, 2023-10-21 at 23:59 +0530, Bharath Rupireddy wrote: > I'm attaching v12 patch set with just pgperltidy ran on the new TAP > test added in 0002. No other changes from that of v11 patch set. Thank you. Comments: * It would be good to document that this is partially an optimization (read from memory first) and partially an API difference that allows reading unflushed data. For instance, walsender may benefit performance-wise (and perhaps later with the ability to read unflushed data) whereas pg_walinspect benefits primarily from reading unflushed data. * Shouldn't there be a new method in XLogReaderRoutine (e.g. read_unflushed_data), rather than having logic in WALRead()? The callers can define the method if it makes sense (and that would be a good place to document why); or leave it NULL if not. * I'm not clear on the "partial hit" case. Wouldn't that mean you found the earliest byte in the buffers, but not the latest byte requested? Is that possible, and if so under what circumstances? I added an "Assert(nread == 0 || nread == count)" in WALRead() after calling XLogReadFromBuffers(), and it wasn't hit. * If the partial hit case is important, wouldn't XLogReadFromBuffers() fill in the end of the buffer rather than the beginning? * Other functions that use xlblocks, e.g. GetXLogBuffer(), use more effort to avoid acquiring WALBufMappingLock. Perhaps you can avoid it, too? One idea is to check that XLogCtl->xlblocks[idx] is equal to expectedEndPtr both before and after the memcpy(), with appropriate barriers. That could mitigate concerns expressed by Kyotaro Horiguchi and Masahiko Sawada. * Are you sure that reducing the number of calls to memcpy() is a win? I would expect that to be true only if the memcpy()s are tiny, but here they are around XLOG_BLCKSZ. I believe this was done based on a comment from Nathan Bossart, but I didn't really follow why that's important. Also, if we try to use one memcpy for all of the data, it might not interact well with my idea above to avoid taking the lock. * Style-wise, the use of "unlikely" seems excessive, unless there's a reason to think it matters. Regards, Jeff Davis