Skip to content

Commit c8a38d5

Browse files
committed
Added check is new item successfuly inserted to a page or not.
1 parent 8d1f52e commit c8a38d5

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

src/backend/access/nbtree/nbtinsert.c

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.14 1997/05/31 06:35:56 vadim Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.15 1997/06/06 03:11:42 vadim Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -488,7 +488,8 @@ _bt_insertonpg(Relation rel,
488488
upditem_offset = P_FIRSTKEY;
489489
if ( !P_LEFTMOST(lpageop) ||
490490
stack->bts_offset != upditem_offset )
491-
elog (FATAL, "btree: items are out of order");
491+
elog (FATAL, "btree: items are out of order (leftmost %d, stack %u, update %u)",
492+
P_LEFTMOST(lpageop), stack->bts_offset, upditem_offset);
492493
}
493494
/*
494495
* There was bug caused by deletion all minimum keys (K1) from
@@ -682,7 +683,8 @@ _bt_split(Relation rel, Buffer buf, BTItem hiRightItem)
682683
+ (sizeof(BTItemData) - sizeof(IndexTupleData));
683684
itemsz = DOUBLEALIGN(itemsz);
684685
}
685-
(void) PageAddItem(rightpage, (Item) item, itemsz, P_HIKEY, LP_USED);
686+
if ( PageAddItem(rightpage, (Item) item, itemsz, P_HIKEY, LP_USED) == InvalidOffsetNumber )
687+
elog (FATAL, "btree: failed to add hikey to the right sibling");
686688
rightoff = P_FIRSTKEY;
687689
} else {
688690
/* splitting a rightmost page, "high key" is the first data item */
@@ -702,12 +704,14 @@ _bt_split(Relation rel, Buffer buf, BTItem hiRightItem)
702704

703705
/* decide which page to put it on */
704706
if (i < firstright) {
705-
(void) PageAddItem(leftpage, (Item) item, itemsz, leftoff,
706-
LP_USED);
707+
if ( PageAddItem(leftpage, (Item) item, itemsz, leftoff,
708+
LP_USED) == InvalidOffsetNumber )
709+
elog (FATAL, "btree: failed to add item to the left sibling");
707710
leftoff = OffsetNumberNext(leftoff);
708711
} else {
709-
(void) PageAddItem(rightpage, (Item) item, itemsz, rightoff,
710-
LP_USED);
712+
if ( PageAddItem(rightpage, (Item) item, itemsz, rightoff,
713+
LP_USED) == InvalidOffsetNumber )
714+
elog (FATAL, "btree: failed to add item to the right sibling");
711715
rightoff = OffsetNumberNext(rightoff);
712716
}
713717
}
@@ -735,7 +739,8 @@ _bt_split(Relation rel, Buffer buf, BTItem hiRightItem)
735739
*/
736740

737741
PageManagerModeSet(OverwritePageManagerMode);
738-
(void) PageAddItem(leftpage, (Item) item, itemsz, P_HIKEY, LP_USED);
742+
if ( PageAddItem(leftpage, (Item) item, itemsz, P_HIKEY, LP_USED) == InvalidOffsetNumber )
743+
elog (FATAL, "btree: failed to add hikey to the left sibling");
739744
PageManagerModeSet(ShufflePageManagerMode);
740745

741746
/*
@@ -913,7 +918,8 @@ _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf)
913918
* page is the rightmost page on its level so the "high key" item
914919
* is the first data item.
915920
*/
916-
(void) PageAddItem(rootpage, (Item) new_item, itemsz, P_HIKEY, LP_USED);
921+
if ( PageAddItem(rootpage, (Item) new_item, itemsz, P_HIKEY, LP_USED) == InvalidOffsetNumber )
922+
elog (FATAL, "btree: failed to add leftkey to new root page");
917923
pfree(new_item);
918924

919925
/*
@@ -929,7 +935,8 @@ _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf)
929935
/*
930936
* insert the right page pointer into the new root page.
931937
*/
932-
(void) PageAddItem(rootpage, (Item) new_item, itemsz, P_FIRSTKEY, LP_USED);
938+
if ( PageAddItem(rootpage, (Item) new_item, itemsz, P_FIRSTKEY, LP_USED) == InvalidOffsetNumber )
939+
elog (FATAL, "btree: failed to add rightkey to new root page");
933940
pfree(new_item);
934941

