PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
brin_pageops.c File Reference
#include "postgres.h"
#include "access/brin_pageops.h"
#include "access/brin_page.h"
#include "access/brin_revmap.h"
#include "access/brin_xlog.h"
#include "access/xloginsert.h"
#include "miscadmin.h"
#include "storage/bufmgr.h"
#include "storage/freespace.h"
#include "storage/lmgr.h"
#include "storage/smgr.h"
#include "utils/rel.h"
Include dependency graph for brin_pageops.c:

Go to the source code of this file.

Macros

#define BrinMaxItemSize
 

Functions

static Buffer brin_getinsertbuffer (Relation irel, Buffer oldbuf, Size itemsz, bool *extended)
 
static Size br_page_get_freespace (Page page)
 
static void brin_initialize_empty_new_buffer (Relation idxrel, Buffer buffer)
 
bool brin_doupdate (Relation idxrel, BlockNumber pagesPerRange, BrinRevmap *revmap, BlockNumber heapBlk, Buffer oldbuf, OffsetNumber oldoff, const BrinTuple *origtup, Size origsz, const BrinTuple *newtup, Size newsz, bool samepage)
 
bool brin_can_do_samepage_update (Buffer buffer, Size origsz, Size newsz)
 
OffsetNumber brin_doinsert (Relation idxrel, BlockNumber pagesPerRange, BrinRevmap *revmap, Buffer *buffer, BlockNumber heapBlk, BrinTuple *tup, Size itemsz)
 
void brin_page_init (Page page, uint16 type)
 
void brin_metapage_init (Page page, BlockNumber pagesPerRange, uint16 version)
 
bool brin_start_evacuating_page (Relation idxRel, Buffer buf)
 
void brin_evacuate_page (Relation idxRel, BlockNumber pagesPerRange, BrinRevmap *revmap, Buffer buf)
 
bool brin_page_cleanup (Relation idxrel, Buffer buf)
 

Macro Definition Documentation

#define BrinMaxItemSize
Value:
MAXALIGN_DOWN(BLCKSZ - \
sizeof(ItemIdData)) + \
#define SizeOfPageHeaderData
Definition: bufpage.h:213
#define MAXALIGN(LEN)
Definition: c.h:588
#define MAXALIGN_DOWN(LEN)
Definition: c.h:600

Definition at line 30 of file brin_pageops.c.

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

Function Documentation

static Size br_page_get_freespace ( Page  page)
static

Definition at line 888 of file brin_pageops.c.

References BRIN_EVACUATE_PAGE, BRIN_IS_REGULAR_PAGE, BrinPageFlags, and PageGetFreeSpace().

Referenced by brin_doinsert(), brin_doupdate(), brin_getinsertbuffer(), brin_initialize_empty_new_buffer(), and brin_page_cleanup().

889 {
890  if (!BRIN_IS_REGULAR_PAGE(page) ||
891  (BrinPageFlags(page) & BRIN_EVACUATE_PAGE) != 0)
892  return 0;
893  else
894  return PageGetFreeSpace(page);
895 }
#define BRIN_IS_REGULAR_PAGE(page)
Definition: brin_page.h:57
Size PageGetFreeSpace(Page page)
Definition: bufpage.c:582
#define BRIN_EVACUATE_PAGE
Definition: brin_page.h:60
#define BrinPageFlags(page)
Definition: brin_page.h:46
bool brin_can_do_samepage_update ( Buffer  buffer,
Size  origsz,
Size  newsz 
)

Definition at line 323 of file brin_pageops.c.

References BufferGetPage, and PageGetExactFreeSpace().

Referenced by brin_doupdate(), brininsert(), and summarize_range().

324 {
325  return
326  ((newsz <= origsz) ||
327  PageGetExactFreeSpace(BufferGetPage(buffer)) >= (newsz - origsz));
328 }
#define BufferGetPage(buffer)
Definition: bufmgr.h:160
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:211
Size PageGetExactFreeSpace(Page page)
Definition: bufpage.c:633
OffsetNumber brin_doinsert ( Relation  idxrel,
BlockNumber  pagesPerRange,
BrinRevmap revmap,
Buffer buffer,
BlockNumber  heapBlk,
BrinTuple tup,
Size  itemsz 
)

Definition at line 342 of file brin_pageops.c.

References Assert, br_page_get_freespace(), BRIN_elog, brin_getinsertbuffer(), brin_page_init(), BRIN_PAGETYPE_REGULAR, brinLockRevmapPageForUpdate(), BrinMaxItemSize, brinRevmapExtend(), brinSetHeapBlockItemptr(), BUFFER_LOCK_EXCLUSIVE, BUFFER_LOCK_UNLOCK, BufferGetBlockNumber(), BufferGetPage, BufferIsValid, DEBUG2, elog, END_CRIT_SECTION, ereport, errcode(), errmsg(), ERROR, FreeSpaceMapVacuum(), xl_brin_insert::heapBlk, InvalidBuffer, InvalidOffsetNumber, ItemPointerSet, LockBuffer(), MarkBufferDirty(), MAXALIGN, xl_brin_insert::offnum, PageAddItem, PageSetLSN, xl_brin_insert::pagesPerRange, REGBUF_STANDARD, REGBUF_WILL_INIT, RelationGetRelationName, RelationNeedsWAL, SizeOfBrinInsert, START_CRIT_SECTION, UnlockReleaseBuffer(), XLOG_BRIN_INIT_PAGE, XLOG_BRIN_INSERT, XLogBeginInsert(), XLogInsert(), XLogRegisterBufData(), XLogRegisterBuffer(), and XLogRegisterData().

Referenced by form_and_insert_tuple(), and summarize_range().

345 {
346  Page page;
347  BlockNumber blk;
348  OffsetNumber off;
349  Buffer revmapbuf;
350  ItemPointerData tid;
351  bool extended;
352 
353  Assert(itemsz == MAXALIGN(itemsz));
354 
355  /* If the item is oversized, don't even bother. */
356  if (itemsz > BrinMaxItemSize)
357  {
358  ereport(ERROR,
359  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
360  errmsg("index row size %lu exceeds maximum %lu for index \"%s\"",
361  (unsigned long) itemsz,
362  (unsigned long) BrinMaxItemSize,
363  RelationGetRelationName(idxrel))));
364  return InvalidOffsetNumber; /* keep compiler quiet */
365  }
366 
367  /* Make sure the revmap is long enough to contain the entry we need */
368  brinRevmapExtend(revmap, heapBlk);
369 
370  /*
371  * Acquire lock on buffer supplied by caller, if any. If it doesn't have
372  * enough space, unpin it to obtain a new one below.
373  */
374  if (BufferIsValid(*buffer))
375  {
376  /*
377  * It's possible that another backend (or ourselves!) extended the
378  * revmap over the page we held a pin on, so we cannot assume that
379  * it's still a regular page.
380  */
383  {
386  }
387  }
388 
389  /*
390  * If we still don't have a usable buffer, have brin_getinsertbuffer
391  * obtain one for us.
392  */
393  if (!BufferIsValid(*buffer))
394  {
395  do
396  *buffer = brin_getinsertbuffer(idxrel, InvalidBuffer, itemsz, &extended);
397  while (!BufferIsValid(*buffer));
398  }
399  else
400  extended = false;
401 
402  /* Now obtain lock on revmap buffer */
403  revmapbuf = brinLockRevmapPageForUpdate(revmap, heapBlk);
404 
405  page = BufferGetPage(*buffer);
407 
408  /* Execute the actual insertion */
410  if (extended)
412  off = PageAddItem(page, (Item) tup, itemsz, InvalidOffsetNumber,
413  false, false);
414  if (off == InvalidOffsetNumber)
415  elog(ERROR, "could not insert new index tuple to page");
417 
418  BRIN_elog((DEBUG2, "inserted tuple (%u,%u) for range starting at %u",
419  blk, off, heapBlk));
420 
421  ItemPointerSet(&tid, blk, off);
422  brinSetHeapBlockItemptr(revmapbuf, pagesPerRange, heapBlk, tid);
423  MarkBufferDirty(revmapbuf);
424 
425  /* XLOG stuff */
426  if (RelationNeedsWAL(idxrel))
427  {
428  xl_brin_insert xlrec;
429  XLogRecPtr recptr;
430  uint8 info;
431 
432  info = XLOG_BRIN_INSERT | (extended ? XLOG_BRIN_INIT_PAGE : 0);
433  xlrec.heapBlk = heapBlk;
434  xlrec.pagesPerRange = pagesPerRange;
435  xlrec.offnum = off;
436 
437  XLogBeginInsert();
438  XLogRegisterData((char *) &xlrec, SizeOfBrinInsert);
439 
441  XLogRegisterBufData(0, (char *) tup, itemsz);
442 
443  XLogRegisterBuffer(1, revmapbuf, 0);
444 
445  recptr = XLogInsert(RM_BRIN_ID, info);
446 
447  PageSetLSN(page, recptr);
448  PageSetLSN(BufferGetPage(revmapbuf), recptr);
449  }
450 
452 
453  /* Tuple is firmly on buffer; we can release our locks */
455  LockBuffer(revmapbuf, BUFFER_LOCK_UNLOCK);
456 
457  if (extended)
458  FreeSpaceMapVacuum(idxrel);
459 
460  return off;
461 }
void XLogRegisterBufData(uint8 block_id, char *data, int len)
Definition: xloginsert.c:361
BlockNumber heapBlk
Definition: brin_xlog.h:65
#define BUFFER_LOCK_UNLOCK
Definition: bufmgr.h:87
#define BRIN_elog(args)
Definition: brin_internal.h:81
#define SizeOfBrinInsert
Definition: brin_xlog.h:74
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
unsigned char uint8
Definition: c.h:266
Pointer Item
Definition: item.h:17
#define InvalidBuffer
Definition: buf.h:25
Buffer brinLockRevmapPageForUpdate(BrinRevmap *revmap, BlockNumber heapBlk)
Definition: brin_revmap.c:137
#define REGBUF_WILL_INIT
Definition: xloginsert.h:32
#define START_CRIT_SECTION()
Definition: miscadmin.h:130
int errcode(int sqlerrcode)
Definition: elog.c:575
#define PageAddItem(page, item, size, offsetNumber, overwrite, is_heap)
Definition: bufpage.h:413
uint32 BlockNumber
Definition: block.h:31
#define BUFFER_LOCK_EXCLUSIVE
Definition: bufmgr.h:89
uint16 OffsetNumber
Definition: off.h:24
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3332
#define ERROR
Definition: elog.h:43
#define BRIN_PAGETYPE_REGULAR
Definition: brin_page.h:53
#define DEBUG2
Definition: elog.h:24
void brinRevmapExtend(BrinRevmap *revmap, BlockNumber heapBlk)
Definition: brin_revmap.c:115
BlockNumber pagesPerRange
Definition: brin_xlog.h:68
#define REGBUF_STANDARD
Definition: xloginsert.h:35
static Size br_page_get_freespace(Page page)
Definition: brin_pageops.c:888
#define RelationGetRelationName(relation)
Definition: rel.h:437
#define BufferGetPage(buffer)
Definition: bufmgr.h:160
#define ereport(elevel, rest)
Definition: elog.h:122
void FreeSpaceMapVacuum(Relation rel)
Definition: freespace.c:379
void XLogRegisterData(char *data, int len)
Definition: xloginsert.c:323
#define XLOG_BRIN_INIT_PAGE
Definition: brin_xlog.h:43
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition: xloginsert.c:415
#define XLOG_BRIN_INSERT
Definition: brin_xlog.h:32
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:3546
#define InvalidOffsetNumber
Definition: off.h:26
#define BrinMaxItemSize
Definition: brin_pageops.c:30
uint64 XLogRecPtr
Definition: xlogdefs.h:21
#define Assert(condition)
Definition: c.h:675
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:211
OffsetNumber offnum
Definition: brin_xlog.h:71
#define MAXALIGN(LEN)
Definition: c.h:588
#define BufferIsValid(bufnum)
Definition: bufmgr.h:114
#define RelationNeedsWAL(relation)
Definition: rel.h:506
BlockNumber BufferGetBlockNumber(Buffer buffer)
Definition: bufmgr.c:2605
int errmsg(const char *fmt,...)
Definition: elog.c:797
static Buffer brin_getinsertbuffer(Relation irel, Buffer oldbuf, Size itemsz, bool *extended)
Definition: brin_pageops.c:666
#define elog
Definition: elog.h:219
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
Pointer Page
Definition: bufpage.h:74
#define ItemPointerSet(pointer, blockNumber, offNum)
Definition: itemptr.h:104
void brin_page_init(Page page, uint16 type)
Definition: brin_pageops.c:469
bool brin_doupdate ( Relation  idxrel,
BlockNumber  pagesPerRange,
BrinRevmap revmap,
BlockNumber  heapBlk,
Buffer  oldbuf,
OffsetNumber  oldoff,
const BrinTuple origtup,
Size  origsz,
const BrinTuple newtup,
Size  newsz,
bool  samepage 
)

Definition at line 55 of file brin_pageops.c.

References Assert, BlockNumberIsValid, br_page_get_freespace(), brin_can_do_samepage_update(), BRIN_EVACUATE_PAGE, brin_getinsertbuffer(), brin_initialize_empty_new_buffer(), brin_page_init(), BRIN_PAGETYPE_REGULAR, brin_tuples_equal(), brinLockRevmapPageForUpdate(), BrinMaxItemSize, BrinPageFlags, brinRevmapExtend(), brinSetHeapBlockItemptr(), BUFFER_LOCK_EXCLUSIVE, BUFFER_LOCK_UNLOCK, BufferGetBlockNumber(), BufferGetPage, BufferIsValid, elog, END_CRIT_SECTION, ereport, errcode(), errmsg(), ERROR, FreeSpaceMapVacuum(), xl_brin_insert::heapBlk, xl_brin_update::insert, InvalidBlockNumber, InvalidBuffer, InvalidOffsetNumber, ItemIdGetLength, ItemIdIsNormal, ItemPointerSet, LockBuffer(), MarkBufferDirty(), MAXALIGN, xl_brin_insert::offnum, xl_brin_samepage_update::offnum, xl_brin_update::oldOffnum, PageAddItem, PageGetItem, PageGetItemId, PageIndexTupleDeleteNoCompact(), PageIndexTupleOverwrite(), PageSetLSN, xl_brin_insert::pagesPerRange, RecordPageWithFreeSpace(), REGBUF_STANDARD, REGBUF_WILL_INIT, RelationGetRelationName, RelationNeedsWAL, SizeOfBrinSamepageUpdate, SizeOfBrinUpdate, START_CRIT_SECTION, UnlockReleaseBuffer(), XLOG_BRIN_INIT_PAGE, XLOG_BRIN_SAMEPAGE_UPDATE, XLOG_BRIN_UPDATE, XLogBeginInsert(), XLogInsert(), XLogRegisterBufData(), XLogRegisterBuffer(), and XLogRegisterData().

Referenced by brin_evacuate_page(), brininsert(), and summarize_range().

61 {
62  Page oldpage;
63  ItemId oldlp;
64  BrinTuple *oldtup;
65  Size oldsz;
66  Buffer newbuf;
67  bool extended;
68 
69  Assert(newsz == MAXALIGN(newsz));
70 
71  /* If the item is oversized, don't bother. */
72  if (newsz > BrinMaxItemSize)
73  {
74  ereport(ERROR,
75  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
76  errmsg("index row size %lu exceeds maximum %lu for index \"%s\"",
77  (unsigned long) newsz,
78  (unsigned long) BrinMaxItemSize,
79  RelationGetRelationName(idxrel))));
80  return false; /* keep compiler quiet */
81  }
82 
83  /* make sure the revmap is long enough to contain the entry we need */
84  brinRevmapExtend(revmap, heapBlk);
85 
86  if (!samepage)
87  {
88  /* need a page on which to put the item */
89  newbuf = brin_getinsertbuffer(idxrel, oldbuf, newsz, &extended);
90  if (!BufferIsValid(newbuf))
91  {
92  Assert(!extended);
93  return false;
94  }
95 
96  /*
97  * Note: it's possible (though unlikely) that the returned newbuf is
98  * the same as oldbuf, if brin_getinsertbuffer determined that the old
99  * buffer does in fact have enough space.
100  */
101  if (newbuf == oldbuf)
102  {
103  Assert(!extended);
104  newbuf = InvalidBuffer;
105  }
106  }
107  else
108  {
110  newbuf = InvalidBuffer;
111  extended = false;
112  }
113  oldpage = BufferGetPage(oldbuf);
114  oldlp = PageGetItemId(oldpage, oldoff);
115 
116  /*
117  * Check that the old tuple wasn't updated concurrently: it might have
118  * moved someplace else entirely ...
119  */
120  if (!ItemIdIsNormal(oldlp))
121  {
123 
124  /*
125  * If this happens, and the new buffer was obtained by extending the
126  * relation, then we need to ensure we don't leave it uninitialized or
127  * forget about it.
128  */
129  if (BufferIsValid(newbuf))
130  {
131  if (extended)
132  brin_initialize_empty_new_buffer(idxrel, newbuf);
133  UnlockReleaseBuffer(newbuf);
134  if (extended)
135  FreeSpaceMapVacuum(idxrel);
136  }
137  return false;
138  }
139 
140  oldsz = ItemIdGetLength(oldlp);
141  oldtup = (BrinTuple *) PageGetItem(oldpage, oldlp);
142 
143  /*
144  * ... or it might have been updated in place to different contents.
145  */
146  if (!brin_tuples_equal(oldtup, oldsz, origtup, origsz))
147  {
149  if (BufferIsValid(newbuf))
150  {
151  if (extended)
152  brin_initialize_empty_new_buffer(idxrel, newbuf);
153  UnlockReleaseBuffer(newbuf);
154  if (extended)
155  FreeSpaceMapVacuum(idxrel);
156  }
157  return false;
158  }
159 
160  /*
161  * Great, the old tuple is intact. We can proceed with the update.
162  *
163  * If there's enough room in the old page for the new tuple, replace it.
164  *
165  * Note that there might now be enough space on the page even though the
166  * caller told us there isn't, if a concurrent update moved another tuple
167  * elsewhere or replaced a tuple with a smaller one.
168  */
169  if (((BrinPageFlags(oldpage) & BRIN_EVACUATE_PAGE) == 0) &&
170  brin_can_do_samepage_update(oldbuf, origsz, newsz))
171  {
172  if (BufferIsValid(newbuf))
173  {
174  /* as above */
175  if (extended)
176  brin_initialize_empty_new_buffer(idxrel, newbuf);
177  UnlockReleaseBuffer(newbuf);
178  }
179 
181  if (!PageIndexTupleOverwrite(oldpage, oldoff, (Item) newtup, newsz))
182  elog(ERROR, "failed to replace BRIN tuple");
183  MarkBufferDirty(oldbuf);
184 
185  /* XLOG stuff */
186  if (RelationNeedsWAL(idxrel))
187  {
189  XLogRecPtr recptr;
191 
192  xlrec.offnum = oldoff;
193 
194  XLogBeginInsert();
195  XLogRegisterData((char *) &xlrec, SizeOfBrinSamepageUpdate);
196 
198  XLogRegisterBufData(0, (char *) newtup, newsz);
199 
200  recptr = XLogInsert(RM_BRIN_ID, info);
201 
202  PageSetLSN(oldpage, recptr);
203  }
204 
206 
208 
209  if (extended)
210  FreeSpaceMapVacuum(idxrel);
211 
212  return true;
213  }
214  else if (newbuf == InvalidBuffer)
215  {
216  /*
217  * Not enough space, but caller said that there was. Tell them to
218  * start over.
219  */
221  return false;
222  }
223  else
224  {
225  /*
226  * Not enough free space on the oldpage. Put the new tuple on the new
227  * page, and update the revmap.
228  */
229  Page newpage = BufferGetPage(newbuf);
230  Buffer revmapbuf;
231  ItemPointerData newtid;
232  OffsetNumber newoff;
234  Size freespace = 0;
235 
236  revmapbuf = brinLockRevmapPageForUpdate(revmap, heapBlk);
237 
239 
240  /*
241  * We need to initialize the page if it's newly obtained. Note we
242  * will WAL-log the initialization as part of the update, so we don't
243  * need to do that here.
244  */
245  if (extended)
247 
248  PageIndexTupleDeleteNoCompact(oldpage, oldoff);
249  newoff = PageAddItem(newpage, (Item) newtup, newsz,
250  InvalidOffsetNumber, false, false);
251  if (newoff == InvalidOffsetNumber)
252  elog(ERROR, "failed to add BRIN tuple to new page");
253  MarkBufferDirty(oldbuf);
254  MarkBufferDirty(newbuf);
255 
256  /* needed to update FSM below */
257  if (extended)
258  {
259  newblk = BufferGetBlockNumber(newbuf);
260  freespace = br_page_get_freespace(newpage);
261  }
262 
263  ItemPointerSet(&newtid, BufferGetBlockNumber(newbuf), newoff);
264  brinSetHeapBlockItemptr(revmapbuf, pagesPerRange, heapBlk, newtid);
265  MarkBufferDirty(revmapbuf);
266 
267  /* XLOG stuff */
268  if (RelationNeedsWAL(idxrel))
269  {
270  xl_brin_update xlrec;
271  XLogRecPtr recptr;
272  uint8 info;
273 
274  info = XLOG_BRIN_UPDATE | (extended ? XLOG_BRIN_INIT_PAGE : 0);
275 
276  xlrec.insert.offnum = newoff;
277  xlrec.insert.heapBlk = heapBlk;
278  xlrec.insert.pagesPerRange = pagesPerRange;
279  xlrec.oldOffnum = oldoff;
280 
281  XLogBeginInsert();
282 
283  /* new page */
284  XLogRegisterData((char *) &xlrec, SizeOfBrinUpdate);
285 
286  XLogRegisterBuffer(0, newbuf, REGBUF_STANDARD | (extended ? REGBUF_WILL_INIT : 0));
287  XLogRegisterBufData(0, (char *) newtup, newsz);
288 
289  /* revmap page */
290  XLogRegisterBuffer(1, revmapbuf, 0);
291 
292  /* old page */
294 
295  recptr = XLogInsert(RM_BRIN_ID, info);
296 
297  PageSetLSN(oldpage, recptr);
298  PageSetLSN(newpage, recptr);
299  PageSetLSN(BufferGetPage(revmapbuf), recptr);
300  }
301 
303 
304  LockBuffer(revmapbuf, BUFFER_LOCK_UNLOCK);
306  UnlockReleaseBuffer(newbuf);
307 
308  if (extended)
309  {
310  Assert(BlockNumberIsValid(newblk));
311  RecordPageWithFreeSpace(idxrel, newblk, freespace);
312  FreeSpaceMapVacuum(idxrel);
313  }
314 
315  return true;
316  }
317 }
void XLogRegisterBufData(uint8 block_id, char *data, int len)
Definition: xloginsert.c:361
BlockNumber heapBlk
Definition: brin_xlog.h:65
#define BUFFER_LOCK_UNLOCK
Definition: bufmgr.h:87
void RecordPageWithFreeSpace(Relation rel, BlockNumber heapBlk, Size spaceAvail)
Definition: freespace.c:181
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
OffsetNumber offnum
Definition: brin_xlog.h:104
unsigned char uint8
Definition: c.h:266
Pointer Item
Definition: item.h:17
#define InvalidBuffer
Definition: buf.h:25
Buffer brinLockRevmapPageForUpdate(BrinRevmap *revmap, BlockNumber heapBlk)
Definition: brin_revmap.c:137
#define REGBUF_WILL_INIT
Definition: xloginsert.h:32
#define START_CRIT_SECTION()
Definition: miscadmin.h:130
int errcode(int sqlerrcode)
Definition: elog.c:575
#define PageAddItem(page, item, size, offsetNumber, overwrite, is_heap)
Definition: bufpage.h:413
uint32 BlockNumber
Definition: block.h:31
#define BUFFER_LOCK_EXCLUSIVE
Definition: bufmgr.h:89
uint16 OffsetNumber
Definition: off.h:24
#define SizeOfBrinUpdate
Definition: brin_xlog.h:95
#define XLOG_BRIN_UPDATE
Definition: brin_xlog.h:33
#define ItemIdGetLength(itemId)
Definition: itemid.h:58
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3332
#define ERROR
Definition: elog.h:43
#define BRIN_PAGETYPE_REGULAR
Definition: brin_page.h:53
void brinRevmapExtend(BrinRevmap *revmap, BlockNumber heapBlk)
Definition: brin_revmap.c:115
bool PageIndexTupleOverwrite(Page page, OffsetNumber offnum, Item newtup, Size newsize)
Definition: bufpage.c:1066
bool brin_tuples_equal(const BrinTuple *a, Size alen, const BrinTuple *b, Size blen)
Definition: brin_tuple.c:340
BlockNumber pagesPerRange
Definition: brin_xlog.h:68
#define REGBUF_STANDARD
Definition: xloginsert.h:35
static Size br_page_get_freespace(Page page)
Definition: brin_pageops.c:888
#define RelationGetRelationName(relation)
Definition: rel.h:437
#define BufferGetPage(buffer)
Definition: bufmgr.h:160
#define ereport(elevel, rest)
Definition: elog.h:122
bool brin_can_do_samepage_update(Buffer buffer, Size origsz, Size newsz)
Definition: brin_pageops.c:323
void FreeSpaceMapVacuum(Relation rel)
Definition: freespace.c:379
#define PageGetItemId(page, offsetNumber)
Definition: bufpage.h:232
void XLogRegisterData(char *data, int len)
Definition: xloginsert.c:323
#define XLOG_BRIN_INIT_PAGE
Definition: brin_xlog.h:43
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition: xloginsert.c:415
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:3546
#define InvalidOffsetNumber
Definition: off.h:26
xl_brin_insert insert
Definition: brin_xlog.h:92
#define BlockNumberIsValid(blockNumber)
Definition: block.h:70
void PageIndexTupleDeleteNoCompact(Page page, OffsetNumber offnum)
Definition: bufpage.c:958
#define BrinMaxItemSize
Definition: brin_pageops.c:30
uint64 XLogRecPtr
Definition: xlogdefs.h:21
#define Assert(condition)
Definition: c.h:675
#define ItemIdIsNormal(itemId)
Definition: itemid.h:98
#define SizeOfBrinSamepageUpdate
Definition: brin_xlog.h:107
size_t Size
Definition: c.h:356
#define XLOG_BRIN_SAMEPAGE_UPDATE
Definition: brin_xlog.h:34
#define InvalidBlockNumber
Definition: block.h:33
OffsetNumber offnum
Definition: brin_xlog.h:71
static void brin_initialize_empty_new_buffer(Relation idxrel, Buffer buffer)
Definition: brin_pageops.c:856
#define MAXALIGN(LEN)
Definition: c.h:588
#define BufferIsValid(bufnum)
Definition: bufmgr.h:114
#define RelationNeedsWAL(relation)
Definition: rel.h:506
BlockNumber BufferGetBlockNumber(Buffer buffer)
Definition: bufmgr.c:2605
int errmsg(const char *fmt,...)
Definition: elog.c:797
static Buffer brin_getinsertbuffer(Relation irel, Buffer oldbuf, Size itemsz, bool *extended)
Definition: brin_pageops.c:666
#define BRIN_EVACUATE_PAGE
Definition: brin_page.h:60
#define elog
Definition: elog.h:219
#define BrinPageFlags(page)
Definition: brin_page.h:46
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
OffsetNumber oldOffnum
Definition: brin_xlog.h:90
int Buffer
Definition: buf.h:23
#define PageGetItem(page, itemId)
Definition: bufpage.h:337
Pointer Page
Definition: bufpage.h:74
#define ItemPointerSet(pointer, blockNumber, offNum)
Definition: itemptr.h:104
void brin_page_init(Page page, uint16 type)
Definition: brin_pageops.c:469
void brin_evacuate_page ( Relation  idxRel,
BlockNumber  pagesPerRange,
BrinRevmap revmap,
Buffer  buf 
)

Definition at line 545 of file brin_pageops.c.

References Assert, brin_copy_tuple(), brin_doupdate(), BRIN_EVACUATE_PAGE, BRIN_IS_REGULAR_PAGE, BrinPageFlags, BrinTuple::bt_blkno, BUFFER_LOCK_SHARE, BUFFER_LOCK_UNLOCK, BufferGetPage, CHECK_FOR_INTERRUPTS, FirstOffsetNumber, ItemIdGetLength, ItemIdIsUsed, LockBuffer(), NULL, PageGetItem, PageGetItemId, PageGetMaxOffsetNumber, and UnlockReleaseBuffer().

Referenced by revmap_physical_extend().

547 {
548  OffsetNumber off;
549  OffsetNumber maxoff;
550  Page page;
551  BrinTuple *btup = NULL;
552  Size btupsz = 0;
553 
554  page = BufferGetPage(buf);
555 
557 
558  maxoff = PageGetMaxOffsetNumber(page);
559  for (off = FirstOffsetNumber; off <= maxoff; off++)
560  {
561  BrinTuple *tup;
562  Size sz;
563  ItemId lp;
564 
566 
567  lp = PageGetItemId(page, off);
568  if (ItemIdIsUsed(lp))
569  {
570  sz = ItemIdGetLength(lp);
571  tup = (BrinTuple *) PageGetItem(page, lp);
572  tup = brin_copy_tuple(tup, sz, btup, &btupsz);
573 
575 
576  if (!brin_doupdate(idxRel, pagesPerRange, revmap, tup->bt_blkno,
577  buf, off, tup, sz, tup, sz, false))
578  off--; /* retry */
579 
581 
582  /* It's possible that someone extended the revmap over this page */
583  if (!BRIN_IS_REGULAR_PAGE(page))
584  break;
585  }
586  }
587 
589 }
#define BUFFER_LOCK_UNLOCK
Definition: bufmgr.h:87
BrinTuple * brin_copy_tuple(BrinTuple *tuple, Size len, BrinTuple *dest, Size *destsz)
Definition: brin_tuple.c:321
#define ItemIdIsUsed(itemId)
Definition: itemid.h:91
#define BRIN_IS_REGULAR_PAGE(page)
Definition: brin_page.h:57
bool brin_doupdate(Relation idxrel, BlockNumber pagesPerRange, BrinRevmap *revmap, BlockNumber heapBlk, Buffer oldbuf, OffsetNumber oldoff, const BrinTuple *origtup, Size origsz, const BrinTuple *newtup, Size newsz, bool samepage)
Definition: brin_pageops.c:55
#define PageGetMaxOffsetNumber(page)
Definition: bufpage.h:354
uint16 OffsetNumber
Definition: off.h:24
#define ItemIdGetLength(itemId)
Definition: itemid.h:58
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3332
static char * buf
Definition: pg_test_fsync.c:66
#define FirstOffsetNumber
Definition: off.h:27
#define BufferGetPage(buffer)
Definition: bufmgr.h:160
#define PageGetItemId(page, offsetNumber)
Definition: bufpage.h:232
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:3546
BlockNumber bt_blkno
Definition: brin_tuple.h:57
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
size_t Size
Definition: c.h:356
#define BUFFER_LOCK_SHARE
Definition: bufmgr.h:88
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:97
#define BRIN_EVACUATE_PAGE
Definition: brin_page.h:60
#define BrinPageFlags(page)
Definition: brin_page.h:46
#define PageGetItem(page, itemId)
Definition: bufpage.h:337
Pointer Page
Definition: bufpage.h:74
static Buffer brin_getinsertbuffer ( Relation  irel,
Buffer  oldbuf,
Size  itemsz,
bool extended 
)
static

