summaryrefslogtreecommitdiff
path: root/src/backend/access/brin
diff options
context:
space:
mode:
authorKevin Grittner2016-04-08 19:30:10 +0000
committerKevin Grittner2016-04-08 19:30:10 +0000
commit8b65cf4c5edabdcae45ceaef7b9ac236879aae50 (patch)
treef4412d3e9bc0db823ac32e08fac8e3124b42ff02 /src/backend/access/brin
parent689f9a058854a1a32e994818dd6d79f49d8f8a1b (diff)
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.
Diffstat (limited to 'src/backend/access/brin')
-rw-r--r--src/backend/access/brin/brin.c15
-rw-r--r--src/backend/access/brin/brin_pageops.c52
-rw-r--r--src/backend/access/brin/brin_revmap.c18
-rw-r--r--src/backend/access/brin/brin_xlog.c16
4 files changed, 63 insertions, 38 deletions
diff --git a/src/backend/access/brin/brin.c b/src/backend/access/brin/brin.c
index c7409529234..6f6f1b1b415 100644
--- a/src/backend/access/brin/brin.c
+++ b/src/backend/access/brin/brin.c
@@ -208,7 +208,8 @@ brininsert(Relation idxRel, Datum *values, bool *nulls,
}
else
{
- Page page = BufferGetPage(buf);
+ Page page = BufferGetPage(buf, NULL, NULL,
+ BGP_NO_SNAPSHOT_TEST);
ItemId lp = PageGetItemId(page, off);
Size origsz;
BrinTuple *origtup;
@@ -617,7 +618,8 @@ brinbuild(Relation heap, Relation index, IndexInfo *indexInfo)
Assert(BufferGetBlockNumber(meta) == BRIN_METAPAGE_BLKNO);
LockBuffer(meta, BUFFER_LOCK_EXCLUSIVE);
- brin_metapage_init(BufferGetPage(meta), BrinGetPagesPerRange(index),
+ brin_metapage_init(BufferGetPage(meta, NULL, NULL, BGP_NO_SNAPSHOT_TEST),
+ BrinGetPagesPerRange(index),
BRIN_CURRENT_VERSION);
MarkBufferDirty(meta);
@@ -636,7 +638,7 @@ brinbuild(Relation heap, Relation index, IndexInfo *indexInfo)
recptr = XLogInsert(RM_BRIN_ID, XLOG_BRIN_CREATE_INDEX);
- page = BufferGetPage(meta);
+ page = BufferGetPage(meta, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
PageSetLSN(page, recptr);
}
@@ -686,7 +688,9 @@ brinbuildempty(Relation index)
/* Initialize and xlog metabuffer. */
START_CRIT_SECTION();
- brin_metapage_init(BufferGetPage(metabuf), BrinGetPagesPerRange(index),
+ brin_metapage_init(BufferGetPage(metabuf, NULL, NULL,
+ BGP_NO_SNAPSHOT_TEST),
+ BrinGetPagesPerRange(index),
BRIN_CURRENT_VERSION);
MarkBufferDirty(metabuf);
log_newpage_buffer(metabuf, false);
@@ -941,7 +945,8 @@ terminate_brin_buildstate(BrinBuildState *state)
{
Page page;
- page = BufferGetPage(state->bs_currentInsertBuf);
+ page = BufferGetPage(state->bs_currentInsertBuf, NULL, NULL,
+ BGP_NO_SNAPSHOT_TEST);
RecordPageWithFreeSpace(state->bs_irel,
BufferGetBlockNumber(state->bs_currentInsertBuf),
PageGetFreeSpace(page));
diff --git a/src/backend/access/brin/brin_pageops.c b/src/backend/access/brin/brin_pageops.c
index d0ca485caa6..a522b0b5dce 100644
--- a/src/backend/access/brin/brin_pageops.c
+++ b/src/backend/access/brin/brin_pageops.c
@@ -110,7 +110,7 @@ brin_doupdate(Relation idxrel, BlockNumber pagesPerRange,
newbuf = InvalidBuffer;
extended = false;
}
- oldpage = BufferGetPage(oldbuf);
+ oldpage = BufferGetPage(oldbuf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
oldlp = PageGetItemId(oldpage, oldoff);
/*
@@ -228,7 +228,8 @@ brin_doupdate(Relation idxrel, BlockNumber pagesPerRange,
* Not enough free space on the oldpage. Put the new tuple on the new
* page, and update the revmap.
*/
- Page newpage = BufferGetPage(newbuf);
+ Page newpage = BufferGetPage(newbuf, NULL, NULL,
+ BGP_NO_SNAPSHOT_TEST);
Buffer revmapbuf;
ItemPointerData newtid;
OffsetNumber newoff;
@@ -245,7 +246,9 @@ brin_doupdate(Relation idxrel, BlockNumber pagesPerRange,
* need to do that here.
*/
if (extended)
- brin_page_init(BufferGetPage(newbuf), BRIN_PAGETYPE_REGULAR);
+ brin_page_init(BufferGetPage(newbuf, NULL, NULL,
+ BGP_NO_SNAPSHOT_TEST),
+ BRIN_PAGETYPE_REGULAR);
PageIndexDeleteNoCompact(oldpage, &oldoff, 1);
newoff = PageAddItem(newpage, (Item) newtup, newsz,
@@ -298,7 +301,9 @@ brin_doupdate(Relation idxrel, BlockNumber pagesPerRange,
PageSetLSN(oldpage, recptr);
PageSetLSN(newpage, recptr);
- PageSetLSN(BufferGetPage(revmapbuf), recptr);
+ PageSetLSN(BufferGetPage(revmapbuf, NULL, NULL,
+ BGP_NO_SNAPSHOT_TEST),
+ recptr);
}
END_CRIT_SECTION();
@@ -326,7 +331,9 @@ brin_can_do_samepage_update(Buffer buffer, Size origsz, Size newsz)
{
return
((newsz <= origsz) ||
- PageGetExactFreeSpace(BufferGetPage(buffer)) >= (newsz - origsz));
+ PageGetExactFreeSpace(BufferGetPage(buffer, NULL, NULL,
+ BGP_NO_SNAPSHOT_TEST))
+ >= (newsz - origsz));
}
/*
@@ -381,7 +388,9 @@ brin_doinsert(Relation idxrel, BlockNumber pagesPerRange,
* it's still a regular page.
*/
LockBuffer(*buffer, BUFFER_LOCK_EXCLUSIVE);
- if (br_page_get_freespace(BufferGetPage(*buffer)) < itemsz)
+ if (br_page_get_freespace(BufferGetPage(*buffer, NULL, NULL,
+ BGP_NO_SNAPSHOT_TEST))
+ < itemsz)
{
UnlockReleaseBuffer(*buffer);
*buffer = InvalidBuffer;
@@ -404,13 +413,15 @@ brin_doinsert(Relation idxrel, BlockNumber pagesPerRange,
/* Now obtain lock on revmap buffer */
revmapbuf = brinLockRevmapPageForUpdate(revmap, heapBlk);
- page = BufferGetPage(*buffer);
+ page = BufferGetPage(*buffer, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
blk = BufferGetBlockNumber(*buffer);
/* Execute the actual insertion */
START_CRIT_SECTION();
if (extended)
- brin_page_init(BufferGetPage(*buffer), BRIN_PAGETYPE_REGULAR);
+ brin_page_init(BufferGetPage(*buffer, NULL, NULL,
+ BGP_NO_SNAPSHOT_TEST),
+ BRIN_PAGETYPE_REGULAR);
off = PageAddItem(page, (Item) tup, itemsz, InvalidOffsetNumber,
false, false);
if (off == InvalidOffsetNumber)
@@ -447,7 +458,8 @@ brin_doinsert(Relation idxrel, BlockNumber pagesPerRange,
recptr = XLogInsert(RM_BRIN_ID, info);
PageSetLSN(page, recptr);
- PageSetLSN(BufferGetPage(revmapbuf), recptr);
+ PageSetLSN(BufferGetPage(revmapbuf, NULL, NULL,
+ BGP_NO_SNAPSHOT_TEST), recptr);
}
END_CRIT_SECTION();
@@ -515,7 +527,7 @@ brin_start_evacuating_page(Relation idxRel, Buffer buf)
OffsetNumber maxoff;
Page page;
- page = BufferGetPage(buf);
+ page = BufferGetPage(buf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
if (PageIsNew(page))
return false;
@@ -551,7 +563,7 @@ brin_evacuate_page(Relation idxRel, BlockNumber pagesPerRange,
OffsetNumber maxoff;
Page page;
- page = BufferGetPage(buf);
+ page = BufferGetPage(buf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
Assert(BrinPageFlags(page) & BRIN_EVACUATE_PAGE);
@@ -598,7 +610,7 @@ brin_evacuate_page(Relation idxRel, BlockNumber pagesPerRange,
bool
brin_page_cleanup(Relation idxrel, Buffer buf)
{
- Page page = BufferGetPage(buf);
+ Page page = BufferGetPage(buf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
Size freespace;
/*
@@ -627,8 +639,10 @@ brin_page_cleanup(Relation idxrel, Buffer buf)
}
/* Nothing to be done for non-regular index pages */
- if (BRIN_IS_META_PAGE(BufferGetPage(buf)) ||
- BRIN_IS_REVMAP_PAGE(BufferGetPage(buf)))
+ if (BRIN_IS_META_PAGE(BufferGetPage(buf, NULL, NULL,
+ BGP_NO_SNAPSHOT_TEST)) ||
+ BRIN_IS_REVMAP_PAGE(BufferGetPage(buf, NULL, NULL,
+ BGP_NO_SNAPSHOT_TEST)))
return false;
/* Measure free space and record it */
@@ -738,7 +752,8 @@ brin_getinsertbuffer(Relation irel, Buffer oldbuf, Size itemsz,
if (BufferIsValid(oldbuf) && oldblk < newblk)
{
LockBuffer(oldbuf, BUFFER_LOCK_EXCLUSIVE);
- if (!BRIN_IS_REGULAR_PAGE(BufferGetPage(oldbuf)))
+ if (!BRIN_IS_REGULAR_PAGE(BufferGetPage(oldbuf, NULL, NULL,
+ BGP_NO_SNAPSHOT_TEST)))
{
LockBuffer(oldbuf, BUFFER_LOCK_UNLOCK);
@@ -770,7 +785,7 @@ brin_getinsertbuffer(Relation irel, Buffer oldbuf, Size itemsz,
if (extensionLockHeld)
UnlockRelationForExtension(irel, ExclusiveLock);
- page = BufferGetPage(buf);
+ page = BufferGetPage(buf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
/*
* We have a new buffer to insert into. Check that the new page has
@@ -805,7 +820,8 @@ brin_getinsertbuffer(Relation irel, Buffer oldbuf, Size itemsz,
if (BufferIsValid(oldbuf) && oldblk > newblk)
{
LockBuffer(oldbuf, BUFFER_LOCK_EXCLUSIVE);
- Assert(BRIN_IS_REGULAR_PAGE(BufferGetPage(oldbuf)));
+ Assert(BRIN_IS_REGULAR_PAGE(BufferGetPage(oldbuf, NULL, NULL,
+ BGP_NO_SNAPSHOT_TEST)));
}
return buf;
@@ -862,7 +878,7 @@ brin_initialize_empty_new_buffer(Relation idxrel, Buffer buffer)
BufferGetBlockNumber(buffer)));
START_CRIT_SECTION();
- page = BufferGetPage(buffer);
+ page = BufferGetPage(buffer, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
brin_page_init(page, BRIN_PAGETYPE_REGULAR);
MarkBufferDirty(buffer);
log_newpage_buffer(buffer, true);
diff --git a/src/backend/access/brin/brin_revmap.c b/src/backend/access/brin/brin_revmap.c
index b2c273daf6e..ce21cbabb7a 100644
--- a/src/backend/access/brin/brin_revmap.c
+++ b/src/backend/access/brin/brin_revmap.c
@@ -73,10 +73,12 @@ brinRevmapInitialize(Relation idxrel, BlockNumber *pagesPerRange)
BrinRevmap *revmap;
Buffer meta;
BrinMetaPageData *metadata;
+ Page page;
meta = ReadBuffer(idxrel, BRIN_METAPAGE_BLKNO);
LockBuffer(meta, BUFFER_LOCK_SHARE);
- metadata = (BrinMetaPageData *) PageGetContents(BufferGetPage(meta));
+ page = BufferGetPage(meta, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
+ metadata = (BrinMetaPageData *) PageGetContents(page);
revmap = palloc(sizeof(BrinRevmap));
revmap->rm_irel = idxrel;
@@ -159,7 +161,7 @@ brinSetHeapBlockItemptr(Buffer buf, BlockNumber pagesPerRange,
Page page;
/* The correct page should already be pinned and locked */
- page = BufferGetPage(buf);
+ page = BufferGetPage(buf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
contents = (RevmapContents *) PageGetContents(page);
iptr = (ItemPointerData *) contents->rm_tids;
iptr += HEAPBLK_TO_REVMAP_INDEX(pagesPerRange, heapBlk);
@@ -226,7 +228,8 @@ brinGetTupleForHeapBlock(BrinRevmap *revmap, BlockNumber heapBlk,
LockBuffer(revmap->rm_currBuf, BUFFER_LOCK_SHARE);
contents = (RevmapContents *)
- PageGetContents(BufferGetPage(revmap->rm_currBuf));
+ PageGetContents(BufferGetPage(revmap->rm_currBuf, NULL, NULL,
+ BGP_NO_SNAPSHOT_TEST));
iptr = contents->rm_tids;
iptr += HEAPBLK_TO_REVMAP_INDEX(revmap->rm_pagesPerRange, heapBlk);
@@ -261,7 +264,7 @@ brinGetTupleForHeapBlock(BrinRevmap *revmap, BlockNumber heapBlk,
*buf = ReadBuffer(idxRel, blk);
}
LockBuffer(*buf, mode);
- page = BufferGetPage(*buf);
+ page = BufferGetPage(*buf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
/* If we land on a revmap page, start over */
if (BRIN_IS_REGULAR_PAGE(page))
@@ -393,7 +396,8 @@ revmap_physical_extend(BrinRevmap *revmap)
* another backend can extend the index with regular BRIN pages.
*/
LockBuffer(revmap->rm_metaBuf, BUFFER_LOCK_EXCLUSIVE);
- metapage = BufferGetPage(revmap->rm_metaBuf);
+ metapage = BufferGetPage(revmap->rm_metaBuf, NULL, NULL,
+ BGP_NO_SNAPSHOT_TEST);
metadata = (BrinMetaPageData *) PageGetContents(metapage);
/*
@@ -413,7 +417,7 @@ revmap_physical_extend(BrinRevmap *revmap)
{
buf = ReadBuffer(irel, mapBlk);
LockBuffer(buf, BUFFER_LOCK_EXCLUSIVE);
- page = BufferGetPage(buf);
+ page = BufferGetPage(buf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
}
else
{
@@ -436,7 +440,7 @@ revmap_physical_extend(BrinRevmap *revmap)
return;
}
LockBuffer(buf, BUFFER_LOCK_EXCLUSIVE);
- page = BufferGetPage(buf);
+ page = BufferGetPage(buf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
if (needLock)
UnlockRelationForExtension(irel, ExclusiveLock);
diff --git a/src/backend/access/brin/brin_xlog.c b/src/backend/access/brin/brin_xlog.c
index deb7af4ca6e..36e4a99fc10 100644
--- a/src/backend/access/brin/brin_xlog.c
+++ b/src/backend/access/brin/brin_xlog.c
@@ -30,7 +30,7 @@ brin_xlog_createidx(XLogReaderState *record)
/* create the index' metapage */
buf = XLogInitBufferForRedo(record, 0);
Assert(BufferIsValid(buf));
- page = (Page) BufferGetPage(buf);
+ page = BufferGetPage(buf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
brin_metapage_init(page, xlrec->pagesPerRange, xlrec->version);
PageSetLSN(page, lsn);
MarkBufferDirty(buf);
@@ -58,7 +58,7 @@ brin_xlog_insert_update(XLogReaderState *record,
if (XLogRecGetInfo(record) & XLOG_BRIN_INIT_PAGE)
{
buffer = XLogInitBufferForRedo(record, 0);
- page = BufferGetPage(buffer);
+ page = BufferGetPage(buffer, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
brin_page_init(page, BRIN_PAGETYPE_REGULAR);
action = BLK_NEEDS_REDO;
}
@@ -81,7 +81,7 @@ brin_xlog_insert_update(XLogReaderState *record,
Assert(tuple->bt_blkno == xlrec->heapBlk);
- page = (Page) BufferGetPage(buffer);
+ page = BufferGetPage(buffer, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
offnum = xlrec->offnum;
if (PageGetMaxOffsetNumber(page) + 1 < offnum)
elog(PANIC, "brin_xlog_insert_update: invalid max offset number");
@@ -103,7 +103,7 @@ brin_xlog_insert_update(XLogReaderState *record,
ItemPointerData tid;
ItemPointerSet(&tid, regpgno, xlrec->offnum);
- page = (Page) BufferGetPage(buffer);
+ page = BufferGetPage(buffer, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
brinSetHeapBlockItemptr(buffer, xlrec->pagesPerRange, xlrec->heapBlk,
tid);
@@ -145,7 +145,7 @@ brin_xlog_update(XLogReaderState *record)
Page page;
OffsetNumber offnum;
- page = (Page) BufferGetPage(buffer);
+ page = BufferGetPage(buffer, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
offnum = xlrec->oldOffnum;
if (PageGetMaxOffsetNumber(page) + 1 < offnum)
@@ -186,7 +186,7 @@ brin_xlog_samepage_update(XLogReaderState *record)
brintuple = (BrinTuple *) XLogRecGetBlockData(record, 0, &tuplen);
- page = (Page) BufferGetPage(buffer);
+ page = BufferGetPage(buffer, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
offnum = xlrec->offnum;
if (PageGetMaxOffsetNumber(page) + 1 < offnum)
@@ -232,7 +232,7 @@ brin_xlog_revmap_extend(XLogReaderState *record)
Page metapg;
BrinMetaPageData *metadata;
- metapg = BufferGetPage(metabuf);
+ metapg = BufferGetPage(metabuf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
metadata = (BrinMetaPageData *) PageGetContents(metapg);
Assert(metadata->lastRevmapPage == xlrec->targetBlk - 1);
@@ -248,7 +248,7 @@ brin_xlog_revmap_extend(XLogReaderState *record)
*/
buf = XLogInitBufferForRedo(record, 1);
- page = (Page) BufferGetPage(buf);
+ page = BufferGetPage(buf, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
brin_page_init(page, BRIN_PAGETYPE_REVMAP);
PageSetLSN(page, lsn);