@@ -4479,10 +4479,9 @@ log_heap_update(Relation reln, Buffer oldbuf, ItemPointerData from,
4479
4479
* Perform XLogInsert of a HEAP_NEWPAGE record to WAL. Caller is responsible
4480
4480
* for writing the page to disk after calling this routine.
4481
4481
*
4482
- * Note: all current callers build pages in private memory and write them
4483
- * directly to smgr, rather than using bufmgr. Therefore there is no need
4484
- * to pass a buffer ID to XLogInsert, nor to perform MarkBufferDirty within
4485
- * the critical section.
4482
+ * Note: If you're using this function, you should be building pages in private
4483
+ * memory and writing them directly to smgr. If you're using buffers, call
4484
+ * log_newpage_buffer instead.
4486
4485
*
4487
4486
* Note: the NEWPAGE log record is used for both heaps and indexes, so do
4488
4487
* not do anything that assumes we are touching a heap.
@@ -4529,6 +4528,53 @@ log_newpage(RelFileNode *rnode, ForkNumber forkNum, BlockNumber blkno,
4529
4528
return recptr ;
4530
4529
}
4531
4530
4531
+ /*
4532
+ * Perform XLogInsert of a HEAP_NEWPAGE record to WAL.
4533
+ *
4534
+ * Caller should initialize the buffer and mark it dirty before calling this
4535
+ * function. This function will set the page LSN and TLI.
4536
+ *
4537
+ * Note: the NEWPAGE log record is used for both heaps and indexes, so do
4538
+ * not do anything that assumes we are touching a heap.
4539
+ */
4540
+ XLogRecPtr
4541
+ log_newpage_buffer (Buffer buffer )
4542
+ {
4543
+ xl_heap_newpage xlrec ;
4544
+ XLogRecPtr recptr ;
4545
+ XLogRecData rdata [2 ];
4546
+ Page page = BufferGetPage (buffer );
4547
+
4548
+ /* We should be in a critical section. */
4549
+ Assert (CritSectionCount > 0 );
4550
+
4551
+ BufferGetTag (buffer , & xlrec .node , & xlrec .forknum , & xlrec .blkno );
4552
+
4553
+ rdata [0 ].data = (char * ) & xlrec ;
4554
+ rdata [0 ].len = SizeOfHeapNewpage ;
4555
+ rdata [0 ].buffer = InvalidBuffer ;
4556
+ rdata [0 ].next = & (rdata [1 ]);
4557
+
4558
+ rdata [1 ].data = page ;
4559
+ rdata [1 ].len = BLCKSZ ;
4560
+ rdata [1 ].buffer = InvalidBuffer ;
4561
+ rdata [1 ].next = NULL ;
4562
+
4563
+ recptr = XLogInsert (RM_HEAP_ID , XLOG_HEAP_NEWPAGE , rdata );
4564
+
4565
+ /*
4566
+ * The page may be uninitialized. If so, we can't set the LSN and TLI
4567
+ * because that would corrupt the page.
4568
+ */
4569
+ if (!PageIsNew (page ))
4570
+ {
4571
+ PageSetLSN (page , recptr );
4572
+ PageSetTLI (page , ThisTimeLineID );
4573
+ }
4574
+
4575
+ return recptr ;
4576
+ }
4577
+
4532
4578
/*
4533
4579
* Handles CLEANUP_INFO
4534
4580
*/
0 commit comments