Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6cd015b

Browse files
committed
Add new function log_newpage_buffer.
When I implemented the ginbuildempty() function as part ofimplementing unlogged tables, I falsified the note in the headercomment for log_newpage. Although we could fix that up by changingthe comment, it seems cleaner to add a new function which isspecifically intended to handle this case. So do that.
1 parenta475c60 commit6cd015b

File tree

3 files changed

+54
-13
lines changed

3 files changed

+54
-13
lines changed

‎src/backend/access/gin/gininsert.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -520,20 +520,14 @@ ginbuildempty(PG_FUNCTION_ARGS)
520520
ReadBufferExtended(index,INIT_FORKNUM,P_NEW,RBM_NORMAL,NULL);
521521
LockBuffer(RootBuffer,BUFFER_LOCK_EXCLUSIVE);
522522

523-
/* Initializeboth pages, mark them dirty, unlockandrelease buffer. */
523+
/* Initializeand xlog metabufferandroot buffer. */
524524
START_CRIT_SECTION();
525525
GinInitMetabuffer(MetaBuffer);
526526
MarkBufferDirty(MetaBuffer);
527+
log_newpage_buffer(MetaBuffer);
527528
GinInitBuffer(RootBuffer,GIN_LEAF);
528529
MarkBufferDirty(RootBuffer);
529-
530-
/* XLOG the new pages */
531-
log_newpage(&index->rd_smgr->smgr_rnode.node,INIT_FORKNUM,
532-
BufferGetBlockNumber(MetaBuffer),
533-
BufferGetPage(MetaBuffer));
534-
log_newpage(&index->rd_smgr->smgr_rnode.node,INIT_FORKNUM,
535-
BufferGetBlockNumber(RootBuffer),
536-
BufferGetPage(RootBuffer));
530+
log_newpage_buffer(RootBuffer);
537531
END_CRIT_SECTION();
538532

539533
/* Unlock and release the buffers. */

‎src/backend/access/heap/heapam.c

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4479,10 +4479,9 @@ log_heap_update(Relation reln, Buffer oldbuf, ItemPointerData from,
44794479
* Perform XLogInsert of a HEAP_NEWPAGE record to WAL. Caller is responsible
44804480
* for writing the page to disk after calling this routine.
44814481
*
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.
44864485
*
44874486
* Note: the NEWPAGE log record is used for both heaps and indexes, so do
44884487
* not do anything that assumes we are touching a heap.
@@ -4529,6 +4528,53 @@ log_newpage(RelFileNode *rnode, ForkNumber forkNum, BlockNumber blkno,
45294528
returnrecptr;
45304529
}
45314530

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(Bufferbuffer)
4542+
{
4543+
xl_heap_newpagexlrec;
4544+
XLogRecPtrrecptr;
4545+
XLogRecDatardata[2];
4546+
Pagepage=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+
returnrecptr;
4576+
}
4577+
45324578
/*
45334579
* Handles CLEANUP_INFO
45344580
*/

‎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
Buffervm_buffer,TransactionIdcutoff_xid);
145145
externXLogRecPtrlog_newpage(RelFileNode*rnode,ForkNumberforkNum,
146146
BlockNumberblk,Pagepage);
147+
externXLogRecPtrlog_newpage_buffer(Bufferbuffer);
147148

148149
/* in heap/pruneheap.c */
149150
externvoidheap_page_prune_opt(Relationrelation,Bufferbuffer,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp