Fix memory context of NeonWALReader allocation.

Allocating it in short living context is wrong because it is reused during
backend lifetime.
This commit is contained in:
Arseny Sher
2024-07-11 19:14:49 +03:00
committed by Arseny Sher
parent 814c8e8f68
commit cd29156927
2 changed files with 11 additions and 4 deletions

View File

@@ -109,11 +109,12 @@ NeonWALReaderAllocate(int wal_segment_size, XLogRecPtr available_lsn, char *log_
{
NeonWALReader *reader;
/*
* Note: we allocate in TopMemoryContext, reusing the reader for all process
* reads.
*/
reader = (NeonWALReader *)
palloc_extended(sizeof(NeonWALReader),
MCXT_ALLOC_NO_OOM | MCXT_ALLOC_ZERO);
if (!reader)
return NULL;
MemoryContextAllocZero(TopMemoryContext, sizeof(NeonWALReader));
reader->available_lsn = available_lsn;
reader->seg.ws_file = -1;

View File

@@ -247,6 +247,12 @@ FROM generate_series(1, 16384) AS seq; -- Inserts enough rows to exceed 16MB of
cur.execute(
"SELECT * FROM pg_logical_slot_peek_binary_changes('slotty_mcslotface', NULL, NULL, 'include-xids', '0')"
)
# do the peek second time: we've had a bug using wrong memory context
# for NeonWALReader leading to the crash in this case.
log.info("peek_changes again")
cur.execute(
"SELECT * FROM pg_logical_slot_peek_binary_changes('slotty_mcslotface', NULL, NULL, 'include-xids', '0')"
)
# Tests that walsender correctly blocks until WAL is downloaded from safekeepers