1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-13 16:22:44 +03:00

Modify BufferGetPage() to prepare for "snapshot too old" feature

This patch is a no-op patch which is intended to reduce the chances
of failures of omission once the functional part of the "snapshot
too old" patch goes in.  It adds parameters for snapshot, relation,
and an enum to specify whether the snapshot age check needs to be
done for the page at this point.  This initial patch passes NULL
for the first two new parameters and BGP_NO_SNAPSHOT_TEST for the
third.  The follow-on patch will change the places where the test
needs to be made.
This commit is contained in:
Kevin Grittner
2016-04-08 14:30:10 -05:00
parent 689f9a0588
commit 8b65cf4c5e
65 changed files with 735 additions and 522 deletions

View File

@@ -278,7 +278,7 @@ hashgettuple(IndexScanDesc scan, ScanDirection dir)
buf = so->hashso_curbuf;
Assert(BufferIsValid(buf));
page = BufferGetPage(buf);
page = BufferGetPage(buf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
maxoffnum = PageGetMaxOffsetNumber(page);
for (offnum = ItemPointerGetOffsetNumber(current);
offnum <= maxoffnum;
@@ -327,7 +327,8 @@ hashgettuple(IndexScanDesc scan, ScanDirection dir)
while (res)
{
offnum = ItemPointerGetOffsetNumber(current);
page = BufferGetPage(so->hashso_curbuf);
page = BufferGetPage(so->hashso_curbuf, NULL, NULL,
BGP_NO_SNAPSHOT_TEST);
if (!ItemIdIsDead(PageGetItemId(page, offnum)))
break;
res = _hash_next(scan, dir);
@@ -370,7 +371,8 @@ hashgetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
OffsetNumber offnum;
offnum = ItemPointerGetOffsetNumber(&(so->hashso_curpos));
page = BufferGetPage(so->hashso_curbuf);
page = BufferGetPage(so->hashso_curbuf, NULL, NULL,
BGP_NO_SNAPSHOT_TEST);
add_tuple = !ItemIdIsDead(PageGetItemId(page, offnum));
}
else
@@ -515,7 +517,8 @@ hashbulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats,
* each bucket.
*/
metabuf = _hash_getbuf(rel, HASH_METAPAGE, HASH_READ, LH_META_PAGE);
metap = HashPageGetMeta(BufferGetPage(metabuf));
metap = HashPageGetMeta(BufferGetPage(metabuf, NULL, NULL,
BGP_NO_SNAPSHOT_TEST));
orig_maxbucket = metap->hashm_maxbucket;
orig_ntuples = metap->hashm_ntuples;
memcpy(&local_metapage, metap, sizeof(local_metapage));
@@ -559,7 +562,7 @@ loop_top:
buf = _hash_getbuf_with_strategy(rel, blkno, HASH_WRITE,
LH_BUCKET_PAGE | LH_OVERFLOW_PAGE,
info->strategy);
page = BufferGetPage(buf);
page = BufferGetPage(buf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
opaque = (HashPageOpaque) PageGetSpecialPointer(page);
Assert(opaque->hasho_bucket == cur_bucket);
@@ -614,7 +617,8 @@ loop_top:
/* Write-lock metapage and check for split since we started */
metabuf = _hash_getbuf(rel, HASH_METAPAGE, HASH_WRITE, LH_META_PAGE);
metap = HashPageGetMeta(BufferGetPage(metabuf));
metap = HashPageGetMeta(BufferGetPage(metabuf, NULL, NULL,
BGP_NO_SNAPSHOT_TEST));
if (cur_maxbucket != metap->hashm_maxbucket)
{

View File

@@ -53,7 +53,8 @@ _hash_doinsert(Relation rel, IndexTuple itup)
/* Read the metapage */
metabuf = _hash_getbuf(rel, HASH_METAPAGE, HASH_READ, LH_META_PAGE);
metap = HashPageGetMeta(BufferGetPage(metabuf));
metap = HashPageGetMeta(BufferGetPage(metabuf, NULL, NULL,
BGP_NO_SNAPSHOT_TEST));
/*
* Check whether the item can fit on a hash page at all. (Eventually, we
@@ -111,7 +112,7 @@ _hash_doinsert(Relation rel, IndexTuple itup)
/* Fetch the primary bucket page for the bucket */
buf = _hash_getbuf(rel, blkno, HASH_WRITE, LH_BUCKET_PAGE);
page = BufferGetPage(buf);
page = BufferGetPage(buf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
pageopaque = (HashPageOpaque) PageGetSpecialPointer(page);
Assert(pageopaque->hasho_bucket == bucket);
@@ -131,7 +132,7 @@ _hash_doinsert(Relation rel, IndexTuple itup)
*/
_hash_relbuf(rel, buf);
buf = _hash_getbuf(rel, nextblkno, HASH_WRITE, LH_OVERFLOW_PAGE);
page = BufferGetPage(buf);
page = BufferGetPage(buf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
}
else
{
@@ -145,7 +146,7 @@ _hash_doinsert(Relation rel, IndexTuple itup)
/* chain to a new overflow page */
buf = _hash_addovflpage(rel, metabuf, buf);
page = BufferGetPage(buf);
page = BufferGetPage(buf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
/* should fit now, given test above */
Assert(PageGetFreeSpace(page) >= itemsz);
@@ -206,7 +207,7 @@ _hash_pgaddtup(Relation rel, Buffer buf, Size itemsize, IndexTuple itup)
uint32 hashkey;
_hash_checkpage(rel, buf, LH_BUCKET_PAGE | LH_OVERFLOW_PAGE);
page = BufferGetPage(buf);
page = BufferGetPage(buf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
/* Find where to insert the tuple (preserving page's hashkey ordering) */
hashkey = _hash_get_indextuple_hashkey(itup);

View File

@@ -123,7 +123,7 @@ _hash_addovflpage(Relation rel, Buffer metabuf, Buffer buf)
{
BlockNumber nextblkno;
page = BufferGetPage(buf);
page = BufferGetPage(buf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
pageopaque = (HashPageOpaque) PageGetSpecialPointer(page);
nextblkno = pageopaque->hasho_nextblkno;
@@ -137,7 +137,7 @@ _hash_addovflpage(Relation rel, Buffer metabuf, Buffer buf)
}
/* now that we have correct backlink, initialize new overflow page */
ovflpage = BufferGetPage(ovflbuf);
ovflpage = BufferGetPage(ovflbuf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
ovflopaque = (HashPageOpaque) PageGetSpecialPointer(ovflpage);
ovflopaque->hasho_prevblkno = BufferGetBlockNumber(buf);
ovflopaque->hasho_nextblkno = InvalidBlockNumber;
@@ -186,7 +186,8 @@ _hash_getovflpage(Relation rel, Buffer metabuf)
_hash_chgbufaccess(rel, metabuf, HASH_NOLOCK, HASH_WRITE);
_hash_checkpage(rel, metabuf, LH_META_PAGE);
metap = HashPageGetMeta(BufferGetPage(metabuf));
metap = HashPageGetMeta(BufferGetPage(metabuf, NULL, NULL,
BGP_NO_SNAPSHOT_TEST));
/* start search at hashm_firstfree */
orig_firstfree = metap->hashm_firstfree;
@@ -224,7 +225,7 @@ _hash_getovflpage(Relation rel, Buffer metabuf)
_hash_chgbufaccess(rel, metabuf, HASH_READ, HASH_NOLOCK);
mapbuf = _hash_getbuf(rel, mapblkno, HASH_WRITE, LH_BITMAP_PAGE);
mappage = BufferGetPage(mapbuf);
mappage = BufferGetPage(mapbuf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
freep = HashPageGetBitmap(mappage);
for (; bit <= last_inpage; j++, bit += BITS_PER_MAP)
@@ -396,7 +397,7 @@ _hash_freeovflpage(Relation rel, Buffer ovflbuf,
/* Get information from the doomed page */
_hash_checkpage(rel, ovflbuf, LH_OVERFLOW_PAGE);
ovflblkno = BufferGetBlockNumber(ovflbuf);
ovflpage = BufferGetPage(ovflbuf);
ovflpage = BufferGetPage(ovflbuf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
ovflopaque = (HashPageOpaque) PageGetSpecialPointer(ovflpage);
nextblkno = ovflopaque->hasho_nextblkno;
prevblkno = ovflopaque->hasho_prevblkno;
@@ -423,7 +424,7 @@ _hash_freeovflpage(Relation rel, Buffer ovflbuf,
HASH_WRITE,
LH_BUCKET_PAGE | LH_OVERFLOW_PAGE,
bstrategy);
Page prevpage = BufferGetPage(prevbuf);
Page prevpage = BufferGetPage(prevbuf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
HashPageOpaque prevopaque = (HashPageOpaque) PageGetSpecialPointer(prevpage);
Assert(prevopaque->hasho_bucket == bucket);
@@ -437,7 +438,7 @@ _hash_freeovflpage(Relation rel, Buffer ovflbuf,
HASH_WRITE,
LH_OVERFLOW_PAGE,
bstrategy);
Page nextpage = BufferGetPage(nextbuf);
Page nextpage = BufferGetPage(nextbuf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
HashPageOpaque nextopaque = (HashPageOpaque) PageGetSpecialPointer(nextpage);
Assert(nextopaque->hasho_bucket == bucket);
@@ -449,7 +450,8 @@ _hash_freeovflpage(Relation rel, Buffer ovflbuf,
/* Read the metapage so we can determine which bitmap page to use */
metabuf = _hash_getbuf(rel, HASH_METAPAGE, HASH_READ, LH_META_PAGE);
metap = HashPageGetMeta(BufferGetPage(metabuf));
metap = HashPageGetMeta(BufferGetPage(metabuf, NULL, NULL,
BGP_NO_SNAPSHOT_TEST));
/* Identify which bit to set */
ovflbitno = blkno_to_bitno(metap, ovflblkno);
@@ -466,7 +468,7 @@ _hash_freeovflpage(Relation rel, Buffer ovflbuf,
/* Clear the bitmap bit to indicate that this overflow page is free */
mapbuf = _hash_getbuf(rel, blkno, HASH_WRITE, LH_BITMAP_PAGE);
mappage = BufferGetPage(mapbuf);
mappage = BufferGetPage(mapbuf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
freep = HashPageGetBitmap(mappage);
Assert(ISSET(freep, bitmapbit));
CLRBIT(freep, bitmapbit);
@@ -521,7 +523,7 @@ _hash_initbitmap(Relation rel, HashMetaPage metap, BlockNumber blkno,
* that it's not worth worrying about.
*/
buf = _hash_getnewbuf(rel, blkno, forkNum);
pg = BufferGetPage(buf);
pg = BufferGetPage(buf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
/* initialize the page's special space */
op = (HashPageOpaque) PageGetSpecialPointer(pg);
@@ -601,7 +603,7 @@ _hash_squeezebucket(Relation rel,
HASH_WRITE,
LH_BUCKET_PAGE,
bstrategy);
wpage = BufferGetPage(wbuf);
wpage = BufferGetPage(wbuf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
wopaque = (HashPageOpaque) PageGetSpecialPointer(wpage);
/*
@@ -631,7 +633,7 @@ _hash_squeezebucket(Relation rel,
HASH_WRITE,
LH_OVERFLOW_PAGE,
bstrategy);
rpage = BufferGetPage(rbuf);
rpage = BufferGetPage(rbuf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
ropaque = (HashPageOpaque) PageGetSpecialPointer(rpage);
Assert(ropaque->hasho_bucket == bucket);
} while (BlockNumberIsValid(ropaque->hasho_nextblkno));
@@ -696,7 +698,7 @@ _hash_squeezebucket(Relation rel,
HASH_WRITE,
LH_OVERFLOW_PAGE,
bstrategy);
wpage = BufferGetPage(wbuf);
wpage = BufferGetPage(wbuf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
wopaque = (HashPageOpaque) PageGetSpecialPointer(wpage);
Assert(wopaque->hasho_bucket == bucket);
wbuf_dirty = false;
@@ -752,7 +754,7 @@ _hash_squeezebucket(Relation rel,
HASH_WRITE,
LH_OVERFLOW_PAGE,
bstrategy);
rpage = BufferGetPage(rbuf);
rpage = BufferGetPage(rbuf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
ropaque = (HashPageOpaque) PageGetSpecialPointer(rpage);
Assert(ropaque->hasho_bucket == bucket);
}

View File

@@ -161,7 +161,8 @@ _hash_getinitbuf(Relation rel, BlockNumber blkno)
/* ref count and lock type are correct */
/* initialize the page */
_hash_pageinit(BufferGetPage(buf), BufferGetPageSize(buf));
_hash_pageinit(BufferGetPage(buf, NULL, NULL, BGP_NO_SNAPSHOT_TEST),
BufferGetPageSize(buf));
return buf;
}
@@ -210,7 +211,8 @@ _hash_getnewbuf(Relation rel, BlockNumber blkno, ForkNumber forkNum)
/* ref count and lock type are correct */
/* initialize the page */
_hash_pageinit(BufferGetPage(buf), BufferGetPageSize(buf));
_hash_pageinit(BufferGetPage(buf, NULL, NULL, BGP_NO_SNAPSHOT_TEST),
BufferGetPageSize(buf));
return buf;
}
@@ -384,7 +386,7 @@ _hash_metapinit(Relation rel, double num_tuples, ForkNumber forkNum)
* the physical index length.
*/
metabuf = _hash_getnewbuf(rel, HASH_METAPAGE, forkNum);
pg = BufferGetPage(metabuf);
pg = BufferGetPage(metabuf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
pageopaque = (HashPageOpaque) PageGetSpecialPointer(pg);
pageopaque->hasho_prevblkno = InvalidBlockNumber;
@@ -452,7 +454,7 @@ _hash_metapinit(Relation rel, double num_tuples, ForkNumber forkNum)
CHECK_FOR_INTERRUPTS();
buf = _hash_getnewbuf(rel, BUCKET_TO_BLKNO(metap, i), forkNum);
pg = BufferGetPage(buf);
pg = BufferGetPage(buf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
pageopaque = (HashPageOpaque) PageGetSpecialPointer(pg);
pageopaque->hasho_prevblkno = InvalidBlockNumber;
pageopaque->hasho_nextblkno = InvalidBlockNumber;
@@ -517,7 +519,8 @@ _hash_expandtable(Relation rel, Buffer metabuf)
_hash_chgbufaccess(rel, metabuf, HASH_NOLOCK, HASH_WRITE);
_hash_checkpage(rel, metabuf, LH_META_PAGE);
metap = HashPageGetMeta(BufferGetPage(metabuf));
metap = HashPageGetMeta(BufferGetPage(metabuf, NULL, NULL,
BGP_NO_SNAPSHOT_TEST));
/*
* Check to see if split is still needed; someone else might have already
@@ -774,10 +777,10 @@ _hash_splitbucket(Relation rel,
* either bucket.
*/
obuf = _hash_getbuf(rel, start_oblkno, HASH_WRITE, LH_BUCKET_PAGE);
opage = BufferGetPage(obuf);
opage = BufferGetPage(obuf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
oopaque = (HashPageOpaque) PageGetSpecialPointer(opage);
npage = BufferGetPage(nbuf);
npage = BufferGetPage(nbuf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
/* initialize the new bucket's primary page */
nopaque = (HashPageOpaque) PageGetSpecialPointer(npage);
@@ -841,7 +844,7 @@ _hash_splitbucket(Relation rel,
_hash_chgbufaccess(rel, nbuf, HASH_WRITE, HASH_NOLOCK);
/* chain to a new overflow page */
nbuf = _hash_addovflpage(rel, metabuf, nbuf);
npage = BufferGetPage(nbuf);
npage = BufferGetPage(nbuf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
/* we don't need nopaque within the loop */
}
@@ -888,7 +891,7 @@ _hash_splitbucket(Relation rel,
/* Else, advance to next old page */
obuf = _hash_getbuf(rel, oblkno, HASH_WRITE, LH_OVERFLOW_PAGE);
opage = BufferGetPage(obuf);
opage = BufferGetPage(obuf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
oopaque = (HashPageOpaque) PageGetSpecialPointer(opage);
}

View File

@@ -55,7 +55,7 @@ _hash_next(IndexScanDesc scan, ScanDirection dir)
current = &(so->hashso_curpos);
offnum = ItemPointerGetOffsetNumber(current);
_hash_checkpage(rel, buf, LH_BUCKET_PAGE | LH_OVERFLOW_PAGE);
page = BufferGetPage(buf);
page = BufferGetPage(buf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
itup = (IndexTuple) PageGetItem(page, PageGetItemId(page, offnum));
so->hashso_heappos = itup->t_tid;
@@ -79,7 +79,7 @@ _hash_readnext(Relation rel,
if (BlockNumberIsValid(blkno))
{
*bufp = _hash_getbuf(rel, blkno, HASH_READ, LH_OVERFLOW_PAGE);
*pagep = BufferGetPage(*bufp);
*pagep = BufferGetPage(*bufp, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
*opaquep = (HashPageOpaque) PageGetSpecialPointer(*pagep);
}
}
@@ -102,7 +102,7 @@ _hash_readprev(Relation rel,
{
*bufp = _hash_getbuf(rel, blkno, HASH_READ,
LH_BUCKET_PAGE | LH_OVERFLOW_PAGE);
*pagep = BufferGetPage(*bufp);
*pagep = BufferGetPage(*bufp, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
*opaquep = (HashPageOpaque) PageGetSpecialPointer(*pagep);
}
}
@@ -188,7 +188,9 @@ _hash_first(IndexScanDesc scan, ScanDirection dir)
/* Read the metapage */
metabuf = _hash_getbuf(rel, HASH_METAPAGE, HASH_READ, LH_META_PAGE);
metap = HashPageGetMeta(BufferGetPage(metabuf));
page = BufferGetPage(metabuf, NULL, NULL,
BGP_NO_SNAPSHOT_TEST);
metap = HashPageGetMeta(page);
/*
* Loop until we get a lock on the correct target bucket.
@@ -240,7 +242,8 @@ _hash_first(IndexScanDesc scan, ScanDirection dir)
/* Fetch the primary bucket page for the bucket */
buf = _hash_getbuf(rel, blkno, HASH_READ, LH_BUCKET_PAGE);
page = BufferGetPage(buf);
page = BufferGetPage(buf, NULL, NULL,
BGP_NO_SNAPSHOT_TEST);
opaque = (HashPageOpaque) PageGetSpecialPointer(page);
Assert(opaque->hasho_bucket == bucket);
@@ -258,7 +261,7 @@ _hash_first(IndexScanDesc scan, ScanDirection dir)
/* if we're here, _hash_step found a valid tuple */
offnum = ItemPointerGetOffsetNumber(current);
_hash_checkpage(rel, buf, LH_BUCKET_PAGE | LH_OVERFLOW_PAGE);
page = BufferGetPage(buf);
page = BufferGetPage(buf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
itup = (IndexTuple) PageGetItem(page, PageGetItemId(page, offnum));
so->hashso_heappos = itup->t_tid;
@@ -294,7 +297,7 @@ _hash_step(IndexScanDesc scan, Buffer *bufP, ScanDirection dir)
buf = *bufP;
_hash_checkpage(rel, buf, LH_BUCKET_PAGE | LH_OVERFLOW_PAGE);
page = BufferGetPage(buf);
page = BufferGetPage(buf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
opaque = (HashPageOpaque) PageGetSpecialPointer(page);
/*

View File

@@ -155,7 +155,7 @@ _hash_log2(uint32 num)
void
_hash_checkpage(Relation rel, Buffer buf, int flags)
{
Page page = BufferGetPage(buf);
Page page = BufferGetPage(buf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
/*
* ReadBuffer verifies that every newly-read page passes