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

Commit 08186dc

Browse files
committed
Move _bt_upgrademetapage() into critical section.
Any changes on page should be done in critical section, so move _bt_upgrademetapage into critical section. Improve comment. Found by Amit Kapila during post-commit review of 857f9c3. Author: Amit Kapila
1 parent 3c9cf06 commit 08186dc

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

src/backend/access/nbtree/nbtinsert.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -2150,10 +2150,6 @@ _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf)
21502150
metapg = BufferGetPage(metabuf);
21512151
metad = BTPageGetMeta(metapg);
21522152

2153-
/* upgrade metapage if needed */
2154-
if (metad->btm_version < BTREE_VERSION)
2155-
_bt_upgrademetapage(metapg);
2156-
21572153
/*
21582154
* Create downlink item for left page (old root). Since this will be the
21592155
* first item in a non-leaf page, it implicitly has minus-infinity key
@@ -2178,6 +2174,10 @@ _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf)
21782174
/* NO EREPORT(ERROR) from here till newroot op is logged */
21792175
START_CRIT_SECTION();
21802176

2177+
/* upgrade metapage if needed */
2178+
if (metad->btm_version < BTREE_VERSION)
2179+
_bt_upgrademetapage(metapg);
2180+
21812181
/* set btree special data */
21822182
rootopaque = (BTPageOpaque) PageGetSpecialPointer(rootpage);
21832183
rootopaque->btpo_prev = rootopaque->btpo_next = P_NONE;

src/backend/access/nbtree/nbtpage.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -341,10 +341,6 @@ _bt_getroot(Relation rel, int access)
341341
LockBuffer(metabuf, BUFFER_LOCK_UNLOCK);
342342
LockBuffer(metabuf, BT_WRITE);
343343

344-
/* upgrade metapage if needed */
345-
if (metad->btm_version < BTREE_VERSION)
346-
_bt_upgrademetapage(metapg);
347-
348344
/*
349345
* Race condition: if someone else initialized the metadata between
350346
* the time we released the read lock and acquired the write lock, we
@@ -379,6 +375,10 @@ _bt_getroot(Relation rel, int access)
379375
/* NO ELOG(ERROR) till meta is updated */
380376
START_CRIT_SECTION();
381377

378+
/* upgrade metapage if needed */
379+
if (metad->btm_version < BTREE_VERSION)
380+
_bt_upgrademetapage(metapg);
381+
382382
metad->btm_root = rootblkno;
383383
metad->btm_level = 0;
384384
metad->btm_fastroot = rootblkno;

src/include/access/nbtree.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ typedef struct BTMetaPageData
103103
BlockNumber btm_fastroot; /* current "fast" root location */
104104
uint32 btm_fastlevel; /* tree level of the "fast" root page */
105105
/* following fields are available since page version 3 */
106-
TransactionId btm_oldest_btpo_xact; /* oldest btpo_xact among of deleted
106+
TransactionId btm_oldest_btpo_xact; /* oldest btpo_xact among all deleted
107107
* pages */
108108
float8 btm_last_cleanup_num_heap_tuples; /* number of heap tuples
109109
* during last cleanup */

0 commit comments

Comments
 (0)