PostgreSQL Source Code  git master
nbtxlog.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * nbtxlog.c
4  * WAL replay logic for btrees.
5  *
6  *
7  * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * IDENTIFICATION
11  * src/backend/access/nbtree/nbtxlog.c
12  *
13  *-------------------------------------------------------------------------
14  */
15 #include "postgres.h"
16 
17 #include "access/bufmask.h"
18 #include "access/nbtree.h"
19 #include "access/nbtxlog.h"
20 #include "access/transam.h"
21 #include "access/xlog.h"
22 #include "access/xlogutils.h"
23 #include "miscadmin.h"
24 #include "storage/procarray.h"
25 #include "utils/memutils.h"
26 
27 static MemoryContext opCtx; /* working memory for operations */
28 
29 /*
30  * _bt_restore_page -- re-enter all the index tuples on a page
31  *
32  * The page is freshly init'd, and *from (length len) is a copy of what
33  * had been its upper part (pd_upper to pd_special). We assume that the
34  * tuples had been added to the page in item-number order, and therefore
35  * the one with highest item number appears first (lowest on the page).
36  */
37 static void
38 _bt_restore_page(Page page, char *from, int len)
39 {
40  IndexTupleData itupdata;
41  Size itemsz;
42  char *end = from + len;
44  uint16 itemsizes[MaxIndexTuplesPerPage];
45  int i;
46  int nitems;
47 
48  /*
49  * To get the items back in the original order, we add them to the page in
50  * reverse. To figure out where one tuple ends and another begins, we
51  * have to scan them in forward order first.
52  */
53  i = 0;
54  while (from < end)
55  {
56  /*
57  * As we step through the items, 'from' won't always be properly
58  * aligned, so we need to use memcpy(). Further, we use Item (which
59  * is just a char*) here for our items array for the same reason;
60  * wouldn't want the compiler or anyone thinking that an item is
61  * aligned when it isn't.
62  */
63  memcpy(&itupdata, from, sizeof(IndexTupleData));
64  itemsz = IndexTupleSize(&itupdata);
65  itemsz = MAXALIGN(itemsz);
66 
67  items[i] = (Item) from;
68  itemsizes[i] = itemsz;
69  i++;
70 
71  from += itemsz;
72  }
73  nitems = i;
74 
75  for (i = nitems - 1; i >= 0; i--)
76  {
77  if (PageAddItem(page, items[i], itemsizes[i], nitems - i,
78  false, false) == InvalidOffsetNumber)
79  elog(PANIC, "_bt_restore_page: cannot add item to page");
80  from += itemsz;
81  }
82 }
83 
84 static void
86 {
87  XLogRecPtr lsn = record->EndRecPtr;
88  Buffer metabuf;
89  Page metapg;
90  BTMetaPageData *md;
91  BTPageOpaque pageop;
92  xl_btree_metadata *xlrec;
93  char *ptr;
94  Size len;
95 
96  metabuf = XLogInitBufferForRedo(record, block_id);
97  ptr = XLogRecGetBlockData(record, block_id, &len);
98 
99  Assert(len == sizeof(xl_btree_metadata));
101  xlrec = (xl_btree_metadata *) ptr;
102  metapg = BufferGetPage(metabuf);
103 
104  _bt_pageinit(metapg, BufferGetPageSize(metabuf));
105 
106  md = BTPageGetMeta(metapg);
107  md->btm_magic = BTREE_MAGIC;
108  md->btm_version = xlrec->version;
109  md->btm_root = xlrec->root;
110  md->btm_level = xlrec->level;
111  md->btm_fastroot = xlrec->fastroot;
112  md->btm_fastlevel = xlrec->fastlevel;
113  /* Cannot log BTREE_MIN_VERSION index metapage without upgrade */
117  md->btm_allequalimage = xlrec->allequalimage;
118 
119  pageop = (BTPageOpaque) PageGetSpecialPointer(metapg);
120  pageop->btpo_flags = BTP_META;
121 
122  /*
123  * Set pd_lower just past the end of the metadata. This is essential,
124  * because without doing so, metadata will be lost if xlog.c compresses
125  * the page.
126  */
127  ((PageHeader) metapg)->pd_lower =
128  ((char *) md + sizeof(BTMetaPageData)) - (char *) metapg;
129 
130  PageSetLSN(metapg, lsn);
131  MarkBufferDirty(metabuf);
132  UnlockReleaseBuffer(metabuf);
133 }
134 
135 /*
136  * _bt_clear_incomplete_split -- clear INCOMPLETE_SPLIT flag on a page
137  *
138  * This is a common subroutine of the redo functions of all the WAL record
139  * types that can insert a downlink: insert, split, and newroot.
140  */
141 static void
143 {
144  XLogRecPtr lsn = record->EndRecPtr;
145  Buffer buf;
146 
147  if (XLogReadBufferForRedo(record, block_id, &buf) == BLK_NEEDS_REDO)
148  {
149  Page page = (Page) BufferGetPage(buf);
151 
152  Assert(P_INCOMPLETE_SPLIT(pageop));
153  pageop->btpo_flags &= ~BTP_INCOMPLETE_SPLIT;
154 
155  PageSetLSN(page, lsn);
156  MarkBufferDirty(buf);
157  }
158  if (BufferIsValid(buf))
159  UnlockReleaseBuffer(buf);
160 }
161 
162 static void
163 btree_xlog_insert(bool isleaf, bool ismeta, bool posting,
164  XLogReaderState *record)
165 {
166  XLogRecPtr lsn = record->EndRecPtr;
167  xl_btree_insert *xlrec = (xl_btree_insert *) XLogRecGetData(record);
168  Buffer buffer;
169  Page page;
170 
171  /*
172  * Insertion to an internal page finishes an incomplete split at the child
173  * level. Clear the incomplete-split flag in the child. Note: during
174  * normal operation, the child and parent pages are locked at the same
175  * time (the locks are coupled), so that clearing the flag and inserting
176  * the downlink appear atomic to other backends. We don't bother with
177  * that during replay, because readers don't care about the
178  * incomplete-split flag and there cannot be updates happening.
179  */
180  if (!isleaf)
181  _bt_clear_incomplete_split(record, 1);
182  if (XLogReadBufferForRedo(record, 0, &buffer) == BLK_NEEDS_REDO)
183  {
184  Size datalen;
185  char *datapos = XLogRecGetBlockData(record, 0, &datalen);
186 
187  page = BufferGetPage(buffer);
188 
189  if (!posting)
190  {
191  /* Simple retail insertion */
192  if (PageAddItem(page, (Item) datapos, datalen, xlrec->offnum,
193  false, false) == InvalidOffsetNumber)
194  elog(PANIC, "failed to add new item");
195  }
196  else
197  {
198  ItemId itemid;
199  IndexTuple oposting,
200  newitem,
201  nposting;
202  uint16 postingoff;
203 
204  /*
205  * A posting list split occurred during leaf page insertion. WAL
206  * record data will start with an offset number representing the
207  * point in an existing posting list that a split occurs at.
208  *
209  * Use _bt_swap_posting() to repeat posting list split steps from
210  * primary. Note that newitem from WAL record is 'orignewitem',
211  * not the final version of newitem that is actually inserted on
212  * page.
213  */
214  postingoff = *((uint16 *) datapos);
215  datapos += sizeof(uint16);
216  datalen -= sizeof(uint16);
217 
218  itemid = PageGetItemId(page, OffsetNumberPrev(xlrec->offnum));
219  oposting = (IndexTuple) PageGetItem(page, itemid);
220 
221  /* Use mutable, aligned newitem copy in _bt_swap_posting() */
222  Assert(isleaf && postingoff > 0);
223  newitem = CopyIndexTuple((IndexTuple) datapos);
224  nposting = _bt_swap_posting(newitem, oposting, postingoff);
225 
226  /* Replace existing posting list with post-split version */
227  memcpy(oposting, nposting, MAXALIGN(IndexTupleSize(nposting)));
228 
229  /* Insert "final" new item (not orignewitem from WAL stream) */
230  Assert(IndexTupleSize(newitem) == datalen);
231  if (PageAddItem(page, (Item) newitem, datalen, xlrec->offnum,
232  false, false) == InvalidOffsetNumber)
233  elog(PANIC, "failed to add posting split new item");
234  }
235 
236  PageSetLSN(page, lsn);
237  MarkBufferDirty(buffer);
238  }
239  if (BufferIsValid(buffer))
240  UnlockReleaseBuffer(buffer);
241 
242  /*
243  * Note: in normal operation, we'd update the metapage while still holding
244  * lock on the page we inserted into. But during replay it's not
245  * necessary to hold that lock, since no other index updates can be
246  * happening concurrently, and readers will cope fine with following an
247  * obsolete link from the metapage.
248  */
249  if (ismeta)
250  _bt_restore_meta(record, 2);
251 }
252 
253 static void
254 btree_xlog_split(bool newitemonleft, XLogReaderState *record)
255 {
256  XLogRecPtr lsn = record->EndRecPtr;
257  xl_btree_split *xlrec = (xl_btree_split *) XLogRecGetData(record);
258  bool isleaf = (xlrec->level == 0);
259  Buffer buf;
260  Buffer rbuf;
261  Page rpage;
262  BTPageOpaque ropaque;
263  char *datapos;
264  Size datalen;
265  BlockNumber origpagenumber;
266  BlockNumber rightpagenumber;
267  BlockNumber spagenumber;
268 
269  XLogRecGetBlockTag(record, 0, NULL, NULL, &origpagenumber);
270  XLogRecGetBlockTag(record, 1, NULL, NULL, &rightpagenumber);
271  if (!XLogRecGetBlockTag(record, 2, NULL, NULL, &spagenumber))
272  spagenumber = P_NONE;
273 
274  /*
275  * Clear the incomplete split flag on the appropriate child page one level
276  * down when origpage/buf is an internal page (there must have been
277  * cascading page splits during original execution in the event of an
278  * internal page split). This is like the corresponding btree_xlog_insert
279  * call for internal pages. We're not clearing the incomplete split flag
280  * for the current page split here (you can think of this as part of the
281  * insert of newitem that the page split action needs to perform in
282  * passing).
283  *
284  * Like in btree_xlog_insert, this can be done before locking other pages.
285  * We never need to couple cross-level locks in REDO routines.
286  */
287  if (!isleaf)
288  _bt_clear_incomplete_split(record, 3);
289 
290  /* Reconstruct right (new) sibling page from scratch */
291  rbuf = XLogInitBufferForRedo(record, 1);
292  datapos = XLogRecGetBlockData(record, 1, &datalen);
293  rpage = (Page) BufferGetPage(rbuf);
294 
295  _bt_pageinit(rpage, BufferGetPageSize(rbuf));
296  ropaque = (BTPageOpaque) PageGetSpecialPointer(rpage);
297 
298  ropaque->btpo_prev = origpagenumber;
299  ropaque->btpo_next = spagenumber;
300  ropaque->btpo.level = xlrec->level;
301  ropaque->btpo_flags = isleaf ? BTP_LEAF : 0;
302  ropaque->btpo_cycleid = 0;
303 
304  _bt_restore_page(rpage, datapos, datalen);
305 
306  PageSetLSN(rpage, lsn);
307  MarkBufferDirty(rbuf);
308 
309  /* Now reconstruct original page (left half of split) */
310  if (XLogReadBufferForRedo(record, 0, &buf) == BLK_NEEDS_REDO)
311  {
312  /*
313  * To retain the same physical order of the tuples that they had, we
314  * initialize a temporary empty page for the left page and add all the
315  * items to that in item number order. This mirrors how _bt_split()
316  * works. Retaining the same physical order makes WAL consistency
317  * checking possible. See also _bt_restore_page(), which does the
318  * same for the right page.
319  */
320  Page origpage = (Page) BufferGetPage(buf);
321  BTPageOpaque oopaque = (BTPageOpaque) PageGetSpecialPointer(origpage);
322  OffsetNumber off;
323  IndexTuple newitem = NULL,
324  left_hikey = NULL,
325  nposting = NULL;
326  Size newitemsz = 0,
327  left_hikeysz = 0;
328  Page leftpage;
329  OffsetNumber leftoff,
330  replacepostingoff = InvalidOffsetNumber;
331 
332  datapos = XLogRecGetBlockData(record, 0, &datalen);
333 
334  if (newitemonleft || xlrec->postingoff != 0)
335  {
336  newitem = (IndexTuple) datapos;
337  newitemsz = MAXALIGN(IndexTupleSize(newitem));
338  datapos += newitemsz;
339  datalen -= newitemsz;
340 
341  if (xlrec->postingoff != 0)
342  {
343  ItemId itemid;
344  IndexTuple oposting;
345 
346  /* Posting list must be at offset number before new item's */
347  replacepostingoff = OffsetNumberPrev(xlrec->newitemoff);
348 
349  /* Use mutable, aligned newitem copy in _bt_swap_posting() */
350  newitem = CopyIndexTuple(newitem);
351  itemid = PageGetItemId(origpage, replacepostingoff);
352  oposting = (IndexTuple) PageGetItem(origpage, itemid);
353  nposting = _bt_swap_posting(newitem, oposting,
354  xlrec->postingoff);
355  }
356  }
357 
358  /*
359  * Extract left hikey and its size. We assume that 16-bit alignment
360  * is enough to apply IndexTupleSize (since it's fetching from a
361  * uint16 field).
362  */
363  left_hikey = (IndexTuple) datapos;
364  left_hikeysz = MAXALIGN(IndexTupleSize(left_hikey));
365  datapos += left_hikeysz;
366  datalen -= left_hikeysz;
367 
368  Assert(datalen == 0);
369 
370  leftpage = PageGetTempPageCopySpecial(origpage);
371 
372  /* Add high key tuple from WAL record to temp page */
373  leftoff = P_HIKEY;
374  if (PageAddItem(leftpage, (Item) left_hikey, left_hikeysz, P_HIKEY,
375  false, false) == InvalidOffsetNumber)
376  elog(ERROR, "failed to add high key to left page after split");
377  leftoff = OffsetNumberNext(leftoff);
378 
379  for (off = P_FIRSTDATAKEY(oopaque); off < xlrec->firstrightoff; off++)
380  {
381  ItemId itemid;
382  Size itemsz;
383  IndexTuple item;
384 
385  /* Add replacement posting list when required */
386  if (off == replacepostingoff)
387  {
388  Assert(newitemonleft ||
389  xlrec->firstrightoff == xlrec->newitemoff);
390  if (PageAddItem(leftpage, (Item) nposting,
391  MAXALIGN(IndexTupleSize(nposting)), leftoff,
392  false, false) == InvalidOffsetNumber)
393  elog(ERROR, "failed to add new posting list item to left page after split");
394  leftoff = OffsetNumberNext(leftoff);
395  continue; /* don't insert oposting */
396  }
397 
398  /* add the new item if it was inserted on left page */
399  else if (newitemonleft && off == xlrec->newitemoff)
400  {
401  if (PageAddItem(leftpage, (Item) newitem, newitemsz, leftoff,
402  false, false) == InvalidOffsetNumber)
403  elog(ERROR, "failed to add new item to left page after split");
404  leftoff = OffsetNumberNext(leftoff);
405  }
406 
407  itemid = PageGetItemId(origpage, off);
408  itemsz = ItemIdGetLength(itemid);
409  item = (IndexTuple) PageGetItem(origpage, itemid);
410  if (PageAddItem(leftpage, (Item) item, itemsz, leftoff,
411  false, false) == InvalidOffsetNumber)
412  elog(ERROR, "failed to add old item to left page after split");
413  leftoff = OffsetNumberNext(leftoff);
414  }
415 
416  /* cope with possibility that newitem goes at the end */
417  if (newitemonleft && off == xlrec->newitemoff)
418  {
419  if (PageAddItem(leftpage, (Item) newitem, newitemsz, leftoff,
420  false, false) == InvalidOffsetNumber)
421  elog(ERROR, "failed to add new item to left page after split");
422  leftoff = OffsetNumberNext(leftoff);
423  }
424 
425  PageRestoreTempPage(leftpage, origpage);
426 
427  /* Fix opaque fields */
428  oopaque->btpo_flags = BTP_INCOMPLETE_SPLIT;
429  if (isleaf)
430  oopaque->btpo_flags |= BTP_LEAF;
431  oopaque->btpo_next = rightpagenumber;
432  oopaque->btpo_cycleid = 0;
433 
434  PageSetLSN(origpage, lsn);
435  MarkBufferDirty(buf);
436  }
437 
438  /* Fix left-link of the page to the right of the new right sibling */
439  if (spagenumber != P_NONE)
440  {
441  Buffer sbuf;
442 
443  if (XLogReadBufferForRedo(record, 2, &sbuf) == BLK_NEEDS_REDO)
444  {
445  Page spage = (Page) BufferGetPage(sbuf);
447 
448  spageop->btpo_prev = rightpagenumber;
449 
450  PageSetLSN(spage, lsn);
451  MarkBufferDirty(sbuf);
452  }
453  if (BufferIsValid(sbuf))
454  UnlockReleaseBuffer(sbuf);
455  }
456 
457  /*
458  * Finally, release the remaining buffers. sbuf, rbuf, and buf must be
459  * released together, so that readers cannot observe inconsistencies.
460  */
461  UnlockReleaseBuffer(rbuf);
462  if (BufferIsValid(buf))
463  UnlockReleaseBuffer(buf);
464 }
465 
466 static void
468 {
469  XLogRecPtr lsn = record->EndRecPtr;
470  xl_btree_dedup *xlrec = (xl_btree_dedup *) XLogRecGetData(record);
471  Buffer buf;
472 
473  if (XLogReadBufferForRedo(record, 0, &buf) == BLK_NEEDS_REDO)
474  {
475  char *ptr = XLogRecGetBlockData(record, 0, NULL);
476  Page page = (Page) BufferGetPage(buf);
478  OffsetNumber offnum,
479  minoff,
480  maxoff;
483  Page newpage;
484 
485  state = (BTDedupState) palloc(sizeof(BTDedupStateData));
486  state->deduplicate = true; /* unused */
487  state->nmaxitems = 0; /* unused */
488  /* Conservatively use larger maxpostingsize than primary */
489  state->maxpostingsize = BTMaxItemSize(page);
490  state->base = NULL;
491  state->baseoff = InvalidOffsetNumber;
492  state->basetupsize = 0;
493  state->htids = palloc(state->maxpostingsize);
494  state->nhtids = 0;
495  state->nitems = 0;
496  state->phystupsize = 0;
497  state->nintervals = 0;
498 
499  minoff = P_FIRSTDATAKEY(opaque);
500  maxoff = PageGetMaxOffsetNumber(page);
501  newpage = PageGetTempPageCopySpecial(page);
502 
503  if (!P_RIGHTMOST(opaque))
504  {
505  ItemId itemid = PageGetItemId(page, P_HIKEY);
506  Size itemsz = ItemIdGetLength(itemid);
507  IndexTuple item = (IndexTuple) PageGetItem(page, itemid);
508 
509  if (PageAddItem(newpage, (Item) item, itemsz, P_HIKEY,
510  false, false) == InvalidOffsetNumber)
511  elog(ERROR, "deduplication failed to add highkey");
512  }
513 
514  intervals = (BTDedupInterval *) ptr;
515  for (offnum = minoff;
516  offnum <= maxoff;
517  offnum = OffsetNumberNext(offnum))
518  {
519  ItemId itemid = PageGetItemId(page, offnum);
520  IndexTuple itup = (IndexTuple) PageGetItem(page, itemid);
521 
522  if (offnum == minoff)
523  _bt_dedup_start_pending(state, itup, offnum);
524  else if (state->nintervals < xlrec->nintervals &&
525  state->baseoff == intervals[state->nintervals].baseoff &&
526  state->nitems < intervals[state->nintervals].nitems)
527  {
528  if (!_bt_dedup_save_htid(state, itup))
529  elog(ERROR, "deduplication failed to add heap tid to pending posting list");
530  }
531  else
532  {
533  _bt_dedup_finish_pending(newpage, state);
534  _bt_dedup_start_pending(state, itup, offnum);
535  }
536  }
537 
538  _bt_dedup_finish_pending(newpage, state);
539  Assert(state->nintervals == xlrec->nintervals);
540  Assert(memcmp(state->intervals, intervals,
541  state->nintervals * sizeof(BTDedupInterval)) == 0);
542 
543  if (P_HAS_GARBAGE(opaque))
544  {
545  BTPageOpaque nopaque = (BTPageOpaque) PageGetSpecialPointer(newpage);
546 
547  nopaque->btpo_flags &= ~BTP_HAS_GARBAGE;
548  }
549 
550  PageRestoreTempPage(newpage, page);
551  PageSetLSN(page, lsn);
552  MarkBufferDirty(buf);
553  }
554 
555  if (BufferIsValid(buf))
556  UnlockReleaseBuffer(buf);
557 }
558 
559 static void
561 {
562  XLogRecPtr lsn = record->EndRecPtr;
563  xl_btree_vacuum *xlrec = (xl_btree_vacuum *) XLogRecGetData(record);
564  Buffer buffer;
565  Page page;
566  BTPageOpaque opaque;
567 
568  /*
569  * We need to take a cleanup lock here, just like btvacuumpage(). However,
570  * it isn't necessary to exhaustively get a cleanup lock on every block in
571  * the index during recovery (just getting a cleanup lock on pages with
572  * items to kill suffices). See nbtree/README for details.
573  */
574  if (XLogReadBufferForRedoExtended(record, 0, RBM_NORMAL, true, &buffer)
575  == BLK_NEEDS_REDO)
576  {
577  char *ptr = XLogRecGetBlockData(record, 0, NULL);
578 
579  page = (Page) BufferGetPage(buffer);
580 
581  if (xlrec->nupdated > 0)
582  {
583  OffsetNumber *updatedoffsets;
584  xl_btree_update *updates;
585 
586  updatedoffsets = (OffsetNumber *)
587  (ptr + xlrec->ndeleted * sizeof(OffsetNumber));
588  updates = (xl_btree_update *) ((char *) updatedoffsets +
589  xlrec->nupdated *
590  sizeof(OffsetNumber));
591 
592  for (int i = 0; i < xlrec->nupdated; i++)
593  {
594  BTVacuumPosting vacposting;
595  IndexTuple origtuple;
596  ItemId itemid;
597  Size itemsz;
598 
599  itemid = PageGetItemId(page, updatedoffsets[i]);
600  origtuple = (IndexTuple) PageGetItem(page, itemid);
601 
602  vacposting = palloc(offsetof(BTVacuumPostingData, deletetids) +
603  updates->ndeletedtids * sizeof(uint16));
604  vacposting->updatedoffset = updatedoffsets[i];
605  vacposting->itup = origtuple;
606  vacposting->ndeletedtids = updates->ndeletedtids;
607  memcpy(vacposting->deletetids,
608  (char *) updates + SizeOfBtreeUpdate,
609  updates->ndeletedtids * sizeof(uint16));
610 
611  _bt_update_posting(vacposting);
612 
613  /* Overwrite updated version of tuple */
614  itemsz = MAXALIGN(IndexTupleSize(vacposting->itup));
615  if (!PageIndexTupleOverwrite(page, updatedoffsets[i],
616  (Item) vacposting->itup, itemsz))
617  elog(PANIC, "failed to update partially dead item");
618 
619  pfree(vacposting->itup);
620  pfree(vacposting);
621 
622  /* advance to next xl_btree_update from array */
623  updates = (xl_btree_update *)
624  ((char *) updates + SizeOfBtreeUpdate +
625  updates->ndeletedtids * sizeof(uint16));
626  }
627  }
628 
629  if (xlrec->ndeleted > 0)
630  PageIndexMultiDelete(page, (OffsetNumber *) ptr, xlrec->ndeleted);
631 
632  /*
633  * Mark the page as not containing any LP_DEAD items --- see comments
634  * in _bt_delitems_vacuum().
635  */
636  opaque = (BTPageOpaque) PageGetSpecialPointer(page);
637  opaque->btpo_flags &= ~BTP_HAS_GARBAGE;
638 
639  PageSetLSN(page, lsn);
640  MarkBufferDirty(buffer);
641  }
642  if (BufferIsValid(buffer))
643  UnlockReleaseBuffer(buffer);
644 }
645 
646 static void
648 {
649  XLogRecPtr lsn = record->EndRecPtr;
650  xl_btree_delete *xlrec = (xl_btree_delete *) XLogRecGetData(record);
651  Buffer buffer;
652  Page page;
653  BTPageOpaque opaque;
654 
655  /*
656  * If we have any conflict processing to do, it must happen before we
657  * update the page
658  */
659  if (InHotStandby)
660  {
661  RelFileNode rnode;
662 
663  XLogRecGetBlockTag(record, 0, &rnode, NULL, NULL);
664 
666  }
667 
668  /*
669  * We don't need to take a cleanup lock to apply these changes. See
670  * nbtree/README for details.
671  */
672  if (XLogReadBufferForRedo(record, 0, &buffer) == BLK_NEEDS_REDO)
673  {
674  char *ptr = XLogRecGetBlockData(record, 0, NULL);
675 
676  page = (Page) BufferGetPage(buffer);
677 
678  PageIndexMultiDelete(page, (OffsetNumber *) ptr, xlrec->ndeleted);
679 
680  /* Mark the page as not containing any LP_DEAD items */
681  opaque = (BTPageOpaque) PageGetSpecialPointer(page);
682  opaque->btpo_flags &= ~BTP_HAS_GARBAGE;
683 
684  PageSetLSN(page, lsn);
685  MarkBufferDirty(buffer);
686  }
687  if (BufferIsValid(buffer))
688  UnlockReleaseBuffer(buffer);
689 }
690 
691 static void
693 {
694  XLogRecPtr lsn = record->EndRecPtr;
696  Buffer buffer;
697  Page page;
698  BTPageOpaque pageop;
699  IndexTupleData trunctuple;
700 
701  /*
702  * In normal operation, we would lock all the pages this WAL record
703  * touches before changing any of them. In WAL replay, it should be okay
704  * to lock just one page at a time, since no concurrent index updates can
705  * be happening, and readers should not care whether they arrive at the
706  * target page or not (since it's surely empty).
707  */
708 
709  /* to-be-deleted subtree's parent page */
710  if (XLogReadBufferForRedo(record, 1, &buffer) == BLK_NEEDS_REDO)
711  {
712  OffsetNumber poffset;
713  ItemId itemid;
714  IndexTuple itup;
715  OffsetNumber nextoffset;
716  BlockNumber rightsib;
717 
718  page = (Page) BufferGetPage(buffer);
719  pageop = (BTPageOpaque) PageGetSpecialPointer(page);
720 
721  poffset = xlrec->poffset;
722 
723  nextoffset = OffsetNumberNext(poffset);
724  itemid = PageGetItemId(page, nextoffset);
725  itup = (IndexTuple) PageGetItem(page, itemid);
726  rightsib = BTreeTupleGetDownLink(itup);
727 
728  itemid = PageGetItemId(page, poffset);
729  itup = (IndexTuple) PageGetItem(page, itemid);
730  BTreeTupleSetDownLink(itup, rightsib);
731  nextoffset = OffsetNumberNext(poffset);
732  PageIndexTupleDelete(page, nextoffset);
733 
734  PageSetLSN(page, lsn);
735  MarkBufferDirty(buffer);
736  }
737 
738  /*
739  * Don't need to couple cross-level locks in REDO routines, so release
740  * lock on internal page immediately
741  */
742  if (BufferIsValid(buffer))
743  UnlockReleaseBuffer(buffer);
744 
745  /* Rewrite the leaf page as a halfdead page */
746  buffer = XLogInitBufferForRedo(record, 0);
747  page = (Page) BufferGetPage(buffer);
748 
749  _bt_pageinit(page, BufferGetPageSize(buffer));
750  pageop = (BTPageOpaque) PageGetSpecialPointer(page);
751 
752  pageop->btpo_prev = xlrec->leftblk;
753  pageop->btpo_next = xlrec->rightblk;
754  pageop->btpo.level = 0;
755  pageop->btpo_flags = BTP_HALF_DEAD | BTP_LEAF;
756  pageop->btpo_cycleid = 0;
757 
758  /*
759  * Construct a dummy high key item that points to top parent page (value
760  * is InvalidBlockNumber when the top parent page is the leaf page itself)
761  */
762  MemSet(&trunctuple, 0, sizeof(IndexTupleData));
763  trunctuple.t_info = sizeof(IndexTupleData);
764  BTreeTupleSetTopParent(&trunctuple, xlrec->topparent);
765 
766  if (PageAddItem(page, (Item) &trunctuple, sizeof(IndexTupleData), P_HIKEY,
767  false, false) == InvalidOffsetNumber)
768  elog(ERROR, "could not add dummy high key to half-dead page");
769 
770  PageSetLSN(page, lsn);
771  MarkBufferDirty(buffer);
772  UnlockReleaseBuffer(buffer);
773 }
774 
775 
776 static void
778 {
779  XLogRecPtr lsn = record->EndRecPtr;
781  BlockNumber leftsib;
782  BlockNumber rightsib;
783  Buffer leftbuf;
784  Buffer target;
785  Buffer rightbuf;
786  Page page;
787  BTPageOpaque pageop;
788 
789  leftsib = xlrec->leftsib;
790  rightsib = xlrec->rightsib;
791 
792  /*
793  * In normal operation, we would lock all the pages this WAL record
794  * touches before changing any of them. In WAL replay, we at least lock
795  * the pages in the same standard left-to-right order (leftsib, target,
796  * rightsib), and don't release the sibling locks until the target is
797  * marked deleted.
798  */
799 
800  /* Fix right-link of left sibling, if any */
801  if (leftsib != P_NONE)
802  {
803  if (XLogReadBufferForRedo(record, 1, &leftbuf) == BLK_NEEDS_REDO)
804  {
805  page = (Page) BufferGetPage(leftbuf);
806  pageop = (BTPageOpaque) PageGetSpecialPointer(page);
807  pageop->btpo_next = rightsib;
808 
809  PageSetLSN(page, lsn);
810  MarkBufferDirty(leftbuf);
811  }
812  }
813  else
814  leftbuf = InvalidBuffer;
815 
816  /* Rewrite target page as empty deleted page */
817  target = XLogInitBufferForRedo(record, 0);
818  page = (Page) BufferGetPage(target);
819 
820  _bt_pageinit(page, BufferGetPageSize(target));
821  pageop = (BTPageOpaque) PageGetSpecialPointer(page);
822 
823  pageop->btpo_prev = leftsib;
824  pageop->btpo_next = rightsib;
825  pageop->btpo.xact = xlrec->btpo_xact;
826  pageop->btpo_flags = BTP_DELETED;
827  if (!BlockNumberIsValid(xlrec->topparent))
828  pageop->btpo_flags |= BTP_LEAF;
829  pageop->btpo_cycleid = 0;
830 
831  PageSetLSN(page, lsn);
832  MarkBufferDirty(target);
833 
834  /* Fix left-link of right sibling */
835  if (XLogReadBufferForRedo(record, 2, &rightbuf) == BLK_NEEDS_REDO)
836  {
837  page = (Page) BufferGetPage(rightbuf);
838  pageop = (BTPageOpaque) PageGetSpecialPointer(page);
839  pageop->btpo_prev = leftsib;
840 
841  PageSetLSN(page, lsn);
842  MarkBufferDirty(rightbuf);
843  }
844 
845  /* Release siblings */
846  if (BufferIsValid(leftbuf))
847  UnlockReleaseBuffer(leftbuf);
848  if (BufferIsValid(rightbuf))
849  UnlockReleaseBuffer(rightbuf);
850 
851  /* Release target */
852  UnlockReleaseBuffer(target);
853 
854  /*
855  * If we deleted a parent of the targeted leaf page, instead of the leaf
856  * itself, update the leaf to point to the next remaining child in the
857  * to-be-deleted subtree
858  */
859  if (XLogRecHasBlockRef(record, 3))
860  {
861  /*
862  * There is no real data on the page, so we just re-create it from
863  * scratch using the information from the WAL record.
864  *
865  * Note that we don't end up here when the target page is also the
866  * leafbuf page. There is no need to add a dummy hikey item with a
867  * top parent link when deleting leafbuf because it's the last page
868  * we'll delete in the subtree undergoing deletion.
869  */
870  Buffer leafbuf;
871  IndexTupleData trunctuple;
872 
873  leafbuf = XLogInitBufferForRedo(record, 3);
874  page = (Page) BufferGetPage(leafbuf);
875 
876  _bt_pageinit(page, BufferGetPageSize(leafbuf));
877  pageop = (BTPageOpaque) PageGetSpecialPointer(page);
878 
879  pageop->btpo_flags = BTP_HALF_DEAD | BTP_LEAF;
880  pageop->btpo_prev = xlrec->leafleftsib;
881  pageop->btpo_next = xlrec->leafrightsib;
882  pageop->btpo.level = 0;
883  pageop->btpo_cycleid = 0;
884 
885  /* Add a dummy hikey item */
886  MemSet(&trunctuple, 0, sizeof(IndexTupleData));
887  trunctuple.t_info = sizeof(IndexTupleData);
888  BTreeTupleSetTopParent(&trunctuple, xlrec->topparent);
889 
890  if (PageAddItem(page, (Item) &trunctuple, sizeof(IndexTupleData), P_HIKEY,
891  false, false) == InvalidOffsetNumber)
892  elog(ERROR, "could not add dummy high key to half-dead page");
893 
894  PageSetLSN(page, lsn);
895  MarkBufferDirty(leafbuf);
896  UnlockReleaseBuffer(leafbuf);
897  }
898 
899  /* Update metapage if needed */
900  if (info == XLOG_BTREE_UNLINK_PAGE_META)
901  _bt_restore_meta(record, 4);
902 }
903 
904 static void
906 {
907  XLogRecPtr lsn = record->EndRecPtr;
908  xl_btree_newroot *xlrec = (xl_btree_newroot *) XLogRecGetData(record);
909  Buffer buffer;
910  Page page;
911  BTPageOpaque pageop;
912  char *ptr;
913  Size len;
914 
915  buffer = XLogInitBufferForRedo(record, 0);
916  page = (Page) BufferGetPage(buffer);
917 
918  _bt_pageinit(page, BufferGetPageSize(buffer));
919  pageop = (BTPageOpaque) PageGetSpecialPointer(page);
920 
921  pageop->btpo_flags = BTP_ROOT;
922  pageop->btpo_prev = pageop->btpo_next = P_NONE;
923  pageop->btpo.level = xlrec->level;
924  if (xlrec->level == 0)
925  pageop->btpo_flags |= BTP_LEAF;
926  pageop->btpo_cycleid = 0;
927 
928  if (xlrec->level > 0)
929  {
930  ptr = XLogRecGetBlockData(record, 0, &len);
931  _bt_restore_page(page, ptr, len);
932 
933  /* Clear the incomplete-split flag in left child */
934  _bt_clear_incomplete_split(record, 1);
935  }
936 
937  PageSetLSN(page, lsn);
938  MarkBufferDirty(buffer);
939  UnlockReleaseBuffer(buffer);
940 
941  _bt_restore_meta(record, 2);
942 }
943 
944 static void
946 {
948 
949  /*
950  * Btree reuse_page records exist to provide a conflict point when we
951  * reuse pages in the index via the FSM. That's all they do though.
952  *
953  * latestRemovedXid was the page's btpo.xact. The
954  * GlobalVisCheckRemovableXid test in _bt_page_recyclable() conceptually
955  * mirrors the pgxact->xmin > limitXmin test in
956  * GetConflictingVirtualXIDs(). Consequently, one XID value achieves the
957  * same exclusion effect on primary and standby.
958  */
959  if (InHotStandby)
960  {
962  xlrec->node);
963  }
964 }
965 
966 void
968 {
969  uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
970  MemoryContext oldCtx;
971 
972  oldCtx = MemoryContextSwitchTo(opCtx);
973  switch (info)
974  {
976  btree_xlog_insert(true, false, false, record);
977  break;
979  btree_xlog_insert(false, false, false, record);
980  break;
982  btree_xlog_insert(false, true, false, record);
983  break;
984  case XLOG_BTREE_SPLIT_L:
985  btree_xlog_split(true, record);
986  break;
987  case XLOG_BTREE_SPLIT_R:
988  btree_xlog_split(false, record);
989  break;
991  btree_xlog_insert(true, false, true, record);
992  break;
993  case XLOG_BTREE_DEDUP:
994  btree_xlog_dedup(record);
995  break;
996  case XLOG_BTREE_VACUUM:
997  btree_xlog_vacuum(record);
998  break;
999  case XLOG_BTREE_DELETE:
1000  btree_xlog_delete(record);
1001  break;
1003  btree_xlog_mark_page_halfdead(info, record);
1004  break;
1007  btree_xlog_unlink_page(info, record);
1008  break;
1009  case XLOG_BTREE_NEWROOT:
1010  btree_xlog_newroot(record);
1011  break;
1012  case XLOG_BTREE_REUSE_PAGE:
1013  btree_xlog_reuse_page(record);
1014  break;
1016  _bt_restore_meta(record, 0);
1017  break;
1018  default:
1019  elog(PANIC, "btree_redo: unknown op code %u", info);
1020  }
1021  MemoryContextSwitchTo(oldCtx);
1022  MemoryContextReset(opCtx);
1023 }
1024 
1025 void
1027 {
1029  "Btree recovery temporary context",
1031 }
1032 
1033 void
1035 {
1036  MemoryContextDelete(opCtx);
1037  opCtx = NULL;
1038 }
1039 
1040 /*
1041  * Mask a btree page before performing consistency checks on it.
1042  */
1043 void
1044 btree_mask(char *pagedata, BlockNumber blkno)
1045 {
1046  Page page = (Page) pagedata;
1047  BTPageOpaque maskopaq;
1048 
1050 
1051  mask_page_hint_bits(page);
1052  mask_unused_space(page);
1053 
1054  maskopaq = (BTPageOpaque) PageGetSpecialPointer(page);
1055 
1056  if (P_ISLEAF(maskopaq))
1057  {
1058  /*
1059  * In btree leaf pages, it is possible to modify the LP_FLAGS without
1060  * emitting any WAL record. Hence, mask the line pointer flags. See
1061  * _bt_killitems(), _bt_check_unique() for details.
1062  */
1063  mask_lp_flags(page);
1064  }
1065 
1066  /*
1067  * BTP_HAS_GARBAGE is just an un-logged hint bit. So, mask it. See
1068  * _bt_delete_or_dedup_one_page(), _bt_killitems(), and _bt_check_unique()
1069  * for details.
1070  */
1071  maskopaq->btpo_flags &= ~BTP_HAS_GARBAGE;
1072 
1073  /*
1074  * During replay of a btree page split, we don't set the BTP_SPLIT_END
1075  * flag of the right sibling and initialize the cycle_id to 0 for the same
1076  * page. See btree_xlog_split() for details.
1077  */
1078  maskopaq->btpo_flags &= ~BTP_SPLIT_END;
1079  maskopaq->btpo_cycleid = 0;
1080 }
char * intervals[]
bool allequalimage
Definition: nbtxlog.h:57
TransactionId latestRemovedXid
Definition: nbtxlog.h:189
IndexTuple base
Definition: nbtree.h:746
uint16 ndeletedtids
Definition: nbtree.h:782
#define BTP_ROOT
Definition: nbtree.h:73
#define BTP_SPLIT_END
Definition: nbtree.h:77
BlockNumber btpo_next
Definition: nbtree.h:59
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:212
#define AllocSetContextCreate
Definition: memutils.h:170
void _bt_update_posting(BTVacuumPosting vacposting)
Definition: nbtdedup.c:632
void PageRestoreTempPage(Page tempPage, Page oldPage)
Definition: bufpage.c:411
uint16 nintervals
Definition: nbtxlog.h:172
OffsetNumber baseoff
Definition: nbtree.h:747
uint32 btm_version
Definition: nbtree.h:101
#define SizeOfBtreeUpdate
Definition: nbtxlog.h:225
void PageIndexTupleDelete(Page page, OffsetNumber offnum)
Definition: bufpage.c:935
void MarkBufferDirty(Buffer buffer)
Definition: bufmgr.c:1471
static void btree_xlog_vacuum(XLogReaderState *record)
Definition: nbtxlog.c:560
OffsetNumber updatedoffset
Definition: nbtree.h:779
#define P_FIRSTDATAKEY(opaque)
Definition: nbtree.h:244
uint32 btm_magic
Definition: nbtree.h:100
#define BTP_LEAF
Definition: nbtree.h:72
#define BTP_HALF_DEAD
Definition: nbtree.h:76
BlockNumber root
Definition: nbtxlog.h:51
IndexTuple itup
Definition: nbtree.h:778
union BTPageOpaqueData::@45 btpo
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
unsigned char uint8
Definition: c.h:427
Pointer Item
Definition: item.h:17
#define P_NONE
Definition: nbtree.h:206
static BlockNumber BTreeTupleGetDownLink(IndexTuple pivot)
Definition: nbtree.h:424
void mask_page_hint_bits(Page page)
Definition: bufmask.c:46
#define InvalidBuffer
Definition: buf.h:25
#define XLOG_BTREE_INSERT_META
Definition: nbtxlog.h:28
#define P_HAS_GARBAGE(opaque)
Definition: nbtree.h:220
RelFileNode node
Definition: nbtxlog.h:206
#define XLogRecHasBlockRef(decoder, block_id)
Definition: xlogreader.h:313
#define InHotStandby
Definition: xlog.h:74
uint32 level
Definition: nbtxlog.h:319
#define BTP_INCOMPLETE_SPLIT
Definition: nbtree.h:79
#define MemSet(start, val, len)
Definition: c.h:1004
#define PageAddItem(page, item, size, offsetNumber, overwrite, is_heap)
Definition: bufpage.h:416
void MemoryContextReset(MemoryContext context)
Definition: mcxt.c:137
uint32 BlockNumber
Definition: block.h:31
void _bt_dedup_start_pending(BTDedupState state, IndexTuple base, OffsetNumber baseoff)
Definition: nbtdedup.c:280
uint16 nupdated
Definition: nbtxlog.h:243
#define P_INCOMPLETE_SPLIT(opaque)
Definition: nbtree.h:221
#define BTP_DELETED
Definition: nbtree.h:74
void btree_redo(XLogReaderState *record)
Definition: nbtxlog.c:967
static void btree_xlog_delete(XLogReaderState *record)
Definition: nbtxlog.c:647
#define PANIC
Definition: elog.h:53
IndexTuple _bt_swap_posting(IndexTuple newitem, IndexTuple oposting, int postingoff)
Definition: nbtdedup.c:730
Size _bt_dedup_finish_pending(Page newpage, BTDedupState state)
Definition: nbtdedup.c:402
#define PageGetMaxOffsetNumber(page)
Definition: bufpage.h:357
TransactionId xact
Definition: nbtree.h:63
#define BTP_META
Definition: nbtree.h:75
BTPageOpaqueData * BTPageOpaque
Definition: nbtree.h:69
uint32 ndeleted
Definition: nbtxlog.h:190
void mask_unused_space(Page page)
Definition: bufmask.c:71
XLogRecPtr EndRecPtr
Definition: xlogreader.h:176
uint16 OffsetNumber
Definition: off.h:24
Page PageGetTempPageCopySpecial(Page page)
Definition: bufpage.c:389
ItemPointer htids
Definition: nbtree.h:751
BlockNumber btm_fastroot
Definition: nbtree.h:104
#define XLOG_BTREE_NEWROOT
Definition: nbtxlog.h:36
unsigned short uint16
Definition: c.h:428
void pfree(void *pointer)
Definition: mcxt.c:1057
#define ItemIdGetLength(itemId)
Definition: itemid.h:59
#define BTREE_MAGIC
Definition: nbtree.h:142
static void btree_xlog_newroot(XLogReaderState *record)
Definition: nbtxlog.c:905
static void _bt_restore_meta(XLogReaderState *record, uint8 block_id)
Definition: nbtxlog.c:85
#define XLogRecGetData(decoder)
Definition: xlogreader.h:310
Size phystupsize
Definition: nbtree.h:754
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3536
#define ERROR
Definition: elog.h:43
static void btree_xlog_reuse_page(XLogReaderState *record)
Definition: nbtxlog.c:945
float8 last_cleanup_num_heap_tuples
Definition: nbtxlog.h:56
Buffer XLogInitBufferForRedo(XLogReaderState *record, uint8 block_id)
Definition: xlogutils.c:305
BTDedupInterval intervals[MaxIndexTuplesPerPage]
Definition: nbtree.h:763
#define XLOG_BTREE_INSERT_LEAF
Definition: nbtxlog.h:26
OffsetNumber newitemoff
Definition: nbtxlog.h:157
BTCycleId btpo_cycleid
Definition: nbtree.h:66
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:192
TransactionId oldest_btpo_xact
Definition: nbtxlog.h:55
#define BTPageGetMeta(p)
Definition: nbtree.h:114
bool btm_allequalimage
Definition: nbtree.h:111
bool PageIndexTupleOverwrite(Page page, OffsetNumber offnum, Item newtup, Size newsize)
Definition: bufpage.c:1288
BlockNumber btpo_prev
Definition: nbtree.h:58
IndexTuple CopyIndexTuple(IndexTuple source)
Definition: indextuple.c:510
static void _bt_clear_incomplete_split(XLogReaderState *record, uint8 block_id)
Definition: nbtxlog.c:142
static char * buf
Definition: pg_test_fsync.c:68
bool _bt_dedup_save_htid(BTDedupState state, IndexTuple itup)
Definition: nbtdedup.c:331
IndexTupleData * IndexTuple
Definition: itup.h:53
#define XLOG_BTREE_VACUUM
Definition: nbtxlog.h:38
#define XLOG_BTREE_UNLINK_PAGE
Definition: nbtxlog.h:34
static void btree_xlog_dedup(XLogReaderState *record)
Definition: nbtxlog.c:467
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
static void BTreeTupleSetDownLink(IndexTuple pivot, BlockNumber blkno)
Definition: nbtree.h:430
#define BTREE_NOVAC_VERSION
Definition: nbtree.h:145
#define BufferGetPage(buffer)
Definition: bufmgr.h:169
static void btree_xlog_insert(bool isleaf, bool ismeta, bool posting, XLogReaderState *record)
Definition: nbtxlog.c:163
#define XLogRecGetInfo(decoder)
Definition: xlogreader.h:305
#define BTREE_METAPAGE
Definition: nbtree.h:141
uint32 version
Definition: nbtxlog.h:50
#define XLOG_BTREE_DELETE
Definition: nbtxlog.h:33
uint16 ndeleted
Definition: nbtxlog.h:242
#define XLOG_BTREE_DEDUP
Definition: nbtxlog.h:32
#define PageGetItemId(page, offsetNumber)
Definition: bufpage.h:235
uint32 btm_fastlevel
Definition: nbtree.h:105
uint32 level
Definition: nbtree.h:62
bool XLogRecGetBlockTag(XLogReaderState *record, uint8 block_id, RelFileNode *rnode, ForkNumber *forknum, BlockNumber *blknum)
Definition: xlogreader.c:1498
char * XLogRecGetBlockData(XLogReaderState *record, uint8 block_id, Size *len)
Definition: xlogreader.c:1522
#define XLOG_BTREE_REUSE_PAGE
Definition: nbtxlog.h:40
void mask_page_lsn_and_checksum(Page page)
Definition: bufmask.c:31
uint32 level
Definition: nbtxlog.h:155
#define XLOG_BTREE_MARK_PAGE_HALFDEAD
Definition: nbtxlog.h:37
uint16 deletetids[FLEXIBLE_ARRAY_MEMBER]
Definition: nbtree.h:783
OffsetNumber offnum
Definition: nbtxlog.h:81
struct IndexTupleData IndexTupleData
static void _bt_restore_page(Page page, char *from, int len)
Definition: nbtxlog.c:38
#define BufferGetPageSize(buffer)
Definition: bufmgr.h:156
BlockNumber btm_root
Definition: nbtree.h:102
#define InvalidOffsetNumber
Definition: off.h:26
#define XLOG_BTREE_SPLIT_R
Definition: nbtxlog.h:30
#define BlockNumberIsValid(blockNumber)
Definition: block.h:70
void btree_xlog_cleanup(void)
Definition: nbtxlog.c:1034
XLogRedoAction XLogReadBufferForRedo(XLogReaderState *record, uint8 block_id, Buffer *buf)
Definition: xlogutils.c:293
static MemoryContext opCtx
Definition: nbtxlog.c:27
uint16 nitems
Definition: nbtree.h:717
PageHeaderData * PageHeader
Definition: bufpage.h:166
uint64 XLogRecPtr
Definition: xlogdefs.h:21
#define Assert(condition)
Definition: c.h:800
#define XLR_INFO_MASK
Definition: xlogrecord.h:62
Definition: regguts.h:298
void PageIndexMultiDelete(Page page, OffsetNumber *itemnos, int nitems)
Definition: bufpage.c:1044
#define XLOG_BTREE_INSERT_POST
Definition: nbtxlog.h:31
#define OffsetNumberNext(offsetNumber)
Definition: off.h:52
size_t Size
Definition: c.h:528
#define PageGetSpecialPointer(page)
Definition: bufpage.h:326
#define OffsetNumberPrev(offsetNumber)
Definition: off.h:54
float8 btm_last_cleanup_num_heap_tuples
Definition: nbtree.h:109
#define MAXALIGN(LEN)
Definition: c.h:753
#define BufferIsValid(bufnum)
Definition: bufmgr.h:123
static void btree_xlog_unlink_page(uint8 info, XLogReaderState *record)
Definition: nbtxlog.c:777
Size basetupsize
Definition: nbtree.h:748
#define XLOG_BTREE_INSERT_UPPER
Definition: nbtxlog.h:27
Size maxpostingsize
Definition: nbtree.h:743
#define BTMaxItemSize(page)
Definition: nbtree.h:157
#define P_HIKEY
Definition: nbtree.h:242
BlockNumber BufferGetBlockNumber(Buffer buffer)
Definition: bufmgr.c:2663
#define MaxIndexTuplesPerPage
Definition: itup.h:145
void * palloc(Size size)
Definition: mcxt.c:950
static void btree_xlog_mark_page_halfdead(uint8 info, XLogReaderState *record)
Definition: nbtxlog.c:692
bool deduplicate
Definition: nbtree.h:741
XLogRedoAction XLogReadBufferForRedoExtended(XLogReaderState *record, uint8 block_id, ReadBufferMode mode, bool get_cleanup_lock, Buffer *buf)
Definition: xlogutils.c:330
uint32 fastlevel
Definition: nbtxlog.h:54
uint32 btm_level
Definition: nbtree.h:103
#define elog(elevel,...)
Definition: elog.h:228
uint32 level
Definition: nbtxlog.h:52
int i
void _bt_pageinit(Page page, Size size)
Definition: nbtpage.c:1066
void ResolveRecoveryConflictWithSnapshot(TransactionId latestRemovedXid, RelFileNode node)
Definition: standby.c:304
#define XLOG_BTREE_SPLIT_L
Definition: nbtxlog.h:29
BlockNumber fastroot
Definition: nbtxlog.h:53
#define XLOG_BTREE_UNLINK_PAGE_META
Definition: nbtxlog.h:35
TransactionId latestRemovedXid
Definition: nbtxlog.h:208
TransactionId btm_oldest_btpo_xact
Definition: nbtree.h:107
unsigned short t_info
Definition: itup.h:49
BTDedupStateData * BTDedupState
Definition: nbtree.h:766
uint16 postingoff
Definition: nbtxlog.h:158
static void btree_xlog_split(bool newitemonleft, XLogReaderState *record)
Definition: nbtxlog.c:254
OffsetNumber baseoff
Definition: nbtree.h:716
uint16 btpo_flags
Definition: nbtree.h:65
OffsetNumber firstrightoff
Definition: nbtxlog.h:156
#define PageSetLSN(page, lsn)
Definition: bufpage.h:368
int Buffer
Definition: buf.h:23
#define P_RIGHTMOST(opaque)
Definition: nbtree.h:213
static void BTreeTupleSetTopParent(IndexTuple leafhikey, BlockNumber blkno)
Definition: nbtree.h:494
void btree_xlog_startup(void)
Definition: nbtxlog.c:1026
#define XLOG_BTREE_META_CLEANUP
Definition: nbtxlog.h:42
void mask_lp_flags(Page page)
Definition: bufmask.c:95
#define offsetof(type, field)
Definition: c.h:723
void btree_mask(char *pagedata, BlockNumber blkno)
Definition: nbtxlog.c:1044
#define BTP_HAS_GARBAGE
Definition: nbtree.h:78
uint16 ndeletedtids
Definition: nbtxlog.h:220
#define PageGetItem(page, itemId)
Definition: bufpage.h:340
Pointer Page
Definition: bufpage.h:78
#define IndexTupleSize(itup)
Definition: itup.h:71
#define P_ISLEAF(opaque)
Definition: nbtree.h:214