mirror of
https://github.com/postgres/postgres.git
synced 2025-11-09 06:21:09 +03:00
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
This commit is contained in:
@@ -837,9 +837,9 @@ brinbuild(Relation heap, Relation index, IndexInfo *indexInfo)
|
||||
* whole relation will be rolled back.
|
||||
*/
|
||||
|
||||
meta = ReadBuffer(index, P_NEW);
|
||||
meta = ExtendBufferedRel(EB_REL(index), MAIN_FORKNUM, NULL,
|
||||
EB_LOCK_FIRST | EB_SKIP_EXTENSION_LOCK);
|
||||
Assert(BufferGetBlockNumber(meta) == BRIN_METAPAGE_BLKNO);
|
||||
LockBuffer(meta, BUFFER_LOCK_EXCLUSIVE);
|
||||
|
||||
brin_metapage_init(BufferGetPage(meta), BrinGetPagesPerRange(index),
|
||||
BRIN_CURRENT_VERSION);
|
||||
@@ -904,9 +904,8 @@ brinbuildempty(Relation index)
|
||||
Buffer metabuf;
|
||||
|
||||
/* An empty BRIN index has a metapage only. */
|
||||
metabuf =
|
||||
ReadBufferExtended(index, INIT_FORKNUM, P_NEW, RBM_NORMAL, NULL);
|
||||
LockBuffer(metabuf, BUFFER_LOCK_EXCLUSIVE);
|
||||
metabuf = ExtendBufferedRel(EB_REL(index), INIT_FORKNUM, NULL,
|
||||
EB_LOCK_FIRST | EB_SKIP_EXTENSION_LOCK);
|
||||
|
||||
/* Initialize and xlog metabuffer. */
|
||||
START_CRIT_SECTION();
|
||||
|
||||
@@ -730,6 +730,10 @@ brin_getinsertbuffer(Relation irel, Buffer oldbuf, Size itemsz,
|
||||
* There's not enough free space in any existing index page,
|
||||
* according to the FSM: extend the relation to obtain a shiny new
|
||||
* page.
|
||||
*
|
||||
* XXX: It's likely possible to use RBM_ZERO_AND_LOCK here,
|
||||
* which'd avoid the need to hold the extension lock during buffer
|
||||
* reclaim.
|
||||
*/
|
||||
if (!RELATION_IS_LOCAL(irel))
|
||||
{
|
||||
|
||||
@@ -538,7 +538,6 @@ revmap_physical_extend(BrinRevmap *revmap)
|
||||
BlockNumber mapBlk;
|
||||
BlockNumber nblocks;
|
||||
Relation irel = revmap->rm_irel;
|
||||
bool needLock = !RELATION_IS_LOCAL(irel);
|
||||
|
||||
/*
|
||||
* Lock the metapage. This locks out concurrent extensions of the revmap,
|
||||
@@ -570,10 +569,8 @@ revmap_physical_extend(BrinRevmap *revmap)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (needLock)
|
||||
LockRelationForExtension(irel, ExclusiveLock);
|
||||
|
||||
buf = ReadBuffer(irel, P_NEW);
|
||||
buf = ExtendBufferedRel(EB_REL(irel), MAIN_FORKNUM, NULL,
|
||||
EB_LOCK_FIRST);
|
||||
if (BufferGetBlockNumber(buf) != mapBlk)
|
||||
{
|
||||
/*
|
||||
@@ -582,17 +579,11 @@ revmap_physical_extend(BrinRevmap *revmap)
|
||||
* up and have caller start over. We will have to evacuate that
|
||||
* page from under whoever is using it.
|
||||
*/
|
||||
if (needLock)
|
||||
UnlockRelationForExtension(irel, ExclusiveLock);
|
||||
LockBuffer(revmap->rm_metaBuf, BUFFER_LOCK_UNLOCK);
|
||||
ReleaseBuffer(buf);
|
||||
UnlockReleaseBuffer(buf);
|
||||
return;
|
||||
}
|
||||
LockBuffer(buf, BUFFER_LOCK_EXCLUSIVE);
|
||||
page = BufferGetPage(buf);
|
||||
|
||||
if (needLock)
|
||||
UnlockRelationForExtension(irel, ExclusiveLock);
|
||||
}
|
||||
|
||||
/* Check that it's a regular block (or an empty page) */
|
||||
|
||||
Reference in New Issue
Block a user