Re: pg_logical_slot_get_changes waits continously for a partial WAL record spanning across 2 pages

Michael Paquier <michael@paquier.xyz>

From: Michael Paquier <michael@paquier.xyz>
To: Dilip Kumar <dilipbalaut@gmail.com>
Cc: vignesh C <vignesh21@gmail.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>, Alexander Korotkov <aekorotkov@gmail.com>, Tom Lane <tgl@sss.pgh.pa.us>, Amit Kapila <amit.kapila16@gmail.com>, Melanie Plageman <melanieplageman@gmail.com>
Date: 2025-06-26T06:17:32Z
Lists: pgsql-hackers
On Thu, Jun 26, 2025 at 08:48:32AM +0530, Dilip Kumar wrote:
> On Thu, Jun 26, 2025 at 6:22 AM Michael Paquier <michael@paquier.xyz> wrote:
>> So you are suggesting the addition of an extra ReadPageInternal() that
>> forces a read of only the read, perform the checks on the header, then
>> read the rest.  After reading SizeOfXLogShortPHD worth of data,
>> shouldn't the checks on xlp_rem_len be done a bit earlier than what
>> you are proposing in this patch?
> 
> I did not get the point, IMHO it has to be validated after the record
> on the next page has been read.

As proposed in the patch, the first ReadPageInternal() reads 
SizeOfXLogShortPHD worth of data (right?), so we should have access to
XLogPageHeaderData.xlp_rem_len before attempting the second
ReadPageInternal() worth Min(total_len - gotlen + SizeOfXLogShortPHD,
XLOG_BLCKSZ) of data.  The check that fails with a "invalid contrecord
length %u" relies on xlp_rem_len, total_len, RecPtr and gotlen.  We
know all this information before the second ReadPageInternal().
--
Michael

Commits

  1. Fix infinite wait when reading a partially written WAL record

  2. Improve the stability of the recovery test 047_checkpoint_physical_slot

  3. Improve recovery test 046_checkpoint_logical_slot