PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
brin_revmap.h File Reference
#include "access/brin_tuple.h"
#include "storage/block.h"
#include "storage/buf.h"
#include "storage/itemptr.h"
#include "storage/off.h"
#include "utils/relcache.h"
#include "utils/snapshot.h"
Include dependency graph for brin_revmap.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef struct BrinRevmap BrinRevmap
 

Functions

BrinRevmapbrinRevmapInitialize (Relation idxrel, BlockNumber *pagesPerRange, Snapshot snapshot)
 
void brinRevmapTerminate (BrinRevmap *revmap)
 
void brinRevmapExtend (BrinRevmap *revmap, BlockNumber heapBlk)
 
Buffer brinLockRevmapPageForUpdate (BrinRevmap *revmap, BlockNumber heapBlk)
 
void brinSetHeapBlockItemptr (Buffer rmbuf, BlockNumber pagesPerRange, BlockNumber heapBlk, ItemPointerData tid)
 
BrinTuplebrinGetTupleForHeapBlock (BrinRevmap *revmap, BlockNumber heapBlk, Buffer *buf, OffsetNumber *off, Size *size, int mode, Snapshot snapshot)
 
bool brinRevmapDesummarizeRange (Relation idxrel, BlockNumber heapBlk)
 

Typedef Documentation

Definition at line 24 of file brin_revmap.h.

Function Documentation

BrinTuple* brinGetTupleForHeapBlock ( BrinRevmap revmap,
BlockNumber  heapBlk,
Buffer buf,
OffsetNumber off,
Size size,
int  mode,
Snapshot  snapshot 
)

Definition at line 194 of file brin_revmap.c.

References Assert, BRIN_IS_REGULAR_PAGE, BrinTuple::bt_blkno, BUFFER_LOCK_SHARE, BUFFER_LOCK_UNLOCK, BufferGetBlockNumber(), BufferGetPage, BufferIsValid, CHECK_FOR_INTERRUPTS, ereport, errcode(), errmsg_internal(), ERROR, HEAPBLK_TO_REVMAP_INDEX, InvalidBlockNumber, InvalidBuffer, InvalidOffsetNumber, ItemIdGetLength, ItemIdIsUsed, ItemPointerEquals(), ItemPointerGetBlockNumber, ItemPointerGetOffsetNumber, ItemPointerIsValid, ItemPointerSetInvalid, LockBuffer(), NULL, PageGetContents, PageGetItem, PageGetItemId, PageGetMaxOffsetNumber, ReadBuffer(), ReleaseBuffer(), revmap_get_blkno(), BrinRevmap::rm_currBuf, BrinRevmap::rm_irel, BrinRevmap::rm_pagesPerRange, RevmapContents::rm_tids, and TestForOldSnapshot().

Referenced by bringetbitmap(), brininsert(), brinsummarize(), and summarize_range().

197 {
198  Relation idxRel = revmap->rm_irel;
199  BlockNumber mapBlk;
200  RevmapContents *contents;
201  ItemPointerData *iptr;
202  BlockNumber blk;
203  Page page;
204  ItemId lp;
205  BrinTuple *tup;
206  ItemPointerData previptr;
207 
208  /* normalize the heap block number to be the first page in the range */
209  heapBlk = (heapBlk / revmap->rm_pagesPerRange) * revmap->rm_pagesPerRange;
210 
211  /*
212  * Compute the revmap page number we need. If Invalid is returned (i.e.,
213  * the revmap page hasn't been created yet), the requested page range is
214  * not summarized.
215  */
216  mapBlk = revmap_get_blkno(revmap, heapBlk);
217  if (mapBlk == InvalidBlockNumber)
218  {
219  *off = InvalidOffsetNumber;
220  return NULL;
221  }
222 
223  ItemPointerSetInvalid(&previptr);
224  for (;;)
225  {
227 
228  if (revmap->rm_currBuf == InvalidBuffer ||
229  BufferGetBlockNumber(revmap->rm_currBuf) != mapBlk)
230  {
231  if (revmap->rm_currBuf != InvalidBuffer)
232  ReleaseBuffer(revmap->rm_currBuf);
233 
234  Assert(mapBlk != InvalidBlockNumber);
235  revmap->rm_currBuf = ReadBuffer(revmap->rm_irel, mapBlk);
236  }
237 
239 
240  contents = (RevmapContents *)
242  iptr = contents->rm_tids;
243  iptr += HEAPBLK_TO_REVMAP_INDEX(revmap->rm_pagesPerRange, heapBlk);
244 
245  if (!ItemPointerIsValid(iptr))
246  {
248  return NULL;
249  }
250 
251  /*
252  * Check the TID we got in a previous iteration, if any, and save the
253  * current TID we got from the revmap; if we loop, we can sanity-check
254  * that the next one we get is different. Otherwise we might be stuck
255  * looping forever if the revmap is somehow badly broken.
256  */
257  if (ItemPointerIsValid(&previptr) && ItemPointerEquals(&previptr, iptr))
258  ereport(ERROR,
259  (errcode(ERRCODE_INDEX_CORRUPTED),
260  errmsg_internal("corrupted BRIN index: inconsistent range map")));
261  previptr = *iptr;
262 
263  blk = ItemPointerGetBlockNumber(iptr);
264  *off = ItemPointerGetOffsetNumber(iptr);
265 
267 
268  /* Ok, got a pointer to where the BrinTuple should be. Fetch it. */
269  if (!BufferIsValid(*buf) || BufferGetBlockNumber(*buf) != blk)
270  {
271  if (BufferIsValid(*buf))
272  ReleaseBuffer(*buf);
273  *buf = ReadBuffer(idxRel, blk);
274  }
275  LockBuffer(*buf, mode);
276  page = BufferGetPage(*buf);
277  TestForOldSnapshot(snapshot, idxRel, page);
278 
279  /* If we land on a revmap page, start over */
280  if (BRIN_IS_REGULAR_PAGE(page))
281  {
282  if (*off > PageGetMaxOffsetNumber(page))
283  ereport(ERROR,
284  (errcode(ERRCODE_INDEX_CORRUPTED),
285  errmsg_internal("corrupted BRIN index: inconsistent range map")));
286  lp = PageGetItemId(page, *off);
287  if (ItemIdIsUsed(lp))
288  {
289  tup = (BrinTuple *) PageGetItem(page, lp);
290 
291  if (tup->bt_blkno == heapBlk)
292  {
293  if (size)
294  *size = ItemIdGetLength(lp);
295  /* found it! */
296  return tup;
297  }
298  }
299  }
300 
301  /*
302  * No luck. Assume that the revmap was updated concurrently.
303  */
305  }
306  /* not reached, but keep compiler quiet */
307  return NULL;
308 }
#define ItemPointerIsValid(pointer)
Definition: itemptr.h:59
#define BUFFER_LOCK_UNLOCK
Definition: bufmgr.h:87
Relation rm_irel
Definition: brin_revmap.c:49
#define HEAPBLK_TO_REVMAP_INDEX(pagesPerRange, heapBlk)
Definition: brin_revmap.c:43
static void TestForOldSnapshot(Snapshot snapshot, Relation relation, Page page)
Definition: bufmgr.h:265
#define ItemIdIsUsed(itemId)
Definition: itemid.h:91
#define InvalidBuffer
Definition: buf.h:25
int errcode(int sqlerrcode)
Definition: elog.c:575
#define BRIN_IS_REGULAR_PAGE(page)
Definition: brin_page.h:57
uint32 BlockNumber
Definition: block.h:31
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3309
#define PageGetMaxOffsetNumber(page)
Definition: bufpage.h:354
#define ItemIdGetLength(itemId)
Definition: itemid.h:58
#define ERROR
Definition: elog.h:43
static char * buf
Definition: pg_test_fsync.c:66
#define BufferGetPage(buffer)
Definition: bufmgr.h:160
#define ereport(elevel, rest)
Definition: elog.h:122
#define PageGetItemId(page, offsetNumber)
Definition: bufpage.h:232
#define PageGetContents(page)
Definition: bufpage.h:243
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:3546
#define InvalidOffsetNumber
Definition: off.h:26
BlockNumber bt_blkno
Definition: brin_tuple.h:57
int errmsg_internal(const char *fmt,...)
Definition: elog.c:827
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
Buffer rm_currBuf
Definition: brin_revmap.c:53
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
Definition: bufmgr.c:594
#define InvalidBlockNumber
Definition: block.h:33
#define BufferIsValid(bufnum)
Definition: bufmgr.h:114
#define ItemPointerGetOffsetNumber(pointer)
Definition: itemptr.h:94
bool ItemPointerEquals(ItemPointer pointer1, ItemPointer pointer2)
Definition: itemptr.c:29
BlockNumber BufferGetBlockNumber(Buffer buffer)
Definition: bufmgr.c:2605
#define ItemPointerSetInvalid(pointer)
Definition: itemptr.h:149
BlockNumber rm_pagesPerRange
Definition: brin_revmap.c:50
#define BUFFER_LOCK_SHARE
Definition: bufmgr.h:88
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:97
#define ItemPointerGetBlockNumber(pointer)
Definition: itemptr.h:75
static BlockNumber revmap_get_blkno(BrinRevmap *revmap, BlockNumber heapBlk)
Definition: brin_revmap.c:448
#define PageGetItem(page, itemId)
Definition: bufpage.h:337
Pointer Page
Definition: bufpage.h:74
ItemPointerData rm_tids[1]
Definition: brin_page.h:85
Buffer brinLockRevmapPageForUpdate ( BrinRevmap revmap,
BlockNumber  heapBlk 
)

Definition at line 137 of file brin_revmap.c.

References BUFFER_LOCK_EXCLUSIVE, LockBuffer(), and revmap_get_buffer().

Referenced by brin_doinsert(), brin_doupdate(), and brinRevmapDesummarizeRange().

138 {
139  Buffer rmBuf;
140 
141  rmBuf = revmap_get_buffer(revmap, heapBlk);
143 
144  return rmBuf;
145 }
#define BUFFER_LOCK_EXCLUSIVE
Definition: bufmgr.h:89
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:3546
static Buffer revmap_get_buffer(BrinRevmap *revmap, BlockNumber heapBlk)
Definition: brin_revmap.c:469
int Buffer
Definition: buf.h:23
bool brinRevmapDesummarizeRange ( Relation  idxrel,
BlockNumber  heapBlk 
)

Definition at line 318 of file brin_revmap.c.

References BlockNumberIsValid, BRIN_IS_REGULAR_PAGE, brinLockRevmapPageForUpdate(), brinRevmapInitialize(), brinRevmapTerminate(), brinSetHeapBlockItemptr(), BrinTupleIsPlaceholder, BUFFER_LOCK_EXCLUSIVE, BUFFER_LOCK_UNLOCK, BufferGetPage, END_CRIT_SECTION, ereport, errcode(), errmsg(), ERROR, xl_brin_desummarize::heapBlk, HEAPBLK_TO_REVMAP_INDEX, ItemIdIsUsed, ItemPointerGetBlockNumber, ItemPointerGetOffsetNumber, ItemPointerIsValid, ItemPointerSetInvalid, LockBuffer(), MarkBufferDirty(), NULL, PageGetContents, PageGetItem, PageGetItemId, PageGetMaxOffsetNumber, PageIndexTupleDeleteNoCompact(), PageSetLSN, xl_brin_desummarize::pagesPerRange, ReadBuffer(), REGBUF_STANDARD, xl_brin_desummarize::regOffset, RelationGetRelationName, RelationNeedsWAL, revmap_get_blkno(), BrinRevmap::rm_pagesPerRange, RevmapContents::rm_tids, SizeOfBrinDesummarize, START_CRIT_SECTION, UnlockReleaseBuffer(), WARNING, XLOG_BRIN_DESUMMARIZE, XLogBeginInsert(), XLogInsert(), XLogRegisterBuffer(), and XLogRegisterData().

Referenced by brin_desummarize_range().

