From 8002c591c208199501b8a0b0548efd96f663fc29 Mon Sep 17 00:00:00 2001 From: Konstantin Knizhnik Date: Wed, 16 Jul 2025 17:38:28 +0300 Subject: [PATCH] Update pgxn/neon/communicator.c Co-authored-by: Matthias van de Meent --- pgxn/neon/communicator.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/pgxn/neon/communicator.c b/pgxn/neon/communicator.c index d4ed9db3dd..d9fe54fe07 100644 --- a/pgxn/neon/communicator.c +++ b/pgxn/neon/communicator.c @@ -1132,24 +1132,20 @@ prefetch_do_request(PrefetchRequest *slot, neon_request_lsns *force_request_lsns static bool check_page_lsn(NeonGetPageResponse* resp, XLogRecPtr* replay_lsn_ptr) { - if (RecoveryInProgress()) - { - XLogRecPtr page_lsn = PageGetLSN((Page)resp->page); -#if PG_MAJORVERSION_NUM >= 15 - XLogRecPtr replay_lsn = GetCurrentReplayRecPtr(NULL); -#else - /* - * PG14 doesn't have GetCurrentReplayRecPtr() function which returns end of currently applied record. - * And GetXLogReplayRecPtr returns end of WAL records which was already applied. - * So we have to use this hack with resp->req.lsn which is expected to contain end record ptr in this case. - * But it works onlyfor v3 protocol version. - */ - XLogRecPtr replay_lsn = Max(GetXLogReplayRecPtr(NULL), resp->req.hdr.lsn); -#endif - if (replay_lsn_ptr) - *replay_lsn_ptr = replay_lsn; - return replay_lsn == 0 || page_lsn <= replay_lsn; - } + PageHeaderData data; + /* move the data to a known aligned place: resp->page may not be correctly aligned */ + memcpy(&data, resp->page, sizeof(PageHeaderData)); + + if (data.pd_lsn > resp->hdr.not_modified_since) + elog(PANIC, "Invalid getpage response version: %X/%08X is higher than last modified LSN %X/%08X", + LSN_FORMAT_ARGS(data.pd_lsn), + LSN_FORMAT_ARGS(resp->hdr.not_modified_since)); + + if (data.pd_lsn > resp->hdr.lsn) + elog(PANIC, "Invalid getpage response version: %X/%08X is higher than request LSN %X/%08X", + LSN_FORMAT_ARGS(data.pd_lsn), + LSN_FORMAT_ARGS(resp->hdr.lsn)); + return true; }