aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/nbtree/nbtpage.c
diff options
context:
space:
mode:
authorAndres Freund <andres@anarazel.de>2023-04-05 18:57:29 -0700
committerAndres Freund <andres@anarazel.de>2023-04-05 18:57:29 -0700
commitacab1b0914e426d28789731f50f5964dd4d2f054 (patch)
tree0c13ad1fa00b1fe9155cc40146b4d7568aa5b468 /src/backend/access/nbtree/nbtpage.c
parentfcdda1e4b50249c344e510ea93d4bd74d2743430 (diff)
downloadpostgresql-acab1b0914e426d28789731f50f5964dd4d2f054.tar.gz
postgresql-acab1b0914e426d28789731f50f5964dd4d2f054.zip
Convert many uses of ReadBuffer[Extended](P_NEW) to ExtendBufferedRel()
A few places are not converted. Some because they are tackled in later commits (e.g. hio.c, xlogutils.c), some because they are more complicated (e.g. brin_pageops.c). Having a few users of ReadBuffer(P_NEW) is good anyway, to ensure the backward compat path stays working. Discussion: https://postgr.es/m/20221029025420.eplyow6k7tgu6he3@awork3.anarazel.de
Diffstat (limited to 'src/backend/access/nbtree/nbtpage.c')
-rw-r--r--src/backend/access/nbtree/nbtpage.c34
1 files changed, 9 insertions, 25 deletions
diff --git a/src/backend/access/nbtree/nbtpage.c b/src/backend/access/nbtree/nbtpage.c
index 0144c3ab571..41aa1c4ccd1 100644
--- a/src/backend/access/nbtree/nbtpage.c
+++ b/src/backend/access/nbtree/nbtpage.c
@@ -882,7 +882,6 @@ _bt_getbuf(Relation rel, Relation heaprel, BlockNumber blkno, int access)
}
else
{
- bool needLock;
Page page;
Assert(access == BT_WRITE);
@@ -963,31 +962,16 @@ _bt_getbuf(Relation rel, Relation heaprel, BlockNumber blkno, int access)
}
/*
- * Extend the relation by one page.
- *
- * We have to use a lock to ensure no one else is extending the rel at
- * the same time, else we will both try to initialize the same new
- * page. We can skip locking for new or temp relations, however,
- * since no one else could be accessing them.
- */
- needLock = !RELATION_IS_LOCAL(rel);
-
- if (needLock)
- LockRelationForExtension(rel, ExclusiveLock);
-
- buf = ReadBuffer(rel, P_NEW);
-
- /* Acquire buffer lock on new page */
- _bt_lockbuf(rel, buf, BT_WRITE);
-
- /*
- * Release the file-extension lock; it's now OK for someone else to
- * extend the relation some more. Note that we cannot release this
- * lock before we have buffer lock on the new page, or we risk a race
- * condition against btvacuumscan --- see comments therein.
+ * Extend the relation by one page. Need to use RBM_ZERO_AND_LOCK or
+ * we risk a race condition against btvacuumscan --- see comments
+ * therein. This forces us to repeat the valgrind request that
+ * _bt_lockbuf() otherwise would make, as we can't use _bt_lockbuf()
+ * without introducing a race.
*/
- if (needLock)
- UnlockRelationForExtension(rel, ExclusiveLock);
+ buf = ExtendBufferedRel(EB_REL(rel), MAIN_FORKNUM, NULL,
+ EB_LOCK_FIRST);
+ if (!RelationUsesLocalBuffers(rel))
+ VALGRIND_MAKE_MEM_DEFINED(BufferGetPage(buf), BLCKSZ);
/* Initialize the new page before returning it */
page = BufferGetPage(buf);