319 {
320  BrinRevmap *revmap;
321  BlockNumber pagesPerRange;
322  RevmapContents *contents;
323  ItemPointerData *iptr;
324  ItemPointerData invalidIptr;
325  BlockNumber revmapBlk;
326  Buffer revmapBuf;
327  Buffer regBuf;
328  Page revmapPg;
329  Page regPg;
330  OffsetNumber revmapOffset;
331  OffsetNumber regOffset;
332  ItemId lp;
333  BrinTuple *tup;
334 
335  revmap = brinRevmapInitialize(idxrel, &pagesPerRange, NULL);
336 
337  revmapBlk = revmap_get_blkno(revmap, heapBlk);
338  if (!BlockNumberIsValid(revmapBlk))
339  {
340  /* revmap page doesn't exist: range not summarized, we're done */
341  brinRevmapTerminate(revmap);
342  return true;
343  }
344 
345  /* Lock the revmap page, obtain the index tuple pointer from it */
346  revmapBuf = brinLockRevmapPageForUpdate(revmap, heapBlk);
347  revmapPg = BufferGetPage(revmapBuf);
348  revmapOffset = HEAPBLK_TO_REVMAP_INDEX(revmap->rm_pagesPerRange, heapBlk);
349 
350  contents = (RevmapContents *) PageGetContents(revmapPg);
351  iptr = contents->rm_tids;
352  iptr += revmapOffset;
353 
354  if (!ItemPointerIsValid(iptr))
355  {
356  /* no index tuple: range not summarized, we're done */
357  LockBuffer(revmapBuf, BUFFER_LOCK_UNLOCK);
358  brinRevmapTerminate(revmap);
359  return true;
360  }
361 
362  regBuf = ReadBuffer(idxrel, ItemPointerGetBlockNumber(iptr));
364  regPg = BufferGetPage(regBuf);
365 
366  /* if this is no longer a regular page, tell caller to start over */
367  if (!BRIN_IS_REGULAR_PAGE(regPg))
368  {
369  LockBuffer(revmapBuf, BUFFER_LOCK_UNLOCK);
371  brinRevmapTerminate(revmap);
372  return false;
373  }
374 
375  regOffset = ItemPointerGetOffsetNumber(iptr);
376  if (regOffset > PageGetMaxOffsetNumber(regPg))
377  ereport(ERROR,
378  (errcode(ERRCODE_INDEX_CORRUPTED),
379  errmsg("corrupted BRIN index: inconsistent range map")));
380 
381  lp = PageGetItemId(regPg, regOffset);
382  if (!ItemIdIsUsed(lp))
383  ereport(ERROR,
384  (errcode(ERRCODE_INDEX_CORRUPTED),
385  errmsg("corrupted BRIN index: inconsistent range map")));
386  tup = (BrinTuple *) PageGetItem(regPg, lp);
387  /* XXX apply sanity checks? Might as well delete a bogus tuple ... */
388 
389  /*
390  * We're only removing data, not reading it, so there's no need to
391  * TestForOldSnapshot here.
392  */
393 
394  /*
395  * Because of SUE lock, this function shouldn't run concurrently with
396  * summarization. Placeholder tuples can only exist as leftovers from
397  * crashed summarization, so if we detect any, we complain but proceed.
398  */
399  if (BrinTupleIsPlaceholder(tup))
401  (errmsg("leftover placeholder tuple detected in BRIN index \"%s\", deleting",
402  RelationGetRelationName(idxrel))));
403 
405 
406  ItemPointerSetInvalid(&invalidIptr);
407  brinSetHeapBlockItemptr(revmapBuf, revmap->rm_pagesPerRange, heapBlk,
408  invalidIptr);
409  PageIndexTupleDeleteNoCompact(regPg, regOffset);
410  /* XXX record free space in FSM? */
411 
412  MarkBufferDirty(regBuf);
413  MarkBufferDirty(revmapBuf);
414 
415  if (RelationNeedsWAL(idxrel))
416  {
417  xl_brin_desummarize xlrec;
418  XLogRecPtr recptr;
419 
420  xlrec.pagesPerRange = revmap->rm_pagesPerRange;
421  xlrec.heapBlk = heapBlk;
422  xlrec.regOffset = regOffset;
423 
424  XLogBeginInsert();
425  XLogRegisterData((char *) &xlrec, SizeOfBrinDesummarize);
426  XLogRegisterBuffer(0, revmapBuf, 0);
428  recptr = XLogInsert(RM_BRIN_ID, XLOG_BRIN_DESUMMARIZE);
429  PageSetLSN(revmapPg, recptr);
430  PageSetLSN(regPg, recptr);
431  }
432 
434 
435  UnlockReleaseBuffer(regBuf);
436  LockBuffer(revmapBuf, BUFFER_LOCK_UNLOCK);
437  brinRevmapTerminate(revmap);
438 
439  return true;
440 }
#define ItemPointerIsValid(pointer)
Definition: itemptr.h:59
#define BrinTupleIsPlaceholder(tup)
Definition: brin_tuple.h:83
#define BUFFER_LOCK_UNLOCK
Definition: bufmgr.h:87
#define HEAPBLK_TO_REVMAP_INDEX(pagesPerRange, heapBlk)
Definition: brin_revmap.c:43
OffsetNumber regOffset
Definition: brin_xlog.h:139
BlockNumber pagesPerRange
Definition: brin_xlog.h:135
void brinRevmapTerminate(BrinRevmap *revmap)
Definition: brin_revmap.c:103
void MarkBufferDirty(Buffer buffer)
Definition: bufmgr.c:1450
void XLogRegisterBuffer(uint8 block_id, Buffer buffer, uint8 flags)
Definition: xloginsert.c:213
#define END_CRIT_SECTION()
Definition: miscadmin.h:132
#define ItemIdIsUsed(itemId)
Definition: itemid.h:91
Buffer brinLockRevmapPageForUpdate(BrinRevmap *revmap, BlockNumber heapBlk)
Definition: brin_revmap.c:137
#define START_CRIT_SECTION()
Definition: miscadmin.h:130
int errcode(int sqlerrcode)
Definition: elog.c:575
#define BRIN_IS_REGULAR_PAGE(page)
Definition: brin_page.h:57
uint32 BlockNumber
Definition: block.h:31
#define BUFFER_LOCK_EXCLUSIVE
Definition: bufmgr.h:89
#define PageGetMaxOffsetNumber(page)
Definition: bufpage.h:354
uint16 OffsetNumber
Definition: off.h:24
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3332
#define ERROR
Definition: elog.h:43
#define XLOG_BRIN_DESUMMARIZE
Definition: brin_xlog.h:36
#define REGBUF_STANDARD
Definition: xloginsert.h:35
#define RelationGetRelationName(relation)
Definition: rel.h:437
#define BufferGetPage(buffer)
Definition: bufmgr.h:160
#define ereport(elevel, rest)
Definition: elog.h:122
#define WARNING
Definition: elog.h:40
#define PageGetItemId(page, offsetNumber)
Definition: bufpage.h:232
void XLogRegisterData(char *data, int len)
Definition: xloginsert.c:323
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition: xloginsert.c:415
#define PageGetContents(page)
Definition: bufpage.h:243
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:3546
#define BlockNumberIsValid(blockNumber)
Definition: block.h:70
void PageIndexTupleDeleteNoCompact(Page page, OffsetNumber offnum)
Definition: bufpage.c:958
#define NULL
Definition: c.h:229
uint64 XLogRecPtr
Definition: xlogdefs.h:21
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
Definition: bufmgr.c:594
BrinRevmap * brinRevmapInitialize(Relation idxrel, BlockNumber *pagesPerRange, Snapshot snapshot)
Definition: brin_revmap.c:71
#define ItemPointerGetOffsetNumber(pointer)
Definition: itemptr.h:94
BlockNumber heapBlk
Definition: brin_xlog.h:137
#define SizeOfBrinDesummarize
Definition: brin_xlog.h:142
#define RelationNeedsWAL(relation)
Definition: rel.h:506
#define ItemPointerSetInvalid(pointer)
Definition: itemptr.h:149
BlockNumber rm_pagesPerRange
Definition: brin_revmap.c:50
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define ItemPointerGetBlockNumber(pointer)
Definition: itemptr.h:75
static BlockNumber revmap_get_blkno(BrinRevmap *revmap, BlockNumber heapBlk)
Definition: brin_revmap.c:448
void brinSetHeapBlockItemptr(Buffer buf, BlockNumber pagesPerRange, BlockNumber heapBlk, ItemPointerData tid)
Definition: brin_revmap.c:158
void XLogBeginInsert(void)
Definition: xloginsert.c:120
#define PageSetLSN(page, lsn)
Definition: bufpage.h:365
int Buffer
Definition: buf.h:23
#define PageGetItem(page, itemId)
Definition: bufpage.h:337
Pointer Page
Definition: bufpage.h:74
ItemPointerData rm_tids[1]
Definition: brin_page.h:85
void brinRevmapExtend ( BrinRevmap revmap,
BlockNumber  heapBlk 
)

Definition at line 115 of file brin_revmap.c.

References Assert, BRIN_METAPAGE_BLKNO, InvalidBlockNumber, PG_USED_FOR_ASSERTS_ONLY, and revmap_extend_and_get_blkno().

Referenced by brin_doinsert(), and brin_doupdate().

116 {
118 
119  mapBlk = revmap_extend_and_get_blkno(revmap, heapBlk);
120 
121  /* Ensure the buffer we got is in the expected range */
122  Assert(mapBlk != InvalidBlockNumber &&
123  mapBlk != BRIN_METAPAGE_BLKNO &&
124  mapBlk <= revmap->rm_lastRevmapPage);
125 }
static BlockNumber revmap_extend_and_get_blkno(BrinRevmap *revmap, BlockNumber heapBlk)
Definition: brin_revmap.c:506
#define BRIN_METAPAGE_BLKNO
Definition: brin_page.h:75
uint32 BlockNumber
Definition: block.h:31
#define Assert(condition)
Definition: c.h:675
#define InvalidBlockNumber
Definition: block.h:33
#define PG_USED_FOR_ASSERTS_ONLY
Definition: c.h:990
BrinRevmap* brinRevmapInitialize ( Relation  idxrel,
BlockNumber pagesPerRange,
Snapshot  snapshot 
)

Definition at line 71 of file brin_revmap.c.

References BRIN_METAPAGE_BLKNO, BUFFER_LOCK_SHARE, BUFFER_LOCK_UNLOCK, BufferGetPage, InvalidBuffer, BrinMetaPageData::lastRevmapPage, LockBuffer(), PageGetContents, BrinMetaPageData::pagesPerRange, palloc(), ReadBuffer(), BrinRevmap::rm_currBuf, BrinRevmap::rm_irel, BrinRevmap::rm_lastRevmapPage, BrinRevmap::rm_metaBuf, BrinRevmap::rm_pagesPerRange, and TestForOldSnapshot().

Referenced by brinbeginscan(), brinbuild(), brininsert(), brinRevmapDesummarizeRange(), and brinsummarize().

73 {
74  BrinRevmap *revmap;
75  Buffer meta;
76  BrinMetaPageData *metadata;
77  Page page;
78 
79  meta = ReadBuffer(idxrel, BRIN_METAPAGE_BLKNO);
81  page = BufferGetPage(meta);
82  TestForOldSnapshot(snapshot, idxrel, page);
83  metadata = (BrinMetaPageData *) PageGetContents(page);
84 
85  revmap = palloc(sizeof(BrinRevmap));
86  revmap->rm_irel = idxrel;
87  revmap->rm_pagesPerRange = metadata->pagesPerRange;
88  revmap->rm_lastRevmapPage = metadata->lastRevmapPage;
89  revmap->rm_metaBuf = meta;
90  revmap->rm_currBuf = InvalidBuffer;
91 
92  *pagesPerRange = metadata->pagesPerRange;
93 
95 
96  return revmap;
97 }
BlockNumber rm_lastRevmapPage
Definition: brin_revmap.c:51
#define BUFFER_LOCK_UNLOCK
Definition: bufmgr.h:87
Relation rm_irel
Definition: brin_revmap.c:49
static void TestForOldSnapshot(Snapshot snapshot, Relation relation, Page page)
Definition: bufmgr.h:265
#define BRIN_METAPAGE_BLKNO
Definition: brin_page.h:75
#define InvalidBuffer
Definition: buf.h:25
#define BufferGetPage(buffer)
Definition: bufmgr.h:160
BlockNumber lastRevmapPage
Definition: brin_page.h:69
#define PageGetContents(page)
Definition: bufpage.h:243
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:3546
BlockNumber pagesPerRange
Definition: brin_page.h:68
Buffer rm_currBuf
Definition: brin_revmap.c:53
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
Definition: bufmgr.c:594
Buffer rm_metaBuf
Definition: brin_revmap.c:52
void * palloc(Size size)
Definition: mcxt.c:849
BlockNumber rm_pagesPerRange
Definition: brin_revmap.c:50
#define BUFFER_LOCK_SHARE
Definition: bufmgr.h:88
int Buffer
Definition: buf.h:23
Pointer Page
Definition: bufpage.h:74
void brinRevmapTerminate ( BrinRevmap revmap)

