Skip to content

Commit 4c641d9

Browse files
committed
Backport log_newpage_buffer.
Andres' fix for XLOG_HEAP2_VISIBLE on unitialized pages requires this.
1 parent 6ab834f commit 4c641d9

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

src/backend/access/heap/heapam.c

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4504,10 +4504,9 @@ log_heap_update(Relation reln, Buffer oldbuf, ItemPointerData from,
45044504
* Perform XLogInsert of a HEAP_NEWPAGE record to WAL. Caller is responsible
45054505
* for writing the page to disk after calling this routine.
45064506
*
4507-
* Note: all current callers build pages in private memory and write them
4508-
* directly to smgr, rather than using bufmgr. Therefore there is no need
4509-
* to pass a buffer ID to XLogInsert, nor to perform MarkBufferDirty within
4510-
* the critical section.
4507+
* Note: If you're using this function, you should be building pages in private
4508+
* memory and writing them directly to smgr. If you're using buffers, call
4509+
* log_newpage_buffer instead.
45114510
*
45124511
* Note: the NEWPAGE log record is used for both heaps and indexes, so do
45134512
* not do anything that assumes we are touching a heap.
@@ -4554,6 +4553,53 @@ log_newpage(RelFileNode *rnode, ForkNumber forkNum, BlockNumber blkno,
45544553
return recptr;
45554554
}
45564555

4556+
/*
4557+
* Perform XLogInsert of a HEAP_NEWPAGE record to WAL.
4558+
*
4559+
* Caller should initialize the buffer and mark it dirty before calling this
4560+
* function. This function will set the page LSN and TLI.
4561+
*
4562+
* Note: the NEWPAGE log record is used for both heaps and indexes, so do
4563+
* not do anything that assumes we are touching a heap.
4564+
*/
4565+
XLogRecPtr
4566+
log_newpage_buffer(Buffer buffer)
4567+
{
4568+
xl_heap_newpage xlrec;
4569+
XLogRecPtr recptr;
4570+
XLogRecData rdata[2];
4571+
Page page = BufferGetPage(buffer);
4572+
4573+
/* We should be in a critical section. */
4574+
Assert(CritSectionCount > 0);
4575+
4576+
BufferGetTag(buffer, &xlrec.node, &xlrec.forknum, &xlrec.blkno);
4577+
4578+
rdata[0].data = (char *) &xlrec;
4579+
rdata[0].len = SizeOfHeapNewpage;
4580+
rdata[0].buffer = InvalidBuffer;
4581+
rdata[0].next = &(rdata[1]);
4582+
4583+
rdata[1].data = page;
4584+
rdata[1].len = BLCKSZ;
4585+
rdata[1].buffer = InvalidBuffer;
4586+
rdata[1].next = NULL;
4587+
4588+
recptr = XLogInsert(RM_HEAP_ID, XLOG_HEAP_NEWPAGE, rdata);
4589+
4590+
/*
4591+
* The page may be uninitialized. If so, we can't set the LSN and TLI
4592+
* because that would corrupt the page.
4593+
*/
4594+
if (!PageIsNew(page))
4595+
{
4596+
PageSetLSN(page, recptr);
4597+
PageSetTLI(page, ThisTimeLineID);
4598+
}
4599+
4600+
return recptr;
4601+
}
4602+
45574603
/*
45584604
* Handles CLEANUP_INFO
45594605
*/

src/include/access/heapam.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ extern XLogRecPtr log_heap_visible(RelFileNode rnode, BlockNumber block,
144144
Buffer vm_buffer, TransactionId cutoff_xid);
145145
extern XLogRecPtr log_newpage(RelFileNode *rnode, ForkNumber forkNum,
146146
BlockNumber blk, Page page);
147+
extern XLogRecPtr log_newpage_buffer(Buffer buffer);
147148

148149
/* in heap/pruneheap.c */
149150
extern void heap_page_prune_opt(Relation relation, Buffer buffer,

0 commit comments

Comments
 (0)