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

Commit598a127

Browse files
committed
Call _bt_fixroot() from _bt_insertonpg.
1 parent72401a4 commit598a127

File tree

2 files changed

+60
-5
lines changed

2 files changed

+60
-5
lines changed

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

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.77 2001/01/26 01:24:31 vadim Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.78 2001/01/29 07:28:16 vadim Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -34,7 +34,10 @@ typedef struct
3434
intbest_delta;/* best size delta so far */
3535
}FindSplitData;
3636

37+
externboolFixBTree;
38+
3739
Buffer_bt_fixroot(Relationrel,Bufferoldrootbuf,boolrelease);
40+
staticvoid_bt_fixtree(Relationrel,BlockNumberblkno,BTStackstack);
3841

3942
staticBuffer_bt_newroot(Relationrel,Bufferlbuf,Bufferrbuf);
4043

@@ -477,10 +480,55 @@ _bt_insertonpg(Relation rel,
477480
BTItemritem;
478481
Bufferpbuf;
479482

480-
/*Set up a phony stack entry if we haven't got a real one */
483+
/*If root page was splitted */
481484
if (stack== (BTStack)NULL)
482485
{
483486
elog(DEBUG,"btree: concurrent ROOT page split");
487+
/*
488+
* If root page splitter failed to create new root page
489+
* then old root' btpo_parent still points to metapage.
490+
* We have to fix root page in this case.
491+
*/
492+
if (lpageop->btpo_parent==BTREE_METAPAGE)
493+
{
494+
if (!FixBTree)
495+
elog(ERROR,"bt_insertonpg: no root page found");
496+
_bt_wrtbuf(rel,rbuf);
497+
_bt_wrtnorelbuf(rel,buf);
498+
while(!P_LEFTMOST(lpageop))
499+
{
500+
BlockNumberblkno=lpageop->btpo_prev;
501+
LockBuffer(buf,BUFFER_LOCK_UNLOCK);
502+
ReleaseBuffer(buf);
503+
buf=_bt_getbuf(rel,blkno,BT_WRITE);
504+
page=BufferGetPage(buf);
505+
lpageop= (BTPageOpaque)PageGetSpecialPointer(page);
506+
/*
507+
* If someone else already created parent pages
508+
* then it's time for _bt_fixtree() to check upper
509+
* levels and fix them, if required.
510+
*/
511+
if (lpageop->btpo_parent!=BTREE_METAPAGE)
512+
{
513+
blkno=lpageop->btpo_parent;
514+
_bt_relbuf(rel,buf,BT_WRITE);
515+
_bt_fixtree(rel,blkno,NULL);
516+
gotoformres;
517+
}
518+
}
519+
/*
520+
* Ok, we are on the leftmost page, it's write locked
521+
* by us and its btpo_parent points to meta page - time
522+
* for _bt_fixroot().
523+
*/
524+
buf=_bt_fixroot(rel,buf, true);
525+
_bt_relbuf(rel,buf,BT_WRITE);
526+
gotoformres;
527+
}
528+
529+
/*
530+
* Set up a phony stack entry if we haven't got a real one
531+
*/
484532
stack=&fakestack;
485533
stack->bts_blkno=lpageop->btpo_parent;
486534
stack->bts_offset=InvalidOffsetNumber;
@@ -537,6 +585,7 @@ _bt_insertonpg(Relation rel,
537585
_bt_wrtbuf(rel,buf);
538586
}
539587

588+
formres:;
540589
/* by here, the new tuple is inserted at itup_blkno/itup_off */
541590
res= (InsertIndexResult)palloc(sizeof(InsertIndexResultData));
542591
ItemPointerSet(&(res->pointerData),itup_blkno,itup_off);
@@ -1414,8 +1463,7 @@ _bt_fixroot(Relation rel, Buffer oldrootbuf, bool release)
14141463
* created with _bt_newroot() - rootbuf, - and buf we've used
14151464
* for last insert ops - buf. If rootbuf != buf then we have to
14161465
* create at least one more level. And if "release" is TRUE
1417-
* (ie we've already created some levels) then we give up
1418-
* oldrootbuf.
1466+
* then we give up oldrootbuf.
14191467
*/
14201468
if (release)
14211469
_bt_relbuf(rel,oldrootbuf,BT_WRITE);
@@ -1429,6 +1477,12 @@ _bt_fixroot(Relation rel, Buffer oldrootbuf, bool release)
14291477
return(rootbuf);
14301478
}
14311479

1480+
staticvoid
1481+
_bt_fixtree(Relationrel,BlockNumberblkno,BTStackstack)
1482+
{
1483+
elog(ERROR,"bt_fixtree: unimplemented , yet");
1484+
}
1485+
14321486
/*
14331487
*_bt_pgaddtup() -- add a tuple to a particular page in the index.
14341488
*

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtpage.c,v 1.48 2001/01/26 01:24:31 vadim Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtpage.c,v 1.49 2001/01/29 07:28:17 vadim Exp $
1313
*
1414
*NOTES
1515
* Postgres btree pages look like ordinary relation pages.The opaque
@@ -257,6 +257,7 @@ check_parent:;
257257
/* handle concurrent fix of root page */
258258
if (rootopaque->btpo_parent==BTREE_METAPAGE)/* unupdated! */
259259
{
260+
elog(NOTICE,"bt_getroot: fixing root page");
260261
newrootbuf=_bt_fixroot(rel,rootbuf, true);
261262
LockBuffer(newrootbuf,BUFFER_LOCK_UNLOCK);
262263
LockBuffer(newrootbuf,BT_READ);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp