Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 7b37f4b

Browse files
Correct more obsolete nbtree page split comments.
Commit 3f34283 corrected obsolete comments about buffer locks at the main _bt_insert_parent() call site, but missed similar obsolete comments above _bt_insert_parent() itself. Both sets of comments were rendered obsolete by commit 40dae7e, which made the nbtree page split algorithm more robust. Fix the comments that were missed the first time around now. In passing, refine a related _bt_insert_parent() comment about re-finding the parent page to insert new downlink.
1 parent 8309eae commit 7b37f4b

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/backend/access/nbtree/nbtinsert.c

+13-9
Original file line numberDiff line numberDiff line change
@@ -1687,13 +1687,15 @@ _bt_split(Relation rel, BTScanInsert itup_key, Buffer buf, Buffer cbuf,
16871687
}
16881688

16891689
/*
1690-
* _bt_insert_parent() -- Insert downlink into parent after a page split.
1690+
* _bt_insert_parent() -- Insert downlink into parent, completing split.
16911691
*
16921692
* On entry, buf and rbuf are the left and right split pages, which we
1693-
* still hold write locks on per the L&Y algorithm. We release the
1694-
* write locks once we have write lock on the parent page. (Any sooner,
1695-
* and it'd be possible for some other process to try to split or delete
1696-
* one of these pages, and get confused because it cannot find the downlink.)
1693+
* still hold write locks on. Both locks will be released here. We
1694+
* release the rbuf lock once we have a write lock on the page that we
1695+
* intend to insert a downlink to rbuf on (i.e. buf's current parent page).
1696+
* The lock on buf is released at the same point as the lock on the parent
1697+
* page, since buf's INCOMPLETE_SPLIT flag must be cleared by the same
1698+
* atomic operation that completes the split by inserting a new downlink.
16971699
*
16981700
* stack - stack showing how we got here. Will be NULL when splitting true
16991701
* root, or during concurrent root split, where we can be inefficient
@@ -1771,11 +1773,13 @@ _bt_insert_parent(Relation rel,
17711773
BTreeInnerTupleSetDownLink(new_item, rbknum);
17721774

17731775
/*
1774-
* Find the parent buffer and get the parent page.
1776+
* Re-find and write lock the parent of buf.
17751777
*
1776-
* Oops - if we were moved right then we need to change stack item! We
1777-
* want to find parent pointing to where we are, right ? - vadim
1778-
* 05/27/97
1778+
* It's possible that the location of buf's downlink has changed
1779+
* since our initial _bt_search() descent. _bt_getstackbuf() will
1780+
* detect and recover from this, updating the stack, which ensures
1781+
* that the new downlink will be inserted at the correct offset.
1782+
* Even buf's parent may have changed.
17791783
*/
17801784
stack->bts_btentry = bknum;
17811785
pbuf = _bt_getstackbuf(rel, stack);

0 commit comments

Comments
 (0)