Definition at line 666 of file brin_pageops.c.

References Assert, br_page_get_freespace(), BRIN_elog, brin_initialize_empty_new_buffer(), BRIN_IS_REGULAR_PAGE, BrinMaxItemSize, buf, BUFFER_LOCK_EXCLUSIVE, BUFFER_LOCK_UNLOCK, BufferGetBlockNumber(), BufferGetPage, BufferIsValid, CHECK_FOR_INTERRUPTS, DEBUG2, ereport, errcode(), errmsg(), ERROR, ExclusiveLock, GetPageWithFreeSpace(), InvalidBlockNumber, InvalidBuffer, LockBuffer(), LockRelationForExtension(), P_NEW, ReadBuffer(), RecordAndGetPageWithFreeSpace(), RecordPageWithFreeSpace(), RELATION_IS_LOCAL, RelationGetRelationName, RelationGetTargetBlock, RelationSetTargetBlock, ReleaseBuffer(), UnlockRelationForExtension(), and UnlockReleaseBuffer().

Referenced by brin_doinsert(), and brin_doupdate().

668 {
669  BlockNumber oldblk;
670  BlockNumber newblk;
671  Page page;
672  int freespace;
673 
674  /* callers must have checked */
675  Assert(itemsz <= BrinMaxItemSize);
676 
677  *extended = false;
678 
679  if (BufferIsValid(oldbuf))
680  oldblk = BufferGetBlockNumber(oldbuf);
681  else
682  oldblk = InvalidBlockNumber;
683 
684  /*
685  * Loop until we find a page with sufficient free space. By the time we
686  * return to caller out of this loop, both buffers are valid and locked;
687  * if we have to restart here, neither buffer is locked and buf is not a
688  * pinned buffer.
689  */
690  newblk = RelationGetTargetBlock(irel);
691  if (newblk == InvalidBlockNumber)
692  newblk = GetPageWithFreeSpace(irel, itemsz);
693  for (;;)
694  {
695  Buffer buf;
696  bool extensionLockHeld = false;
697 
699 
700  if (newblk == InvalidBlockNumber)
701  {
702  /*
703  * There's not enough free space in any existing index page,
704  * according to the FSM: extend the relation to obtain a shiny new
705  * page.
706  */
707  if (!RELATION_IS_LOCAL(irel))
708  {
710  extensionLockHeld = true;
711  }
712  buf = ReadBuffer(irel, P_NEW);
713  newblk = BufferGetBlockNumber(buf);
714  *extended = true;
715 
716  BRIN_elog((DEBUG2, "brin_getinsertbuffer: extending to page %u",
717  BufferGetBlockNumber(buf)));
718  }
719  else if (newblk == oldblk)
720  {
721  /*
722  * There's an odd corner-case here where the FSM is out-of-date,
723  * and gave us the old page.
724  */
725  buf = oldbuf;
726  }
727  else
728  {
729  buf = ReadBuffer(irel, newblk);
730  }
731 
732  /*
733  * We lock the old buffer first, if it's earlier than the new one; but
734  * before we do, we need to check that it hasn't been turned into a
735  * revmap page concurrently; if we detect that it happened, give up
736  * and tell caller to start over.
737  */
738  if (BufferIsValid(oldbuf) && oldblk < newblk)
739  {
741  if (!BRIN_IS_REGULAR_PAGE(BufferGetPage(oldbuf)))
742  {
744 
745  /*
746  * It is possible that the new page was obtained from
747  * extending the relation. In that case, we must be sure to
748  * record it in the FSM before leaving, because otherwise the
749  * space would be lost forever. However, we cannot let an
750  * uninitialized page get in the FSM, so we need to initialize
751  * it first.
752  */
753  if (*extended)
754  {
756  /* shouldn't matter, but don't confuse caller */
757  *extended = false;
758  }
759 
760  if (extensionLockHeld)
762 
763  ReleaseBuffer(buf);
764  return InvalidBuffer;
765  }
766  }
767 
769 
770  if (extensionLockHeld)
772 
773  page = BufferGetPage(buf);
774 
775  /*
776  * We have a new buffer to insert into. Check that the new page has
777  * enough free space, and return it if it does; otherwise start over.
778  * Note that we allow for the FSM to be out of date here, and in that
779  * case we update it and move on.
780  *
781  * (br_page_get_freespace also checks that the FSM didn't hand us a
782  * page that has since been repurposed for the revmap.)
783  */
784  freespace = *extended ?
786  if (freespace >= itemsz)
787  {
789 
790  /*
791  * Since the target block specification can get lost on cache
792  * invalidations, make sure we update the more permanent FSM with
793  * data about it before going away.
794  */
795  if (*extended)
797  freespace);
798 
799  /*
800  * Lock the old buffer if not locked already. Note that in this
801  * case we know for sure it's a regular page: it's later than the
802  * new page we just got, which is not a revmap page, and revmap
803  * pages are always consecutive.
804  */
805  if (BufferIsValid(oldbuf) && oldblk > newblk)
806  {
809  }
810 
811  return buf;
812  }
813 
814  /* This page is no good. */
815 
816  /*
817  * If an entirely new page does not contain enough free space for the
818  * new item, then surely that item is oversized. Complain loudly; but
819  * first make sure we initialize the page and record it as free, for
820  * next time.
821  */
822  if (*extended)
823  {
825 
826  ereport(ERROR,
827  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
828  errmsg("index row size %lu exceeds maximum %lu for index \"%s\"",
829  (unsigned long) itemsz,
830  (unsigned long) freespace,
831  RelationGetRelationName(irel))));
832  return InvalidBuffer; /* keep compiler quiet */
833  }
834 
835  if (newblk != oldblk)
836  UnlockReleaseBuffer(buf);
837  if (BufferIsValid(oldbuf) && oldblk <= newblk)
839 
840  newblk = RecordAndGetPageWithFreeSpace(irel, newblk, freespace, itemsz);
841  }
842 }
#define BUFFER_LOCK_UNLOCK
Definition: bufmgr.h:87
#define BRIN_elog(args)
Definition: brin_internal.h:81
void RecordPageWithFreeSpace(Relation rel, BlockNumber heapBlk, Size spaceAvail)
Definition: freespace.c:181
#define ExclusiveLock
Definition: lockdefs.h:44
#define RELATION_IS_LOCAL(relation)
Definition: rel.h:524
#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 P_NEW
Definition: bufmgr.h:82
#define BUFFER_LOCK_EXCLUSIVE
Definition: bufmgr.h:89
#define RelationGetTargetBlock(relation)
Definition: rel.h:489
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3332
#define ERROR
Definition: elog.h:43
#define DEBUG2
Definition: elog.h:24
static char * buf
Definition: pg_test_fsync.c:66
static Size br_page_get_freespace(Page page)
Definition: brin_pageops.c:888
#define RelationGetRelationName(relation)
Definition: rel.h:437
#define BufferGetPage(buffer)
Definition: bufmgr.h:160
#define ereport(elevel, rest)
Definition: elog.h:122
void LockRelationForExtension(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:332
void UnlockRelationForExtension(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:382
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:3546
#define BrinMaxItemSize
Definition: brin_pageops.c:30
#define Assert(condition)
Definition: c.h:675
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
Definition: bufmgr.c:594
#define RelationSetTargetBlock(relation, targblock)
Definition: rel.h:496
#define InvalidBlockNumber
Definition: block.h:33
static void brin_initialize_empty_new_buffer(Relation idxrel, Buffer buffer)
Definition: brin_pageops.c:856
#define BufferIsValid(bufnum)
Definition: bufmgr.h:114
BlockNumber BufferGetBlockNumber(Buffer buffer)
Definition: bufmgr.c:2605
int errmsg(const char *fmt,...)
Definition: elog.c:797
BlockNumber GetPageWithFreeSpace(Relation rel, Size spaceNeeded)
Definition: freespace.c:132
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:97
BlockNumber RecordAndGetPageWithFreeSpace(Relation rel, BlockNumber oldPage, Size oldSpaceAvail, Size spaceNeeded)
Definition: freespace.c:149
int Buffer
Definition: buf.h:23
Pointer Page
Definition: bufpage.h:74
static void brin_initialize_empty_new_buffer ( Relation  idxrel,
Buffer  buffer 
)
static

Definition at line 856 of file brin_pageops.c.

References br_page_get_freespace(), BRIN_elog, brin_page_init(), BRIN_PAGETYPE_REGULAR, BufferGetBlockNumber(), BufferGetPage, DEBUG2, END_CRIT_SECTION, log_newpage_buffer(), MarkBufferDirty(), RecordPageWithFreeSpace(), and START_CRIT_SECTION.

Referenced by brin_doupdate(), brin_getinsertbuffer(), and brin_page_cleanup().

857 {
858  Page page;
859 
860  BRIN_elog((DEBUG2,
861  "brin_initialize_empty_new_buffer: initializing blank page %u",
863 
865  page = BufferGetPage(buffer);
868  log_newpage_buffer(buffer, true);
870 
871  /*
872  * We update the FSM for this page, but this is not WAL-logged. This is
873  * acceptable because VACUUM will scan the index and update the FSM with
874  * pages whose FSM records were forgotten in a crash.
875  */
877  br_page_get_freespace(page));
878 }
#define BRIN_elog(args)
Definition: brin_internal.h:81
XLogRecPtr log_newpage_buffer(Buffer buffer, bool page_std)
Definition: xloginsert.c:1009
void RecordPageWithFreeSpace(Relation rel, BlockNumber heapBlk, Size spaceAvail)
Definition: freespace.c:181
void MarkBufferDirty(Buffer buffer)
Definition: bufmgr.c:1450
#define END_CRIT_SECTION()
Definition: miscadmin.h:132
#define START_CRIT_SECTION()
Definition: miscadmin.h:130
#define BRIN_PAGETYPE_REGULAR
Definition: brin_page.h:53
#define DEBUG2
Definition: elog.h:24
static Size br_page_get_freespace(Page page)
Definition: brin_pageops.c:888
#define BufferGetPage(buffer)
Definition: bufmgr.h:160
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:211
BlockNumber BufferGetBlockNumber(Buffer buffer)
Definition: bufmgr.c:2605
Pointer Page
Definition: bufpage.h:74
void brin_page_init(Page page, uint16 type)
Definition: brin_pageops.c:469
void brin_metapage_init ( Page  page,
BlockNumber  pagesPerRange,
uint16  version 
)

Definition at line 480 of file brin_pageops.c.

References BRIN_META_MAGIC, brin_page_init(), BRIN_PAGETYPE_META, BrinMetaPageData::brinMagic, BrinMetaPageData::brinVersion, BrinMetaPageData::lastRevmapPage, PageGetContents, and BrinMetaPageData::pagesPerRange.

Referenced by brin_xlog_createidx(), brinbuild(), and brinbuildempty().

481 {
482  BrinMetaPageData *metadata;
483 
485 
486  metadata = (BrinMetaPageData *) PageGetContents(page);
487 
488  metadata->brinMagic = BRIN_META_MAGIC;
489  metadata->brinVersion = version;
490  metadata->pagesPerRange = pagesPerRange;
491 
492  /*
493  * Note we cheat here a little. 0 is not a valid revmap block number
494  * (because it's the metapage buffer), but doing this enables the first
495  * revmap page to be created when the index is.
496  */
497  metadata->lastRevmapPage = 0;
498 }
uint32 brinVersion
Definition: brin_page.h:67
uint32 brinMagic
Definition: brin_page.h:66
#define BRIN_PAGETYPE_META
Definition: brin_page.h:51
BlockNumber lastRevmapPage
Definition: brin_page.h:69
#define PageGetContents(page)
Definition: bufpage.h:243
BlockNumber pagesPerRange
Definition: brin_page.h:68
void brin_page_init(Page page, uint16 type)
Definition: brin_pageops.c:469
#define BRIN_META_MAGIC
Definition: brin_page.h:73
bool brin_page_cleanup ( Relation  idxrel,
Buffer  buf 
)

Definition at line 599 of file brin_pageops.c.

References br_page_get_freespace(), brin_initialize_empty_new_buffer(), BRIN_IS_META_PAGE, BRIN_IS_REVMAP_PAGE, BUFFER_LOCK_EXCLUSIVE, BUFFER_LOCK_UNLOCK, BufferGetBlockNumber(), BufferGetPage, GetRecordedFreeSpace(), LockBuffer(), LockRelationForExtension(), PageIsNew, RecordPageWithFreeSpace(), ShareLock, and UnlockRelationForExtension().

Referenced by brin_vacuum_scan().

600 {
601  Page page = BufferGetPage(buf);
602  Size freespace;
603 
604  /*
605  * If a page was left uninitialized, initialize it now; also record it in
606  * FSM.
607  *
608  * Somebody else might be extending the relation concurrently. To avoid
609  * re-initializing the page before they can grab the buffer lock, we
610  * acquire the extension lock momentarily. Since they hold the extension
611  * lock from before getting the page and after its been initialized, we're
612  * sure to see their initialization.
613  */
614  if (PageIsNew(page))
615  {
618 
620  if (PageIsNew(page))
621  {
624  return true;
625  }
627  }
628 
629  /* Nothing to be done for non-regular index pages */
632  return false;
633 
634  /* Measure free space and record it */
635  freespace = br_page_get_freespace(page);
636  if (freespace > GetRecordedFreeSpace(idxrel, BufferGetBlockNumber(buf)))
637  {
638  RecordPageWithFreeSpace(idxrel, BufferGetBlockNumber(buf), freespace);
639  return true;
640  }
641 
642  return false;
643 }
#define BUFFER_LOCK_UNLOCK
Definition: bufmgr.h:87
void RecordPageWithFreeSpace(Relation rel, BlockNumber heapBlk, Size spaceAvail)
Definition: freespace.c:181
#define BUFFER_LOCK_EXCLUSIVE
Definition: bufmgr.h:89
static char * buf
Definition: pg_test_fsync.c:66
static Size br_page_get_freespace(Page page)
Definition: brin_pageops.c:888
#define BufferGetPage(buffer)
Definition: bufmgr.h:160
void LockRelationForExtension(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:332
#define BRIN_IS_META_PAGE(page)
Definition: brin_page.h:55
Size GetRecordedFreeSpace(Relation rel, BlockNumber heapBlk)
Definition: freespace.c:270
void UnlockRelationForExtension(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:382
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:3546
#define BRIN_IS_REVMAP_PAGE(page)
Definition: brin_page.h:56
size_t Size
Definition: c.h:356
static void brin_initialize_empty_new_buffer(Relation idxrel, Buffer buffer)
Definition: brin_pageops.c:856
BlockNumber BufferGetBlockNumber(Buffer buffer)
Definition: bufmgr.c:2605
#define PageIsNew(page)
Definition: bufpage.h:226
#define ShareLock
Definition: lockdefs.h:41
Pointer Page
Definition: bufpage.h:74
void brin_page_init ( Page  page,
uint16  type 
)

Definition at line 469 of file brin_pageops.c.

References BrinPageType, and PageInit().

Referenced by brin_doinsert(), brin_doupdate(), brin_initialize_empty_new_buffer(), brin_metapage_init(), brin_xlog_insert_update(), brin_xlog_revmap_extend(), and revmap_physical_extend().

470 {
471  PageInit(page, BLCKSZ, sizeof(BrinSpecialSpace));
472 
473  BrinPageType(page) = type;
474 }
#define BrinPageType(page)
Definition: brin_page.h:42
void PageInit(Page page, Size pageSize, Size specialSize)
Definition: bufpage.c:41
bool brin_start_evacuating_page ( Relation  idxRel,
Buffer  buf 
)

Definition at line 510 of file brin_pageops.c.

References BRIN_EVACUATE_PAGE, BrinPageFlags, BufferGetPage, FirstOffsetNumber, ItemIdIsUsed, MarkBufferDirtyHint(), PageGetItemId, PageGetMaxOffsetNumber, and PageIsNew.

Referenced by revmap_physical_extend().

511 {
512  OffsetNumber off;
513  OffsetNumber maxoff;
514  Page page;
515 
516  page = BufferGetPage(buf);
517 
518  if (PageIsNew(page))
519  return false;
520 
521  maxoff = PageGetMaxOffsetNumber(page);
522  for (off = FirstOffsetNumber; off <= maxoff; off++)
523  {
524  ItemId lp;
525 
526  lp = PageGetItemId(page, off);
527  if (ItemIdIsUsed(lp))
528  {
529  /* prevent other backends from adding more stuff to this page */
531  MarkBufferDirtyHint(buf, true);
532 
533  return true;
534  }
535  }
536  return false;
537 }
void MarkBufferDirtyHint(Buffer buffer, bool buffer_std)
Definition: bufmgr.c:3379
#define ItemIdIsUsed(itemId)
Definition: itemid.h:91
#define PageGetMaxOffsetNumber(page)
Definition: bufpage.h:354
uint16 OffsetNumber
Definition: off.h:24
static char * buf
Definition: pg_test_fsync.c:66
#define FirstOffsetNumber
Definition: off.h:27
#define BufferGetPage(buffer)
Definition: bufmgr.h:160
#define PageGetItemId(page, offsetNumber)
Definition: bufpage.h:232
#define PageIsNew(page)
Definition: bufpage.h:226
#define BRIN_EVACUATE_PAGE
Definition: brin_page.h:60
#define BrinPageFlags(page)
Definition: brin_page.h:46
Pointer Page
Definition: bufpage.h:74