Definition at line 103 of file brin_revmap.c.

References InvalidBuffer, pfree(), ReleaseBuffer(), BrinRevmap::rm_currBuf, and BrinRevmap::rm_metaBuf.

Referenced by brinbuild(), brinendscan(), brininsert(), brinRevmapDesummarizeRange(), and brinsummarize().

104 {
105  ReleaseBuffer(revmap->rm_metaBuf);
106  if (revmap->rm_currBuf != InvalidBuffer)
107  ReleaseBuffer(revmap->rm_currBuf);
108  pfree(revmap);
109 }
#define InvalidBuffer
Definition: buf.h:25
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3309
void pfree(void *pointer)
Definition: mcxt.c:950
Buffer rm_currBuf
Definition: brin_revmap.c:53
Buffer rm_metaBuf
Definition: brin_revmap.c:52
void brinSetHeapBlockItemptr ( Buffer  rmbuf,
BlockNumber  pagesPerRange,
BlockNumber  heapBlk,
ItemPointerData  tid 
)

Definition at line 158 of file brin_revmap.c.

References BufferGetPage, HEAPBLK_TO_REVMAP_INDEX, ItemPointerGetBlockNumber, ItemPointerGetOffsetNumber, ItemPointerIsValid, ItemPointerSet, ItemPointerSetInvalid, PageGetContents, and RevmapContents::rm_tids.

Referenced by brin_doinsert(), brin_doupdate(), brin_xlog_desummarize_page(), brin_xlog_insert_update(), and brinRevmapDesummarizeRange().

160 {
161  RevmapContents *contents;
162  ItemPointerData *iptr;
163  Page page;
164 
165  /* The correct page should already be pinned and locked */
166  page = BufferGetPage(buf);
167  contents = (RevmapContents *) PageGetContents(page);
168  iptr = (ItemPointerData *) contents->rm_tids;
169  iptr += HEAPBLK_TO_REVMAP_INDEX(pagesPerRange, heapBlk);
170 
171  if (ItemPointerIsValid(&tid))
172  ItemPointerSet(iptr,
175  else
176  ItemPointerSetInvalid(iptr);
177 }
#define ItemPointerIsValid(pointer)
Definition: itemptr.h:59
#define HEAPBLK_TO_REVMAP_INDEX(pagesPerRange, heapBlk)
Definition: brin_revmap.c:43
static char * buf
Definition: pg_test_fsync.c:66
#define BufferGetPage(buffer)
Definition: bufmgr.h:160
#define PageGetContents(page)
Definition: bufpage.h:243
#define ItemPointerGetOffsetNumber(pointer)
Definition: itemptr.h:94
#define ItemPointerSetInvalid(pointer)
Definition: itemptr.h:149
#define ItemPointerGetBlockNumber(pointer)
Definition: itemptr.h:75
Pointer Page
Definition: bufpage.h:74
#define ItemPointerSet(pointer, blockNumber, offNum)
Definition: itemptr.h:104
ItemPointerData rm_tids[1]
Definition: brin_page.h:85