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

Commitc91a9b5

Browse files
committed
Fix backup-block numbering in redo of b-tree split.
I got the backup block numbers off-by-one in the commit that changed theway incomplete-splits are handled. I blame the comments, which said"backup block 1" and "backup block 2", even though the backup blocksare numbered starting from 0, in the macros and functions used in replay.Fix the comments and the code.Per Jeff Janes' bug report about corruption caused by torn page writes.The incorrect code is new in git master, but backpatch the comment changedown to 9.0, where the numbering in the redo-side macros was changed.
1 parenteb56812 commitc91a9b5

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,7 @@ _bt_split(Relation rel, Buffer buf, Buffer cbuf, OffsetNumber firstright,
12991299

13001300
lastrdata->data= (char*)newitem;
13011301
lastrdata->len=MAXALIGN(newitemsz);
1302-
lastrdata->buffer=buf;/* backup block1 */
1302+
lastrdata->buffer=buf;/* backup block0 */
13031303
lastrdata->buffer_std= true;
13041304
}
13051305

@@ -1320,7 +1320,7 @@ _bt_split(Relation rel, Buffer buf, Buffer cbuf, OffsetNumber firstright,
13201320
item= (IndexTuple)PageGetItem(origpage,itemid);
13211321
lastrdata->data= (char*)item;
13221322
lastrdata->len=MAXALIGN(IndexTupleSize(item));
1323-
lastrdata->buffer=buf;/* backup block1 */
1323+
lastrdata->buffer=buf;/* backup block0 */
13241324
lastrdata->buffer_std= true;
13251325
}
13261326

@@ -1333,11 +1333,11 @@ _bt_split(Relation rel, Buffer buf, Buffer cbuf, OffsetNumber firstright,
13331333
* Although we don't need to WAL-log anything on the left page, we
13341334
* still need XLogInsert to consider storing a full-page image of
13351335
* the left page, so make an empty entry referencing that buffer.
1336-
* This also ensures that the left page is always backup block1.
1336+
* This also ensures that the left page is always backup block0.
13371337
*/
13381338
lastrdata->data=NULL;
13391339
lastrdata->len=0;
1340-
lastrdata->buffer=buf;/* backup block1 */
1340+
lastrdata->buffer=buf;/* backup block0 */
13411341
lastrdata->buffer_std= true;
13421342
}
13431343

@@ -1353,7 +1353,7 @@ _bt_split(Relation rel, Buffer buf, Buffer cbuf, OffsetNumber firstright,
13531353
cblkno=BufferGetBlockNumber(cbuf);
13541354
lastrdata->data= (char*)&cblkno;
13551355
lastrdata->len=sizeof(BlockNumber);
1356-
lastrdata->buffer=cbuf;/* backup block2 */
1356+
lastrdata->buffer=cbuf;/* backup block1 */
13571357
lastrdata->buffer_std= true;
13581358
}
13591359

@@ -1386,7 +1386,7 @@ _bt_split(Relation rel, Buffer buf, Buffer cbuf, OffsetNumber firstright,
13861386

13871387
lastrdata->data=NULL;
13881388
lastrdata->len=0;
1389-
lastrdata->buffer=sbuf;/* bkp block2 (leaf) or3 (non-leaf) */
1389+
lastrdata->buffer=sbuf;/* bkp block1 (leaf) or2 (non-leaf) */
13901390
lastrdata->buffer_std= true;
13911391
}
13921392

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,8 @@ btree_xlog_split(bool onleft, bool isroot,
300300
*/
301301
if (!isleaf)
302302
{
303-
if (record->xl_info&XLR_BKP_BLOCK(2))
304-
(void)RestoreBackupBlock(lsn,record,2, false, false);
303+
if (record->xl_info&XLR_BKP_BLOCK(1))
304+
(void)RestoreBackupBlock(lsn,record,1, false, false);
305305
else
306306
_bt_clear_incomplete_split(lsn,record,xlrec->node,cblkno);
307307
}
@@ -439,10 +439,10 @@ btree_xlog_split(bool onleft, bool isroot,
439439
if (xlrec->rnext!=P_NONE)
440440
{
441441
/*
442-
* the backup block containing right sibling is2 or3, depending
442+
* the backup block containing right sibling is1 or2, depending
443443
* whether this was a leaf or internal page.
444444
*/
445-
intrnext_index=isleaf ?2 :3;
445+
intrnext_index=isleaf ?1 :2;
446446

447447
if (record->xl_info&XLR_BKP_BLOCK(rnext_index))
448448
(void)RestoreBackupBlock(lsn,record,rnext_index, false, false);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp