@@ -4504,10 +4504,9 @@ log_heap_update(Relation reln, Buffer oldbuf, ItemPointerData from,
4504
4504
* Perform XLogInsert of a HEAP_NEWPAGE record to WAL. Caller is responsible
4505
4505
* for writing the page to disk after calling this routine.
4506
4506
*
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.
4511
4510
*
4512
4511
* Note: the NEWPAGE log record is used for both heaps and indexes, so do
4513
4512
* not do anything that assumes we are touching a heap.
@@ -4554,6 +4553,53 @@ log_newpage(RelFileNode *rnode, ForkNumber forkNum, BlockNumber blkno,
4554
4553
return recptr ;
4555
4554
}
4556
4555
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
+
4557
4603
/*
4558
4604
* Handles CLEANUP_INFO
4559
4605
*/
0 commit comments