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