Skip to content

Commit

Permalink
Emit nbtree vacuum cycle id in nbtree xlog through FPIs
Browse files Browse the repository at this point in the history
This fixes the PostgreSQL side of neondatabase/neon#9929.
  • Loading branch information
MMeent committed Nov 28, 2024
1 parent 284ae56 commit 2ad772b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/backend/access/nbtree/nbtinsert.c
Original file line number Diff line number Diff line change
Expand Up @@ -1978,7 +1978,18 @@ _bt_split(Relation rel, BTScanInsert itup_key, Buffer buf, Buffer cbuf,
XLogBeginInsert();
XLogRegisterData((char *) &xlrec, SizeOfBtreeSplit);

XLogRegisterBuffer(0, buf, REGBUF_STANDARD);
/*
* NEON: If we split during a btree vacuum cycle, and the new right
* sibling is located before the original page in the relation, then
* we have to include the cycle ID in the WAL record. The easiest
* method to do that is to force an image, which happens to be
* relatively cheap, as the data already contained in the record is
* enough to populate the new right page.
*/
if (origpagenumber < rightpagenumber || lopaque->btpo_cycleid == 0)
XLogRegisterBuffer(0, buf, REGBUF_STANDARD);
else
XLogRegisterBuffer(0, buf, REGBUF_FORCE_IMAGE | REGBUF_STANDARD);
XLogRegisterBuffer(1, rbuf, REGBUF_WILL_INIT);
/* Log original right sibling, since we've changed its prev-pointer */
if (!isrightmost)
Expand Down

0 comments on commit 2ad772b

Please sign in to comment.