Add circular WAL decoding buffer, take II.

Enterprise / PostgreSQL - Thomas Munro [] - 18 March 2022 05:45 UTC

Teach xlogreader.c to decode the WAL into a circular buffer. This will support optimizations based on looking ahead, to follow in a later commit.

- XLogReadRecord() works as before, decoding records one by one, and allowing them to be examined via the traditional XLogRecGetXXX() macros and certain traditional members like xlogreader->ReadRecPtr.

- An alternative new interface XLogReadAhead()/XLogNextRecord() is added that returns pointers to DecodedXLogRecord objects so that it's now possible to look ahead in the WAL stream while replaying.

- In order to be able to use the new interface effectively while streaming data, support is added for the page_read() callback to respond to a new nonblocking mode with XLREAD_WOULDBLOCK instead of waiting for more data to arrive.

No direct user of the new interface is included in this commit, though XLogReadRecord() uses it internally. Existing code doesn't need to change, except in a few places where it was accessing reader internals directly and now needs to go through accessor macros.

3f1ce97346 Add circular WAL decoding buffer, take II.
src/backend/access/transam/generic_xlog.c | 6 +-
src/backend/access/transam/xlog.c | 18 +-
src/backend/access/transam/xlogreader.c | 645 ++++++++++++++++++++++++------
src/backend/access/transam/xlogrecovery.c | 4 +-
src/backend/access/transam/xlogutils.c | 2 +-
src/backend/replication/logical/decode.c | 2 +-
src/bin/pg_rewind/parsexlog.c | 2 +-
src/bin/pg_waldump/pg_waldump.c | 25 +-
src/include/access/xlogreader.h | 154 +++++--
src/tools/pgindent/typedefs.list | 2 +
10 files changed, 686 insertions(+), 174 deletions(-)


  • Share