diff options
author | Kevin Grittner <kgrittn@postgresql.org> | 2016-04-08 14:30:10 -0500 |
---|---|---|
committer | Kevin Grittner <kgrittn@postgresql.org> | 2016-04-08 14:30:10 -0500 |
commit | 8b65cf4c5edabdcae45ceaef7b9ac236879aae50 (patch) | |
tree | f4412d3e9bc0db823ac32e08fac8e3124b42ff02 /src/backend/access/nbtree/nbtsearch.c | |
parent | 689f9a058854a1a32e994818dd6d79f49d8f8a1b (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/nbtree/nbtsearch.c')
-rw-r--r-- | src/backend/access/nbtree/nbtsearch.c | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/src/backend/access/nbtree/nbtsearch.c b/src/backend/access/nbtree/nbtsearch.c index 14dffe07db6..83f790f7917 100644 --- a/src/backend/access/nbtree/nbtsearch.c +++ b/src/backend/access/nbtree/nbtsearch.c @@ -30,7 +30,7 @@ static bool _bt_readpage(IndexScanDesc scan, ScanDirection dir, static void _bt_saveitem(BTScanOpaque so, int itemIndex, OffsetNumber offnum, IndexTuple itup); static bool _bt_steppage(IndexScanDesc scan, ScanDirection dir); -static Buffer _bt_walk_left(Relation rel, Buffer buf); +static Buffer _bt_walk_left(Relation rel, Buffer buf, Snapshot snapshot); static bool _bt_endpoint(IndexScanDesc scan, ScanDirection dir); static void _bt_drop_lock_and_maybe_pin(IndexScanDesc scan, BTScanPos sp); @@ -96,7 +96,9 @@ _bt_search(Relation rel, int keysz, ScanKey scankey, bool nextkey, /* If index is empty and access = BT_READ, no root page is created. */ if (!BufferIsValid(*bufP)) + { return (BTStack) NULL; + } /* Loop iterates once per level descended in the tree */ for (;;) @@ -127,7 +129,7 @@ _bt_search(Relation rel, int keysz, ScanKey scankey, bool nextkey, BT_READ); /* if this is a leaf page, we're done */ - page = BufferGetPage(*bufP); + page = BufferGetPage(*bufP, NULL, NULL, BGP_NO_SNAPSHOT_TEST); opaque = (BTPageOpaque) PageGetSpecialPointer(page); if (P_ISLEAF(opaque)) break; @@ -231,7 +233,7 @@ _bt_moveright(Relation rel, for (;;) { - page = BufferGetPage(buf); + page = BufferGetPage(buf, NULL, NULL, BGP_NO_SNAPSHOT_TEST); opaque = (BTPageOpaque) PageGetSpecialPointer(page); if (P_RIGHTMOST(opaque)) @@ -319,7 +321,7 @@ _bt_binsrch(Relation rel, int32 result, cmpval; - page = BufferGetPage(buf); + page = BufferGetPage(buf, NULL, NULL, BGP_NO_SNAPSHOT_TEST); opaque = (BTPageOpaque) PageGetSpecialPointer(page); low = P_FIRSTDATAKEY(opaque); @@ -1141,7 +1143,7 @@ _bt_readpage(IndexScanDesc scan, ScanDirection dir, OffsetNumber offnum) */ Assert(BufferIsValid(so->currPos.buf)); - page = BufferGetPage(so->currPos.buf); + page = BufferGetPage(so->currPos.buf, NULL, NULL, BGP_NO_SNAPSHOT_TEST); opaque = (BTPageOpaque) PageGetSpecialPointer(page); minoff = P_FIRSTDATAKEY(opaque); maxoff = PageGetMaxOffsetNumber(page); @@ -1335,7 +1337,8 @@ _bt_steppage(IndexScanDesc scan, ScanDirection dir) /* step right one page */ so->currPos.buf = _bt_getbuf(rel, blkno, BT_READ); /* check for deleted page */ - page = BufferGetPage(so->currPos.buf); + page = BufferGetPage(so->currPos.buf, NULL, NULL, + BGP_NO_SNAPSHOT_TEST); opaque = (BTPageOpaque) PageGetSpecialPointer(page); if (!P_IGNORE(opaque)) { @@ -1394,7 +1397,8 @@ _bt_steppage(IndexScanDesc scan, ScanDirection dir) } /* Step to next physical page */ - so->currPos.buf = _bt_walk_left(rel, so->currPos.buf); + so->currPos.buf = _bt_walk_left(rel, so->currPos.buf, + scan->xs_snapshot); /* if we're physically at end of index, return failure */ if (so->currPos.buf == InvalidBuffer) @@ -1408,7 +1412,8 @@ _bt_steppage(IndexScanDesc scan, ScanDirection dir) * it's not half-dead and contains matching tuples. Else loop back * and do it all again. */ - page = BufferGetPage(so->currPos.buf); + page = BufferGetPage(so->currPos.buf, NULL, NULL, + BGP_NO_SNAPSHOT_TEST); opaque = (BTPageOpaque) PageGetSpecialPointer(page); if (!P_IGNORE(opaque)) { @@ -1442,12 +1447,12 @@ _bt_steppage(IndexScanDesc scan, ScanDirection dir) * again if it's important. */ static Buffer -_bt_walk_left(Relation rel, Buffer buf) +_bt_walk_left(Relation rel, Buffer buf, Snapshot snapshot) { Page page; BTPageOpaque opaque; - page = BufferGetPage(buf); + page = BufferGetPage(buf, NULL, NULL, BGP_NO_SNAPSHOT_TEST); opaque = (BTPageOpaque) PageGetSpecialPointer(page); for (;;) @@ -1471,7 +1476,7 @@ _bt_walk_left(Relation rel, Buffer buf) /* check for interrupts while we're not holding any buffer lock */ CHECK_FOR_INTERRUPTS(); buf = _bt_getbuf(rel, blkno, BT_READ); - page = BufferGetPage(buf); + page = BufferGetPage(buf, NULL, NULL, BGP_NO_SNAPSHOT_TEST); opaque = (BTPageOpaque) PageGetSpecialPointer(page); /* @@ -1497,13 +1502,14 @@ _bt_walk_left(Relation rel, Buffer buf) break; blkno = opaque->btpo_next; buf = _bt_relandgetbuf(rel, buf, blkno, BT_READ); - page = BufferGetPage(buf); + page = BufferGetPage(buf, NULL, NULL, + BGP_NO_SNAPSHOT_TEST); opaque = (BTPageOpaque) PageGetSpecialPointer(page); } /* Return to the original page to see what's up */ buf = _bt_relandgetbuf(rel, buf, obknum, BT_READ); - page = BufferGetPage(buf); + page = BufferGetPage(buf, NULL, NULL, BGP_NO_SNAPSHOT_TEST); opaque = (BTPageOpaque) PageGetSpecialPointer(page); if (P_ISDELETED(opaque)) { @@ -1520,7 +1526,8 @@ _bt_walk_left(Relation rel, Buffer buf) RelationGetRelationName(rel)); blkno = opaque->btpo_next; buf = _bt_relandgetbuf(rel, buf, blkno, BT_READ); - page = BufferGetPage(buf); + page = BufferGetPage(buf, NULL, NULL, + BGP_NO_SNAPSHOT_TEST); opaque = (BTPageOpaque) PageGetSpecialPointer(page); if (!P_ISDELETED(opaque)) break; @@ -1579,7 +1586,7 @@ _bt_get_endpoint(Relation rel, uint32 level, bool rightmost) if (!BufferIsValid(buf)) return InvalidBuffer; - page = BufferGetPage(buf); + page = BufferGetPage(buf, NULL, NULL, BGP_NO_SNAPSHOT_TEST); opaque = (BTPageOpaque) PageGetSpecialPointer(page); for (;;) @@ -1598,7 +1605,8 @@ _bt_get_endpoint(Relation rel, uint32 level, bool rightmost) elog(ERROR, "fell off the end of index \"%s\"", RelationGetRelationName(rel)); buf = _bt_relandgetbuf(rel, buf, blkno, BT_READ); - page = BufferGetPage(buf); + page = BufferGetPage(buf, NULL, NULL, + BGP_NO_SNAPSHOT_TEST); opaque = (BTPageOpaque) PageGetSpecialPointer(page); } @@ -1619,7 +1627,7 @@ _bt_get_endpoint(Relation rel, uint32 level, bool rightmost) blkno = ItemPointerGetBlockNumber(&(itup->t_tid)); buf = _bt_relandgetbuf(rel, buf, blkno, BT_READ); - page = BufferGetPage(buf); + page = BufferGetPage(buf, NULL, NULL, BGP_NO_SNAPSHOT_TEST); opaque = (BTPageOpaque) PageGetSpecialPointer(page); } @@ -1665,7 +1673,7 @@ _bt_endpoint(IndexScanDesc scan, ScanDirection dir) } PredicateLockPage(rel, BufferGetBlockNumber(buf), scan->xs_snapshot); - page = BufferGetPage(buf); + page = BufferGetPage(buf, NULL, NULL, BGP_NO_SNAPSHOT_TEST); opaque = (BTPageOpaque) PageGetSpecialPointer(page); Assert(P_ISLEAF(opaque)); |