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

Commit4fafc4e

Browse files
committed
Cleanup of new b-tree page deletion code.
When marking a branch as half-dead, a pointer to the top of the branch isstored in the leaf block's hi-key. During normal operation, the high keywas left in place, and the block number was just stored in the ctid fieldof the high key tuple, but in WAL replay, the high key was recreated as atruncated tuple with zero columns. For the sake of easier debugging, alsotruncate the tuple in normal operation, so that the page is identicalafter WAL replay. Also, rename the 'downlink' field in the WAL record to'topparent', as that seems like a more descriptive name. And make sureit's set to invalid when unlinking the leaf page.
1 parentd26b042 commit4fafc4e

File tree

4 files changed

+33
-18
lines changed

4 files changed

+33
-18
lines changed

‎src/backend/access/nbtree/nbtpage.c

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,6 +1303,10 @@ _bt_pagedel(Relation rel, Buffer buf)
13031303
returnndeleted;
13041304
}
13051305

1306+
/*
1307+
* First stage of page deletion. Remove the downlink to the top of the
1308+
* branch being deleted, and mark the leaf page as half-dead.
1309+
*/
13061310
staticbool
13071311
_bt_mark_page_halfdead(Relationrel,Bufferleafbuf,BTStackstack)
13081312
{
@@ -1317,6 +1321,7 @@ _bt_mark_page_halfdead(Relation rel, Buffer leafbuf, BTStack stack)
13171321
OffsetNumbertopoff;
13181322
OffsetNumbernextoffset;
13191323
IndexTupleitup;
1324+
IndexTupleDatatrunctuple;
13201325

13211326
page=BufferGetPage(leafbuf);
13221327
opaque= (BTPageOpaque)PageGetSpecialPointer(page);
@@ -1406,12 +1411,17 @@ _bt_mark_page_halfdead(Relation rel, Buffer leafbuf, BTStack stack)
14061411
opaque= (BTPageOpaque)PageGetSpecialPointer(page);
14071412
opaque->btpo_flags |=BTP_HALF_DEAD;
14081413

1409-
itemid=PageGetItemId(page,P_HIKEY);
1410-
itup= (IndexTuple)PageGetItem(page,itemid);
1411-
if (target==leafblkno)
1412-
ItemPointerSetInvalid(&(itup->t_tid));
1414+
PageIndexTupleDelete(page,P_HIKEY);
1415+
Assert(PageGetMaxOffsetNumber(page)==0);
1416+
MemSet(&trunctuple,0,sizeof(IndexTupleData));
1417+
trunctuple.t_info=sizeof(IndexTupleData);
1418+
if (target!=leafblkno)
1419+
ItemPointerSet(&trunctuple.t_tid,target,P_HIKEY);
14131420
else
1414-
ItemPointerSet(&(itup->t_tid),target,P_HIKEY);
1421+
ItemPointerSetInvalid(&trunctuple.t_tid);
1422+
if (PageAddItem(page, (Item)&trunctuple,sizeof(IndexTupleData),P_HIKEY,
1423+
false, false)==InvalidOffsetNumber)
1424+
elog(ERROR,"could not add dummy high key to half-dead page");
14151425

14161426
/* Must mark buffers dirty before XLogInsert */
14171427
MarkBufferDirty(topparent);
@@ -1427,7 +1437,10 @@ _bt_mark_page_halfdead(Relation rel, Buffer leafbuf, BTStack stack)
14271437
xlrec.target.node=rel->rd_node;
14281438
ItemPointerSet(&(xlrec.target.tid),BufferGetBlockNumber(topparent),topoff);
14291439
xlrec.leafblk=leafblkno;
1430-
xlrec.downlink=target;
1440+
if (target!=leafblkno)
1441+
xlrec.topparent=target;
1442+
else
1443+
xlrec.topparent=InvalidBlockNumber;
14311444

14321445
page=BufferGetPage(leafbuf);
14331446
opaque= (BTPageOpaque)PageGetSpecialPointer(page);
@@ -1768,7 +1781,7 @@ _bt_unlink_halfdead_page(Relation rel, Buffer leafbuf, bool *rightsib_empty)
17681781
xlrec.leafblk=leafblkno;
17691782
xlrec.leafleftsib=leafleftsib;
17701783
xlrec.leafrightsib=leafrightsib;
1771-
xlrec.downlink=nextchild;
1784+
xlrec.topparent=nextchild;
17721785

17731786
rdata[0].data= (char*)&xlrec;
17741787
rdata[0].len=SizeOfBtreeUnlinkPage;

‎src/backend/access/nbtree/nbtxlog.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -870,8 +870,8 @@ btree_xlog_mark_page_halfdead(uint8 info, XLogRecPtr lsn, XLogRecord *record)
870870
*/
871871
MemSet(&trunctuple,0,sizeof(IndexTupleData));
872872
trunctuple.t_info=sizeof(IndexTupleData);
873-
if (xlrec->downlink!=InvalidBlockNumber)
874-
ItemPointerSet(&trunctuple.t_tid,xlrec->downlink,P_HIKEY);
873+
if (xlrec->topparent!=InvalidBlockNumber)
874+
ItemPointerSet(&trunctuple.t_tid,xlrec->topparent,P_HIKEY);
875875
else
876876
ItemPointerSetInvalid(&trunctuple.t_tid);
877877
if (PageAddItem(page, (Item)&trunctuple,sizeof(IndexTupleData),P_HIKEY,
@@ -1006,8 +1006,8 @@ btree_xlog_unlink_page(uint8 info, XLogRecPtr lsn, XLogRecord *record)
10061006
/* Add a dummy hikey item */
10071007
MemSet(&trunctuple,0,sizeof(IndexTupleData));
10081008
trunctuple.t_info=sizeof(IndexTupleData);
1009-
if (xlrec->downlink!=InvalidBlockNumber)
1010-
ItemPointerSet(&trunctuple.t_tid,xlrec->downlink,P_HIKEY);
1009+
if (xlrec->topparent!=InvalidBlockNumber)
1010+
ItemPointerSet(&trunctuple.t_tid,xlrec->topparent,P_HIKEY);
10111011
else
10121012
ItemPointerSetInvalid(&trunctuple.t_tid);
10131013
if (PageAddItem(page, (Item)&trunctuple,sizeof(IndexTupleData),P_HIKEY,

‎src/backend/access/rmgrdesc/nbtdesc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ btree_desc(StringInfo buf, uint8 xl_info, char *rec)
130130

131131
appendStringInfoString(buf,"mark_page_halfdead: ");
132132
out_target(buf,&(xlrec->target));
133-
appendStringInfo(buf,";downlink %u; leaf %u; left %u; right %u",
134-
xlrec->downlink,xlrec->leafblk,xlrec->leftblk,xlrec->rightblk);
133+
appendStringInfo(buf,";topparent %u; leaf %u; left %u; right %u",
134+
xlrec->topparent,xlrec->leafblk,xlrec->leftblk,xlrec->rightblk);
135135
break;
136136
}
137137
caseXLOG_BTREE_UNLINK_PAGE_META:
@@ -143,8 +143,8 @@ btree_desc(StringInfo buf, uint8 xl_info, char *rec)
143143
xlrec->node.spcNode,xlrec->node.dbNode,xlrec->node.relNode);
144144
appendStringInfo(buf,"dead %u; left %u; right %u; btpo_xact %u; ",
145145
xlrec->deadblk,xlrec->leftsib,xlrec->rightsib,xlrec->btpo_xact);
146-
appendStringInfo(buf,"leaf %u; leafleft %u; leafright %u;downlink %u",
147-
xlrec->leafblk,xlrec->leafleftsib,xlrec->leafrightsib,xlrec->downlink);
146+
appendStringInfo(buf,"leaf %u; leafleft %u; leafright %u;topparent %u",
147+
xlrec->leafblk,xlrec->leafleftsib,xlrec->leafrightsib,xlrec->topparent);
148148
break;
149149
}
150150
caseXLOG_BTREE_NEWROOT:

‎src/include/access/nbtree.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,13 +379,15 @@ typedef struct xl_btree_vacuum
379379
typedefstructxl_btree_mark_page_halfdead
380380
{
381381
xl_btreetidtarget;/* deleted tuple id in parent page */
382+
383+
/* information needed to recreate the leaf page: */
382384
BlockNumberleafblk;/* leaf block ultimately being deleted */
383385
BlockNumberleftblk;/* leaf block's left sibling, if any */
384386
BlockNumberrightblk;/* leaf block's right sibling */
385-
BlockNumberdownlink;/*next child down in the branch */
387+
BlockNumbertopparent;/*topmost internal page in the branch */
386388
}xl_btree_mark_page_halfdead;
387389

388-
#defineSizeOfBtreeMarkPageHalfDead(offsetof(xl_btree_mark_page_halfdead,downlink) + sizeof(BlockNumber))
390+
#defineSizeOfBtreeMarkPageHalfDead(offsetof(xl_btree_mark_page_halfdead,topparent) + sizeof(BlockNumber))
389391

390392
/*
391393
* This is what we need to know about deletion of a btree page. Note we do
@@ -406,7 +408,7 @@ typedef struct xl_btree_unlink_page
406408
BlockNumberleafblk;
407409
BlockNumberleafleftsib;
408410
BlockNumberleafrightsib;
409-
BlockNumberdownlink;/* next child down in the branch */
411+
BlockNumbertopparent;/* next child down in the branch */
410412

411413
TransactionIdbtpo_xact;/* value of btpo.xact for use in recovery */
412414
/* xl_btree_metadata FOLLOWS IF XLOG_BTREE_UNLINK_PAGE_META */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp