PostgreSQL Source Code  git master
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 buf, 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

◆ BrinRevmap

typedef struct BrinRevmap BrinRevmap

Definition at line 24 of file brin_revmap.h.

Function Documentation

◆ brinGetTupleForHeapBlock()

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

Definition at line 197 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(), 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().

200 {
201  Relation idxRel = revmap->rm_irel;
202  BlockNumber mapBlk;
203  RevmapContents *contents;
204  ItemPointerData *iptr;
205  BlockNumber blk;
206  Page page;
207  ItemId lp;
208  BrinTuple *tup;
209  ItemPointerData previptr;
210 
211  /* normalize the heap block number to be the first page in the range */
212  heapBlk = (heapBlk / revmap->rm_pagesPerRange) * revmap->rm_pagesPerRange;
213 
214  /*
215  * Compute the revmap page number we need. If Invalid is returned (i.e.,
216  * the revmap page hasn't been created yet), the requested page range is
217  * not summarized.
218  */
219  mapBlk = revmap_get_blkno(revmap, heapBlk);
220  if (mapBlk == InvalidBlockNumber)
221  {
222  *off = InvalidOffsetNumber;
223  return NULL;
224  }
225 
226  ItemPointerSetInvalid(&previptr);
227  for (;;)
228  {
230 
231  if (revmap->rm_currBuf == InvalidBuffer ||
232  BufferGetBlockNumber(revmap->rm_currBuf) != mapBlk)
233  {
234  if (revmap->rm_currBuf != InvalidBuffer)
235  ReleaseBuffer(revmap->rm_currBuf);
236 
237  Assert(mapBlk != InvalidBlockNumber);
238  revmap->rm_currBuf = ReadBuffer(revmap->rm_irel, mapBlk);
239  }
240 
242 
243  contents = (RevmapContents *)
245  iptr = contents->rm_tids;
246  iptr += HEAPBLK_TO_REVMAP_INDEX(revmap->rm_pagesPerRange, heapBlk);
247 
248  if (!ItemPointerIsValid(iptr))
249  {
251  return NULL;
252  }
253 
254  /*
255  * Check the TID we got in a previous iteration, if any, and save the
256  * current TID we got from the revmap; if we loop, we can sanity-check
257  * that the next one we get is different. Otherwise we might be stuck
258  * looping forever if the revmap is somehow badly broken.
259  */
260  if (ItemPointerIsValid(&previptr) && ItemPointerEquals(&previptr, iptr))
261  ereport(ERROR,
262  (errcode(ERRCODE_INDEX_CORRUPTED),
263  errmsg_internal("corrupted BRIN index: inconsistent range map")));
264  previptr = *iptr;
265 
266  blk = ItemPointerGetBlockNumber(iptr);
267  *off = ItemPointerGetOffsetNumber(iptr);
268 
270 
271  /* Ok, got a pointer to where the BrinTuple should be. Fetch it. */
272  if (!BufferIsValid(*buf) || BufferGetBlockNumber(*buf) != blk)
273  {
274  if (BufferIsValid(*buf))
275  ReleaseBuffer(*buf);
276  *buf = ReadBuffer(idxRel, blk);
277  }
278  LockBuffer(*buf, mode);
279  page = BufferGetPage(*buf);
280  TestForOldSnapshot(snapshot, idxRel, page);
281 
282  /* If we land on a revmap page, start over */
283  if (BRIN_IS_REGULAR_PAGE(page))
284  {
285  /*
286  * If the offset number is greater than what's in the page, it's
287  * possible that the range was desummarized concurrently. Just
288  * return NULL to handle that case.
289  */
290  if (*off > PageGetMaxOffsetNumber(page))
291  {
293  return NULL;
294  }
295 
296  lp = PageGetItemId(page, *off);
297  if (ItemIdIsUsed(lp))
298  {
299  tup = (BrinTuple *) PageGetItem(page, lp);
300 
301  if (tup->bt_blkno == heapBlk)
302  {
303  if (size)
304  *size = ItemIdGetLength(lp);
305  /* found it! */
306  return tup;
307  }
308  }
309  }
310 
311  /*
312  * No luck. Assume that the revmap was updated concurrently.
313  */
315  }
316  /* not reached, but keep compiler quiet */
317  return NULL;
318 }
#define ItemPointerIsValid(pointer)
Definition: itemptr.h:82
static PgChecksumMode mode
Definition: pg_checksums.c:61
#define BUFFER_LOCK_UNLOCK
Definition: bufmgr.h:96
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:280
#define ItemIdIsUsed(itemId)
Definition: itemid.h:92
#define InvalidBuffer
Definition: buf.h:25
int errcode(int sqlerrcode)
Definition: elog.c:610
#define BRIN_IS_REGULAR_PAGE(page)
Definition: brin_page.h:57
uint32 BlockNumber
Definition: block.h:31
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3513
#define PageGetMaxOffsetNumber(page)
Definition: bufpage.h:357
#define ItemIdGetLength(itemId)
Definition: itemid.h:59
#define ERROR
Definition: elog.h:43
static char * buf
Definition: pg_test_fsync.c:68
#define BufferGetPage(buffer)
Definition: bufmgr.h:169
#define PageGetItemId(page, offsetNumber)
Definition: bufpage.h:235
#define PageGetContents(page)
Definition: bufpage.h:246
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:3752
#define InvalidOffsetNumber
Definition: off.h:26
#define ereport(elevel,...)
Definition: elog.h:144
BlockNumber bt_blkno
Definition: brin_tuple.h:57
int errmsg_internal(const char *fmt,...)
Definition: elog.c:908
#define Assert(condition)
Definition: c.h:746
Buffer rm_currBuf
Definition: brin_revmap.c:53
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
Definition: bufmgr.c:607
#define InvalidBlockNumber
Definition: block.h:33
#define BufferIsValid(bufnum)
Definition: bufmgr.h:123
#define ItemPointerGetOffsetNumber(pointer)
Definition: itemptr.h:117
bool ItemPointerEquals(ItemPointer pointer1, ItemPointer pointer2)
Definition: itemptr.c:29
BlockNumber BufferGetBlockNumber(Buffer buffer)
Definition: bufmgr.c:2663
#define ItemPointerSetInvalid(pointer)
Definition: itemptr.h:172
BlockNumber rm_pagesPerRange
Definition: brin_revmap.c:50
#define BUFFER_LOCK_SHARE
Definition: bufmgr.h:97
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:99
#define ItemPointerGetBlockNumber(pointer)
Definition: itemptr.h:98
static BlockNumber revmap_get_blkno(BrinRevmap *revmap, BlockNumber heapBlk)
Definition: brin_revmap.c:451
#define PageGetItem(page, itemId)
Definition: bufpage.h:340
Pointer Page
Definition: bufpage.h:78
ItemPointerData rm_tids[1]
Definition: brin_page.h:85

◆ brinLockRevmapPageForUpdate()

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:98
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:3752
static Buffer revmap_get_buffer(BrinRevmap *revmap, BlockNumber heapBlk)
Definition: brin_revmap.c:472
int Buffer
Definition: buf.h:23

◆ brinRevmapDesummarizeRange()

bool brinRevmapDesummarizeRange ( Relation  idxrel,
BlockNumber  heapBlk 
)

Definition at line 328 of file brin_revmap.c.

References BlockNumberIsValid, BRIN_IS_REGULAR_PAGE, brinLockRevmapPageForUpdate(), brinRevmapInitialize(), brinRevmapTerminate(), brinSetHeapBlockItemptr(), 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(), PageGetContents, PageGetItemId, PageGetMaxOffsetNumber, PageIndexTupleDeleteNoCompact(), PageSetLSN, xl_brin_desummarize::pagesPerRange, ReadBuffer(), REGBUF_STANDARD, xl_brin_desummarize::regOffset, RelationNeedsWAL, revmap_get_blkno(), BrinRevmap::rm_pagesPerRange, RevmapContents::rm_tids, SizeOfBrinDesummarize, START_CRIT_SECTION, UnlockReleaseBuffer(), XLOG_BRIN_DESUMMARIZE, XLogBeginInsert(), XLogInsert(), XLogRegisterBuffer(), and XLogRegisterData().

Referenced by brin_desummarize_range().

329 {
330  BrinRevmap *revmap;
331  BlockNumber pagesPerRange;
332  RevmapContents *contents;
333  ItemPointerData *iptr;
334  ItemPointerData invalidIptr;
335  BlockNumber revmapBlk;
336  Buffer revmapBuf;
337  Buffer regBuf;
338  Page revmapPg;
339  Page regPg;
340  OffsetNumber revmapOffset;
341  OffsetNumber regOffset;
342  ItemId lp;
343 
344  revmap = brinRevmapInitialize(idxrel, &pagesPerRange, NULL);
345 
346  revmapBlk = revmap_get_blkno(revmap, heapBlk);
347  if (!BlockNumberIsValid(revmapBlk))
348  {
349  /* revmap page doesn't exist: range not summarized, we're done */
350  brinRevmapTerminate(revmap);
351  return true;
352  }
353 
354  /* Lock the revmap page, obtain the index tuple pointer from it */
355  revmapBuf = brinLockRevmapPageForUpdate(revmap, heapBlk);
356  revmapPg = BufferGetPage(revmapBuf);
357  revmapOffset = HEAPBLK_TO_REVMAP_INDEX(revmap->rm_pagesPerRange, heapBlk);
358 
359  contents = (RevmapContents *) PageGetContents(revmapPg);
360  iptr = contents->rm_tids;
361  iptr += revmapOffset;
362 
363  if (!ItemPointerIsValid(iptr))
364  {
365  /* no index tuple: range not summarized, we're done */
366  LockBuffer(revmapBuf, BUFFER_LOCK_UNLOCK);
367  brinRevmapTerminate(revmap);
368  return true;
369  }
370 
371  regBuf = ReadBuffer(idxrel, ItemPointerGetBlockNumber(iptr));
373  regPg = BufferGetPage(regBuf);
374  /*
375  * We're only removing data, not reading it, so there's no need to
376  * TestForOldSnapshot here.
377  */
378 
379  /* if this is no longer a regular page, tell caller to start over */
380  if (!BRIN_IS_REGULAR_PAGE(regPg))
381  {
382  LockBuffer(revmapBuf, BUFFER_LOCK_UNLOCK);
384  brinRevmapTerminate(revmap);
385  return false;
386  }
387 
388  regOffset = ItemPointerGetOffsetNumber(iptr);
389  if (regOffset > PageGetMaxOffsetNumber(regPg))
390  ereport(ERROR,
391  (errcode(ERRCODE_INDEX_CORRUPTED),
392  errmsg("corrupted BRIN index: inconsistent range map")));
393 
394  lp = PageGetItemId(regPg, regOffset);
395  if (!ItemIdIsUsed(lp))
396  ereport(ERROR,
397  (errcode(ERRCODE_INDEX_CORRUPTED),
398  errmsg("corrupted BRIN index: inconsistent range map")));
399 
400  /*
401  * Placeholder tuples only appear during unfinished summarization, and we
402  * hold ShareUpdateExclusiveLock, so this function cannot run concurrently
403  * with that. So any placeholder tuples that exist are leftovers from a
404  * crashed or aborted summarization; remove them silently.
405  */
406 
408 
409  ItemPointerSetInvalid(&invalidIptr);
410  brinSetHeapBlockItemptr(revmapBuf, revmap->rm_pagesPerRange, heapBlk,
411  invalidIptr);
412  PageIndexTupleDeleteNoCompact(regPg, regOffset);
413  /* XXX record free space in FSM? */
414 
415  MarkBufferDirty(regBuf);
416  MarkBufferDirty(revmapBuf);
417 
418  if (RelationNeedsWAL(idxrel))
419  {
420  xl_brin_desummarize xlrec;
421  XLogRecPtr recptr;
422 
423  xlrec.pagesPerRange = revmap->rm_pagesPerRange;
424  xlrec.heapBlk = heapBlk;
425  xlrec.regOffset = regOffset;
426 
427  XLogBeginInsert();
428  XLogRegisterData((char *) &xlrec, SizeOfBrinDesummarize);
429  XLogRegisterBuffer(0, revmapBuf, 0);
431  recptr = XLogInsert(RM_BRIN_ID, XLOG_BRIN_DESUMMARIZE);
432  PageSetLSN(revmapPg, recptr);
433  PageSetLSN(regPg, recptr);
434  }
435 
437 
438  UnlockReleaseBuffer(regBuf);
439  LockBuffer(revmapBuf, BUFFER_LOCK_UNLOCK);
440  brinRevmapTerminate(revmap);
441 
442  return true;
443 }
#define ItemPointerIsValid(pointer)
Definition: itemptr.h:82
#define BUFFER_LOCK_UNLOCK
Definition: bufmgr.h:96
#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:1471
void XLogRegisterBuffer(uint8 block_id, Buffer buffer, uint8 flags)
Definition: xloginsert.c:220
#define END_CRIT_SECTION()
Definition: miscadmin.h:134
#define ItemIdIsUsed(itemId)
Definition: itemid.h:92
Buffer brinLockRevmapPageForUpdate(BrinRevmap *revmap, BlockNumber heapBlk)
Definition: brin_revmap.c:137
#define START_CRIT_SECTION()
Definition: miscadmin.h:132
int errcode(int sqlerrcode)
Definition: elog.c:610
#define BRIN_IS_REGULAR_PAGE(page)
Definition: brin_page.h:57
uint32 BlockNumber
Definition: block.h:31
#define BUFFER_LOCK_EXCLUSIVE
Definition: bufmgr.h:98
#define PageGetMaxOffsetNumber(page)
Definition: bufpage.h:357
uint16 OffsetNumber
Definition: off.h:24
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3536
#define ERROR
Definition: elog.h:43
#define XLOG_BRIN_DESUMMARIZE
Definition: brin_xlog.h:36
#define REGBUF_STANDARD
Definition: xloginsert.h:35
#define BufferGetPage(buffer)
Definition: bufmgr.h:169
#define PageGetItemId(page, offsetNumber)
Definition: bufpage.h:235
void XLogRegisterData(char *data, int len)
Definition: xloginsert.c:330
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition: xloginsert.c:422
#define PageGetContents(page)
Definition: bufpage.h:246
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:3752
#define ereport(elevel,...)
Definition: elog.h:144
#define BlockNumberIsValid(blockNumber)
Definition: block.h:70
void PageIndexTupleDeleteNoCompact(Page page, OffsetNumber offnum)
Definition: bufpage.c:1178
uint64 XLogRecPtr
Definition: xlogdefs.h:21
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
Definition: bufmgr.c:607
BrinRevmap * brinRevmapInitialize(Relation idxrel, BlockNumber *pagesPerRange, Snapshot snapshot)
Definition: brin_revmap.c:71
#define ItemPointerGetOffsetNumber(pointer)
Definition: itemptr.h:117
BlockNumber heapBlk
Definition: brin_xlog.h:137
#define SizeOfBrinDesummarize
Definition: brin_xlog.h:142
#define RelationNeedsWAL(relation)
Definition: rel.h:562
#define ItemPointerSetInvalid(pointer)
Definition: itemptr.h:172
BlockNumber rm_pagesPerRange
Definition: brin_revmap.c:50
int errmsg(const char *fmt,...)
Definition: elog.c:821
#define ItemPointerGetBlockNumber(pointer)
Definition: itemptr.h:98
static BlockNumber revmap_get_blkno(BrinRevmap *revmap, BlockNumber heapBlk)
Definition: brin_revmap.c:451
void brinSetHeapBlockItemptr(Buffer buf, BlockNumber pagesPerRange, BlockNumber heapBlk, ItemPointerData tid)
Definition: brin_revmap.c:158
void XLogBeginInsert(void)
Definition: xloginsert.c:123
#define PageSetLSN(page, lsn)
Definition: bufpage.h:368
int Buffer
Definition: buf.h:23
Pointer Page
Definition: bufpage.h:78
ItemPointerData rm_tids[1]
Definition: brin_page.h:85

◆ brinRevmapExtend()

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, revmap_extend_and_get_blkno(), and BrinRevmap::rm_lastRevmapPage.

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:509
#define BRIN_METAPAGE_BLKNO
Definition: brin_page.h:75
uint32 BlockNumber
Definition: block.h:31
#define Assert(condition)
Definition: c.h:746
#define InvalidBlockNumber
Definition: block.h:33
#define PG_USED_FOR_ASSERTS_ONLY
Definition: c.h:122

◆ brinRevmapInitialize()

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:96
Relation rm_irel
Definition: brin_revmap.c:49
static void TestForOldSnapshot(Snapshot snapshot, Relation relation, Page page)
Definition: bufmgr.h:280
#define BRIN_METAPAGE_BLKNO
Definition: brin_page.h:75
#define InvalidBuffer
Definition: buf.h:25
#define BufferGetPage(buffer)
Definition: bufmgr.h:169
BlockNumber lastRevmapPage
Definition: brin_page.h:69
#define PageGetContents(page)
Definition: bufpage.h:246
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:3752
BlockNumber pagesPerRange
Definition: brin_page.h:68
Buffer rm_currBuf
Definition: brin_revmap.c:53
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
Definition: bufmgr.c:607
Buffer rm_metaBuf
Definition: brin_revmap.c:52
void * palloc(Size size)
Definition: mcxt.c:950
BlockNumber rm_pagesPerRange
Definition: brin_revmap.c:50
#define BUFFER_LOCK_SHARE
Definition: bufmgr.h:97
int Buffer
Definition: buf.h:23
Pointer Page
Definition: bufpage.h:78

◆ brinRevmapTerminate()

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:3513
void pfree(void *pointer)
Definition: mcxt.c:1057
Buffer rm_currBuf
Definition: brin_revmap.c:53
Buffer rm_metaBuf
Definition: brin_revmap.c:52

◆ brinSetHeapBlockItemptr()

void brinSetHeapBlockItemptr ( Buffer  buf,
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:82
#define HEAPBLK_TO_REVMAP_INDEX(pagesPerRange, heapBlk)
Definition: brin_revmap.c:43
static char * buf
Definition: pg_test_fsync.c:68
#define BufferGetPage(buffer)
Definition: bufmgr.h:169
#define PageGetContents(page)
Definition: bufpage.h:246
#define ItemPointerGetOffsetNumber(pointer)
Definition: itemptr.h:117
#define ItemPointerSetInvalid(pointer)
Definition: itemptr.h:172
#define ItemPointerGetBlockNumber(pointer)
Definition: itemptr.h:98
Pointer Page
Definition: bufpage.h:78
#define ItemPointerSet(pointer, blockNumber, offNum)
Definition: itemptr.h:127
ItemPointerData rm_tids[1]
Definition: brin_page.h:85