On Tue, Oct 28, 2025 at 07:33:00PM +0900, Shinya Kato wrote:
> I investigated previous discussions and found [0]. This thread
> mentioned that XLogInsert() calls XLogRecordAssemble() multiple times
> in its do-while loop, so the value might be invalid.
>
> Based on the discussion above, it seems my previous patch also has the
> same issue.
>
> [0] https://www.postgresql.org/message-id/20200329121944.GA79261%40nol
Dammit, you are right. I didn't see through this one. Even on HEAD
it is true that we may trigger an early exit of XLogInsertRecord() and
call XLogRecordAssemble() multiple times with a different FPI setup.
So we cannot do direct manipulations of pgWalUsage in
XLogRecordAssemble(), we must do these once the record is inserted.
I'll clean up that tomorrow, which can be summarized as something like
the attached (quick fix, need to double-check).
--
Michael