935942
/* write and let go of the root buffer */
@@ -981,7 +988,8 @@ _bt_pgaddtup(Relation rel,
981988
} while ( ! BTItemSame (chkitem, afteritem) );
982989
}
983990

984-
(void) PageAddItem(page, (Item) btitem, itemsize, itup_off, LP_USED);
991+
if ( PageAddItem(page, (Item) btitem, itemsize, itup_off, LP_USED) == InvalidOffsetNumber )
992+
elog (FATAL, "btree: failed to add item to the page");
985993

986994
/* write the buffer, but hold our lock */
987995
_bt_wrtnorelbuf(rel, buf);
@@ -1325,14 +1333,16 @@ _bt_shift (Relation rel, Buffer buf, BTStack stack, int keysz,
13251333
itemsz = IndexTupleDSize(hikey->bti_itup)
13261334
+ (sizeof(BTItemData) - sizeof(IndexTupleData));
13271335
itemsz = DOUBLEALIGN(itemsz);
1328-
(void) PageAddItem(page, (Item) hikey, itemsz, P_HIKEY, LP_USED);
1336+
if ( PageAddItem(page, (Item) hikey, itemsz, P_HIKEY, LP_USED) == InvalidOffsetNumber )
1337+
elog (FATAL, "btree: failed to add hikey in _bt_shift");
13291338
pfree (hikey);
13301339

13311340
/* add btitem */
13321341
itemsz = IndexTupleDSize(btitem->bti_itup)
13331342
+ (sizeof(BTItemData) - sizeof(IndexTupleData));
13341343
itemsz = DOUBLEALIGN(itemsz);
1335-
(void) PageAddItem(page, (Item) btitem, itemsz, P_FIRSTKEY, LP_USED);
1344+
if ( PageAddItem(page, (Item) btitem, itemsz, P_FIRSTKEY, LP_USED) == InvalidOffsetNumber )
1345+
elog (FATAL, "btree: failed to add firstkey in _bt_shift");
13361346
pfree (btitem);
13371347
nitem = (BTItem) PageGetItem(page, PageGetItemId(page, P_FIRSTKEY));
13381348
btitem = _bt_formitem(&(nitem->bti_itup));

src/backend/access/nbtree/nbtsort.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
*
77
* IDENTIFICATION
8-
* $Id: nbtsort.c,v 1.16 1997/05/30 18:35:40 vadim Exp $
8+
* $Id: nbtsort.c,v 1.17 1997/06/06 03:11:46 vadim Exp $
99
*
1010
* NOTES
1111
*
@@ -938,8 +938,9 @@ _bt_buildadd(Relation index, void *pstate, BTItem bti, int flags)
938938
o <= last_off;
939939
o = OffsetNumberNext(o), n = OffsetNumberNext(n)) {
940940
ii = PageGetItemId(opage, o);
941-
(void) PageAddItem(npage, PageGetItem(opage, ii),
942-
ii->lp_len, n, LP_USED);
941+
if ( PageAddItem(npage, PageGetItem(opage, ii),
942+
ii->lp_len, n, LP_USED) == InvalidOffsetNumber )
943+
elog (FATAL, "btree: failed to add item to the page in _bt_sort (1)");
943944
#if 0
944945
#if defined(FASTBUILD_DEBUG) && defined(FASTBUILD_MERGE)
945946
{
@@ -1021,7 +1022,8 @@ _bt_buildadd(Relation index, void *pstate, BTItem bti, int flags)
10211022
* new chain of duplicates.
10221023
*/
10231024
off = OffsetNumberNext(last_off);
1024-
(void) PageAddItem(npage, (Item) bti, btisz, off, LP_USED);
1025+
if ( PageAddItem(npage, (Item) bti, btisz, off, LP_USED) == InvalidOffsetNumber )
1026+
elog (FATAL, "btree: failed to add item to the page in _bt_sort (2)");
10251027
#if 0
10261028
#if defined(FASTBUILD_DEBUG) && defined(FASTBUILD_MERGE)
10271029
{

0 commit comments

Comments
 (0)