mirror of
https://github.com/postgres/postgres.git
synced 2025-05-31 00:01:57 -04:00
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 857f9c36. Author: Amit Kapila
This commit is contained in:
parent
3c9cf06945
commit
08186dc05b
@ -2150,10 +2150,6 @@ _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf)
|
|||||||
metapg = BufferGetPage(metabuf);
|
metapg = BufferGetPage(metabuf);
|
||||||
metad = BTPageGetMeta(metapg);
|
metad = BTPageGetMeta(metapg);
|
||||||
|
|
||||||
/* upgrade metapage if needed */
|
|
||||||
if (metad->btm_version < BTREE_VERSION)
|
|
||||||
_bt_upgrademetapage(metapg);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create downlink item for left page (old root). Since this will be the
|
* Create downlink item for left page (old root). Since this will be the
|
||||||
* first item in a non-leaf page, it implicitly has minus-infinity key
|
* 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)
|
|||||||
/* NO EREPORT(ERROR) from here till newroot op is logged */
|
/* NO EREPORT(ERROR) from here till newroot op is logged */
|
||||||
START_CRIT_SECTION();
|
START_CRIT_SECTION();
|
||||||
|
|
||||||
|
/* upgrade metapage if needed */
|
||||||
|
if (metad->btm_version < BTREE_VERSION)
|
||||||
|
_bt_upgrademetapage(metapg);
|
||||||
|
|
||||||
/* set btree special data */
|
/* set btree special data */
|
||||||
rootopaque = (BTPageOpaque) PageGetSpecialPointer(rootpage);
|
rootopaque = (BTPageOpaque) PageGetSpecialPointer(rootpage);
|
||||||
rootopaque->btpo_prev = rootopaque->btpo_next = P_NONE;
|
rootopaque->btpo_prev = rootopaque->btpo_next = P_NONE;
|
||||||
|
@ -341,10 +341,6 @@ _bt_getroot(Relation rel, int access)
|
|||||||
LockBuffer(metabuf, BUFFER_LOCK_UNLOCK);
|
LockBuffer(metabuf, BUFFER_LOCK_UNLOCK);
|
||||||
LockBuffer(metabuf, BT_WRITE);
|
LockBuffer(metabuf, BT_WRITE);
|
||||||
|
|
||||||
/* upgrade metapage if needed */
|
|
||||||
if (metad->btm_version < BTREE_VERSION)
|
|
||||||
_bt_upgrademetapage(metapg);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Race condition: if someone else initialized the metadata between
|
* Race condition: if someone else initialized the metadata between
|
||||||
* the time we released the read lock and acquired the write lock, we
|
* the time we released the read lock and acquired the write lock, we
|
||||||
@ -379,6 +375,10 @@ _bt_getroot(Relation rel, int access)
|
|||||||
/* NO ELOG(ERROR) till meta is updated */
|
/* NO ELOG(ERROR) till meta is updated */
|
||||||
START_CRIT_SECTION();
|
START_CRIT_SECTION();
|
||||||
|
|
||||||
|
/* upgrade metapage if needed */
|
||||||
|
if (metad->btm_version < BTREE_VERSION)
|
||||||
|
_bt_upgrademetapage(metapg);
|
||||||
|
|
||||||
metad->btm_root = rootblkno;
|
metad->btm_root = rootblkno;
|
||||||
metad->btm_level = 0;
|
metad->btm_level = 0;
|
||||||
metad->btm_fastroot = rootblkno;
|
metad->btm_fastroot = rootblkno;
|
||||||
|
@ -103,7 +103,7 @@ typedef struct BTMetaPageData
|
|||||||
BlockNumber btm_fastroot; /* current "fast" root location */
|
BlockNumber btm_fastroot; /* current "fast" root location */
|
||||||
uint32 btm_fastlevel; /* tree level of the "fast" root page */
|
uint32 btm_fastlevel; /* tree level of the "fast" root page */
|
||||||
/* following fields are available since page version 3 */
|
/* following fields are available since page version 3 */
|
||||||
TransactionId btm_oldest_btpo_xact; /* oldest btpo_xact among of deleted
|
TransactionId btm_oldest_btpo_xact; /* oldest btpo_xact among all deleted
|
||||||
* pages */
|
* pages */
|
||||||
float8 btm_last_cleanup_num_heap_tuples; /* number of heap tuples
|
float8 btm_last_cleanup_num_heap_tuples; /* number of heap tuples
|
||||||
* during last cleanup */
|
* during last cleanup */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user