From 52209e4e5969129ce3a1335559cafbb74dae2672 Mon Sep 17 00:00:00 2001
From: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Date: Fri, 16 Aug 2024 17:59:38 +0900
Subject: [PATCH v34 07/16] Transactional buffer persistence switching

This commit introduces functionality for transactional buffer
persistence switching with no user-side code. The switching is
reverted if the transaction aborts, and both the switching and
reverting are WAL-logged. Repeated back-and-forth switching within and
across subtransactions is prohibited for simplicity.
---
 src/backend/access/rmgrdesc/smgrdesc.c |  13 +
 src/backend/access/transam/twophase.c  |   2 +
 src/backend/access/transam/xact.c      |  16 +-
 src/backend/access/transam/xlog.c      |   1 +
 src/backend/catalog/storage.c          |  32 +++
 src/backend/storage/buffer/bufmgr.c    | 328 +++++++++++++++++++++++++
 src/bin/pg_rewind/parsexlog.c          |   6 +
 src/include/catalog/storage_xlog.h     |  11 +
 src/include/storage/bufmgr.h           |  10 +
 src/tools/pgindent/typedefs.list       |   2 +
 10 files changed, 420 insertions(+), 1 deletion(-)

diff --git a/src/backend/access/rmgrdesc/smgrdesc.c b/src/backend/access/rmgrdesc/smgrdesc.c
index 71410e0a2d..d7b763f529 100644
--- a/src/backend/access/rmgrdesc/smgrdesc.c
+++ b/src/backend/access/rmgrdesc/smgrdesc.c
@@ -40,6 +40,16 @@ smgr_desc(StringInfo buf, XLogReaderState *record)
 						 xlrec->blkno, xlrec->flags);
 		pfree(path);
 	}
+	else if (info == XLOG_SMGR_BUFPERSISTENCE)
+	{
+		xl_smgr_bufpersistence *xlrec = (xl_smgr_bufpersistence *) rec;
+		char	   *path = relpathperm(xlrec->rlocator, MAIN_FORKNUM);
+
+		appendStringInfoString(buf, path);
+		appendStringInfo(buf, " persistence \"%c\"",
+						 xlrec->persistence ? 'p' : 'u');
+		pfree(path);
+	}
 }
 
 const char *
@@ -55,6 +65,9 @@ smgr_identify(uint8 info)
 		case XLOG_SMGR_TRUNCATE:
 			id = "TRUNCATE";
 			break;
+		case XLOG_SMGR_BUFPERSISTENCE:
+			id = "BUFPERSISTENCE";
+			break;
 	}
 
 	return id;
diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c
index bd31b77906..24285c7d20 100644
--- a/src/backend/access/transam/twophase.c
+++ b/src/backend/access/transam/twophase.c
@@ -1588,6 +1588,8 @@ FinishPreparedTransaction(const char *gid, bool isCommit)
 									   abortstats,
 									   gid);
 
+	/* Clean up buffer persistence changes and unecessary files. */
+	PreCommit_Buffers(isCommit);
 	SimpleUndoLog_UndoByXid(isCommit, xid, hdr->nsubxacts, children);
 
 	ProcArrayRemove(proc, latestXid);
diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c
index 19223d35de..78ac4c7d5e 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -2270,6 +2270,9 @@ CommitTransaction(void)
 	CallXactCallbacks(is_parallel_worker ? XACT_EVENT_PARALLEL_PRE_COMMIT
 					  : XACT_EVENT_PRE_COMMIT);
 
+	/* Clean up buffer persistence changes */
+	PreCommit_Buffers(true);
+
 	/*
 	 * If this xact has started any unfinished parallel operation, clean up
 	 * its workers, warning about leaked resources.  (But we don't actually
@@ -2860,6 +2863,9 @@ AbortTransaction(void)
 	 */
 	sigprocmask(SIG_SETMASK, &UnBlockSig, NULL);
 
+	/* Clean up buffer persistence changes */
+	PreCommit_Buffers(false);
+
 	/*
 	 * check the current transaction state
 	 */
@@ -5126,6 +5132,9 @@ CommitSubTransaction(void)
 	CallSubXactCallbacks(SUBXACT_EVENT_PRE_COMMIT_SUB, s->subTransactionId,
 						 s->parent->subTransactionId);
 
+	/* Clean up buffer persistence changes. */
+	PreSubCommit_Buffers(true);
+
 	/*
 	 * If this subxact has started any unfinished parallel operation, clean up
 	 * its workers and exit parallel mode.  Warn about leaked resources.
@@ -5273,6 +5282,9 @@ AbortSubTransaction(void)
 	 */
 	reschedule_timeouts();
 
+	/* Clean up buffer persistence changes */
+	PreSubCommit_Buffers(false);
+
 	/*
 	 * Re-enable signals, in case we got here by longjmp'ing out of a signal
 	 * handler.  We do this fairly early in the sequence so that the timeout
@@ -6246,7 +6258,8 @@ xact_redo_commit(xl_xact_parsed_commit *parsed,
 	}
 
 	SimpleUndoLog_UndoByXid(true, xid, parsed->nsubxacts, parsed->subxacts);
-
+	AtEOXact_Buffers_Redo(true, xid, parsed->nsubxacts, parsed->subxacts);
+	
 	if (parsed->nstats > 0)
 	{
 		/* see equivalent call for relations above */
@@ -6359,6 +6372,7 @@ xact_redo_abort(xl_xact_parsed_abort *parsed, TransactionId xid,
 	}
 
 	SimpleUndoLog_UndoByXid(false, xid, parsed->nsubxacts, parsed->subxacts);
+	AtEOXact_Buffers_Redo(false, xid, parsed->nsubxacts, parsed->subxacts);
 
 	if (parsed->nstats > 0)
 	{
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 2809ce5014..5d234db8f1 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -5897,6 +5897,7 @@ StartupXLOG(void)
 	 */
 	if (InRecovery)
 	{
+		BufmgrDoCleanupRedo();
 		UndoLogCleanup();
 		ResetUnloggedRelations(UNLOGGED_RELATION_INIT);
 	}
diff --git a/src/backend/catalog/storage.c b/src/backend/catalog/storage.c
index 31400c514f..a00c59a274 100644
--- a/src/backend/catalog/storage.c
+++ b/src/backend/catalog/storage.c
@@ -259,6 +259,29 @@ ulog_smgrcreate_redo(SMgrRelation srel, ForkNumber forkNum,
 						   &ulrec, sizeof(ulrec), xid);
 }
 
+/*
+ * Perform XLogInsert of an XLOG_SMGR_BUFPERSISTENCE record to WAL.
+ *
+ * XXX: This function essentially belongs in bufmgr.c, but is placed here to
+ * avoid adding a new rmgr type solely for this record type.
+ */
+void
+log_smgrbufpersistence(const RelFileLocator rlocator, bool persistence)
+{
+	xl_smgr_bufpersistence xlrec;
+
+	/*
+	 * Make an XLOG entry reporting the change of buffer persistence.
+	 */
+	xlrec.rlocator = rlocator;
+	xlrec.persistence = persistence;
+	xlrec.topxid = GetTopTransactionId();
+
+	XLogBeginInsert();
+	XLogRegisterData((char *) &xlrec, sizeof(xlrec));
+	XLogInsert(RM_SMGR_ID, XLOG_SMGR_BUFPERSISTENCE | XLR_SPECIAL_REL_UPDATE);
+}
+
 /*
  * RelationDropStorage
  *		Schedule unlinking of physical storage at transaction commit.
@@ -1118,6 +1141,15 @@ smgr_redo(XLogReaderState *record)
 
 		FreeFakeRelcacheEntry(rel);
 	}
+	else if (info == XLOG_SMGR_BUFPERSISTENCE)
+	{
+		xl_smgr_bufpersistence *xlrec =
+		(xl_smgr_bufpersistence *) XLogRecGetData(record);
+		SMgrRelation reln;
+
+		reln = smgropen(xlrec->rlocator, INVALID_PROC_NUMBER);
+		SetRelationBuffersPersistence(reln, xlrec->persistence);
+	}
 	else
 		elog(PANIC, "smgr_redo: unknown op code %u", info);
 }
diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c
index 2bc60f7295..14360f69b7 100644
--- a/src/backend/storage/buffer/bufmgr.c
+++ b/src/backend/storage/buffer/bufmgr.c
@@ -58,6 +58,7 @@
 #include "storage/smgr.h"
 #include "storage/standby.h"
 #include "utils/memdebug.h"
+#include "utils/memutils.h"
 #include "utils/ps_status.h"
 #include "utils/rel.h"
 #include "utils/resowner.h"
@@ -136,6 +137,23 @@ typedef struct SMgrSortArray
 	SMgrRelation srel;
 } SMgrSortArray;
 
+
+/*
+ * We keep a list of all relations whose buffer persistence has been switched
+ * in the current transaction. This allows us to properly revert the
+ * persistence if the transaction is aborted.
+ */
+typedef struct BufMgrCleanup
+{
+	RelFileLocator rlocator;	/* relation that may need to be deleted */
+	bool		bufpersistence; /* buffer persistence to set */
+	int			nestLevel;		/* xact nesting level of request */
+	TransactionId xid;			/* used during recovery */
+	struct BufMgrCleanup *next;	/* linked-list link */
+} BufMgrCleanup;
+
+static BufMgrCleanup * cleanups = NULL; /* head of linked list */
+
 /*
  * Helper struct for read stream object used in
  * RelationCopyStorageUsingBuffer() function.
@@ -250,6 +268,8 @@ static char *ResOwnerPrintBufferIO(Datum res);
 static void ResOwnerReleaseBufferPin(Datum res);
 static char *ResOwnerPrintBufferPin(Datum res);
 
+static void set_relation_buffers_persistence(SMgrRelation srel, bool permanent);
+
 const ResourceOwnerDesc buffer_io_resowner_desc =
 {
 	.name = "buffer io",
@@ -3557,6 +3577,153 @@ SyncOneBuffer(int buf_id, bool skip_recently_used, WritebackContext *wb_context)
 	return result | BUF_WRITTEN;
 }
 
+/*
+ * bufmgrDoCleanup() -- Take care of buffer persistence chages at end of xact
+ *
+ * This function is called at the end of both transactions and subtransactions,
+ * aiming to immediately clean up failed transactions.
+ */
+static void
+bufmgrDoCleanup(bool isCommit)
+{
+	int	nestLevel = GetCurrentTransactionNestLevel();
+	BufMgrCleanup *cu;
+	BufMgrCleanup *next;
+
+	for (cu = cleanups ; cu && cu->nestLevel <= nestLevel ; cu = next)
+	{
+		next = cu->next;
+		cleanups = next;
+
+		if (!isCommit)
+		{
+			SMgrRelation srel = smgropen(cu->rlocator, INVALID_PROC_NUMBER);
+			set_relation_buffers_persistence(srel, cu->bufpersistence);
+		}
+		pfree(cu);
+	}
+
+#ifdef USE_ASSERT_CHECKING
+	/* All remaining entriespertain to upper levels. */
+	for (cu = cleanups ; cu ; cu = cu->next)
+		Assert(cu->nestLevel < nestLevel);
+#endif
+}
+
+/*
+ * AtEOXact_Buffers_Redo() -- End-of-transaction cleanup of buffer persistence
+ *      chages during rcovery.
+ *
+ * Unlike normal operation, the cleanup entries are keyed by xid rather than by
+ * nestLevel. See SetRelationBuffersPersistenceRedo() for details on the
+ * registration of those entries.
+ */
+void
+AtEOXact_Buffers_Redo(bool isCommit, TransactionId xid,
+					  int nchildren, TransactionId *children)
+{
+	BufMgrCleanup *cu;
+	BufMgrCleanup *prev;
+	BufMgrCleanup *next;
+
+	prev = NULL;
+	for (cu = cleanups ; cu ; cu = next)
+	{
+		next = cu->next;
+
+		if (cu->xid != xid)
+		{
+			int i;
+
+			for (i = 0 ; i < nchildren && cu->xid != children[i] ; i++);
+
+			if (i == nchildren)
+			{
+				/* did not match, go to next */
+				prev = cu;
+				continue;
+			}
+		}
+
+		if (!isCommit)
+		{
+			/*
+			 * Record this revert to WAL without re-registering a BufMgrCleanup
+			 * entry.
+			 */
+			SMgrRelation srel = smgropen(cu->rlocator, INVALID_PROC_NUMBER);
+			set_relation_buffers_persistence(srel, cu->bufpersistence);
+		}
+		if (prev)
+			prev->next = next;
+		else
+			cleanups = next;
+		pfree(cu);
+	}
+}
+
+/*
+ * BufmgrDoCleanupRedo() -- End-of-recovery cleanup of buffer persistence
+ *        chages.
+ *
+ * Revert buffer persistence changes made in transactions that are not
+ * committed at the end of recovery.
+ */
+void
+BufmgrDoCleanupRedo(void)
+{
+	BufMgrCleanup *cu;
+	BufMgrCleanup *next;
+
+	for (cu = cleanups ; cu ; cu = next)
+	{
+		SMgrRelation srel = smgropen(cu->rlocator, INVALID_PROC_NUMBER);
+		set_relation_buffers_persistence(srel, cu->bufpersistence);
+
+		next = cu->next;
+		pfree(cu);
+	}
+
+	cleanups = NULL;
+}
+
+/*
+ * PreSubCommit_Buffers() -- Take care of buffer persistence changes at subxact
+ * end
+ */
+void
+PreSubCommit_Buffers(bool isCommit)
+{
+	int	nestLevel = GetCurrentTransactionNestLevel();
+
+	if (!isCommit)
+	{
+		bufmgrDoCleanup(isCommit);
+		return;
+	}
+
+	/*
+	 * Reassign all cleanup items at the current nestlevel to the parent
+	 * transaction.
+	 */
+
+	for (BufMgrCleanup *cu = cleanups ;
+		 cu && cu->nestLevel >= nestLevel ;
+		 cu = cu->next)
+	{
+		/* no lower-level entry is expected */
+		Assert(cu->nestLevel == nestLevel);
+
+		cu->nestLevel = nestLevel - 1;
+	}
+}
+
+void
+PreCommit_Buffers(bool isCommit)
+{
+	bufmgrDoCleanup(isCommit);
+}
+
 /*
  *		AtEOXact_Buffers - clean up at end of transaction.
  *
@@ -4151,6 +4318,167 @@ DropRelationBuffers(SMgrRelation smgr_reln, ForkNumber *forkNum,
 	}
 }
 
+/*
+ * set_relation_buffers_persistence()
+ *
+ *	The core function to change the persistence of all buffer pages of a
+ *	relation then writes all dirty pages to disk (or kernel disk buffers) when
+ *	switching to PERMANENT, ensuring the kernel has an up-to-date view of the
+ *	relation.
+ *
+ *	The caller must be holding AccessExclusiveLock on the target relation to
+ *	ensure no other backend is busy loading more blocks.
+ *
+ *	XXX currently it sequentially searches the buffer pool; consider
+ *	implementing more efficient search methods.  This routine isn't used in
+ *	performance-critical code paths, so it's not worth additional overhead to
+ *	make it go faster; see also DropRelationBuffers.
+ */
+static void
+set_relation_buffers_persistence(SMgrRelation srel, bool permanent)
+{
+	int			i;
+	RelFileLocator rlocator = srel->smgr_rlocator.locator;
+
+	Assert(!RelFileLocatorBackendIsTemp(srel->smgr_rlocator));
+
+	ResourceOwnerEnlarge(CurrentResourceOwner);
+
+	for (i = 0; i < NBuffers; i++)
+	{
+		BufferDesc *bufHdr = GetBufferDescriptor(i);
+		uint32		buf_state;
+
+		/* try unlocked check to avoid locking irrelevant buffers */
+		if (!RelFileLocatorEquals(BufTagGetRelFileLocator(&bufHdr->tag),
+								  rlocator))
+			continue;
+
+		ReservePrivateRefCountEntry();
+
+		buf_state = LockBufHdr(bufHdr);
+
+		if (!RelFileLocatorEquals(BufTagGetRelFileLocator(&bufHdr->tag),
+								  rlocator))
+		{
+			UnlockBufHdr(bufHdr, buf_state);
+			continue;
+		}
+
+		if (permanent)
+		{
+			/* The init fork is being dropped, drop buffers for it. */
+			if (BufTagGetForkNum(&bufHdr->tag) == INIT_FORKNUM)
+			{
+				InvalidateBuffer(bufHdr);
+				continue;
+			}
+
+			/* Switch the buffer state to BM_PERMANENT before flushing it. */
+			Assert((buf_state & BM_PERMANENT) == 0);
+			buf_state |= BM_PERMANENT;
+			pg_atomic_write_u32(&bufHdr->state, buf_state);
+
+			/*
+			 * We haven't written WALs for this buffer. Flush this buffer to
+			 * establish the epoch for subsequent WAL records.
+			 */
+			if ((buf_state & (BM_VALID | BM_DIRTY)) == (BM_VALID | BM_DIRTY))
+			{
+				PinBuffer_Locked(bufHdr);
+				LWLockAcquire(BufferDescriptorGetContentLock(bufHdr),
+							  LW_SHARED);
+				FlushBuffer(bufHdr, srel, IOOBJECT_RELATION, IOCONTEXT_NORMAL);
+				LWLockRelease(BufferDescriptorGetContentLock(bufHdr));
+				UnpinBuffer(bufHdr);
+			}
+			else
+				UnlockBufHdr(bufHdr, buf_state);
+		}
+		else
+		{
+			/* There shouldn't be an init fork for this relation */
+			Assert(BufTagGetForkNum(&bufHdr->tag) != INIT_FORKNUM);
+			Assert(buf_state & BM_PERMANENT);
+
+			/* Just switch the buffer state to non-permanent. */
+			buf_state &= ~BM_PERMANENT;
+			UnlockBufHdr(bufHdr, buf_state);
+		}
+	}
+}
+
+/* ---------------------------------------------------------------------
+ *	SetRelationBuffersPersistence
+ *
+ *		This function changes the persistence of all buffer pages of a
+ *		relation. See set_relation_buffers_persistence() for functionality
+ *		details.
+ *
+ *		This function's behavior is transactional, meaning that the changes it
+ *		makes will be reverted if this or any higher-level transaction is
+ *		aborted.
+ *
+ *		The caller must be holding AccessExclusiveLock on the target relation
+ *		to ensure no other backend is busy loading more blocks.
+ *		--------------------------------------------------------------------
+ */
+void
+SetRelationBuffersPersistence(SMgrRelation srel, bool permanent)
+{
+	BufMgrCleanup *cu;
+	RelFileLocator rlocator = srel->smgr_rlocator.locator;
+
+	/*
+	 * Double-flipping relation persistence within the same transaction
+	 * significantly increases complexixty relative to its benefits. Therefore,
+	 * error out if persistence has already flipped for this relation in the
+	 * current transaction.
+	 */
+	for (cu = cleanups ; cu ; cu = cu->next)
+	{
+		if (RelFileLocatorEquals(rlocator, cu->rlocator))
+			ereport(ERROR,
+					errmsg("persistence of this relation has been already changed in the current transaction"));
+	}
+
+	set_relation_buffers_persistence(srel, permanent);
+
+	/* Schedule reverting this change at abort */
+	cu = (BufMgrCleanup *)
+		MemoryContextAlloc(TopMemoryContext, sizeof(BufMgrCleanup));
+	cu->rlocator = rlocator;
+	cu->bufpersistence = !permanent;
+	cu->nestLevel = GetCurrentTransactionNestLevel();
+	cu->next = cleanups;
+	cleanups = cu;
+}
+
+/* ---------------------------------------------------------------------
+ *	SetRelationBuffersPersistenceRedo
+ *
+ *		This function changes the persistence of all buffer pages of a relation
+ *		during recovery. The cleanup entry is keyed by xid, not by nestLevel.
+ *		--------------------------------------------------------------------
+ */
+void
+SetRelationBuffersPersistenceRedo(SMgrRelation srel, bool permanent,
+								  TransactionId xid)
+{
+	BufMgrCleanup *cu;
+
+	set_relation_buffers_persistence(srel, permanent);
+
+	/* Schedule reverting this change at abort */
+	cu = (BufMgrCleanup *)
+		MemoryContextAlloc(TopMemoryContext, sizeof(BufMgrCleanup));
+	cu->rlocator = srel->smgr_rlocator.locator;
+	cu->bufpersistence = !permanent;
+	cu->xid = xid;
+	cu->next = cleanups;
+	cleanups = cu;
+}
+
 /* ---------------------------------------------------------------------
  *		DropRelationsAllBuffers
  *
diff --git a/src/bin/pg_rewind/parsexlog.c b/src/bin/pg_rewind/parsexlog.c
index 525b98899f..c8c9cc361f 100644
--- a/src/bin/pg_rewind/parsexlog.c
+++ b/src/bin/pg_rewind/parsexlog.c
@@ -418,6 +418,12 @@ extractPageInfo(XLogReaderState *record)
 		 * source system.
 		 */
 	}
+	else if (rmid == RM_SMGR_ID && rminfo == XLOG_SMGR_BUFPERSISTENCE)
+	{
+		/*
+		 * We can safely ignore these. These don't make any on-disk changes.
+		 */
+	}
 	else if (rmid == RM_XACT_ID &&
 			 ((rminfo & XLOG_XACT_OPMASK) == XLOG_XACT_COMMIT ||
 			  (rminfo & XLOG_XACT_OPMASK) == XLOG_XACT_COMMIT_PREPARED ||
diff --git a/src/include/catalog/storage_xlog.h b/src/include/catalog/storage_xlog.h
index a490e05f88..085b1bc1df 100644
--- a/src/include/catalog/storage_xlog.h
+++ b/src/include/catalog/storage_xlog.h
@@ -29,6 +29,7 @@
 /* XLOG gives us high 4 bits */
 #define XLOG_SMGR_CREATE	0x10
 #define XLOG_SMGR_TRUNCATE	0x20
+#define XLOG_SMGR_BUFPERSISTENCE	0x30
 
 typedef struct xl_smgr_create
 {
@@ -36,6 +37,14 @@ typedef struct xl_smgr_create
 	ForkNumber	forkNum;
 } xl_smgr_create;
 
+typedef struct xl_smgr_bufpersistence
+{
+	RelFileLocator rlocator;
+	bool		persistence;
+	TransactionId topxid;
+	/* subxid is in the record header */
+} xl_smgr_bufpersistence;
+
 /* flags for xl_smgr_truncate */
 #define SMGR_TRUNCATE_HEAP		0x0001
 #define SMGR_TRUNCATE_VM		0x0002
@@ -51,6 +60,8 @@ typedef struct xl_smgr_truncate
 } xl_smgr_truncate;
 
 extern void log_smgrcreate(const RelFileLocator *rlocator, ForkNumber forkNum);
+extern void log_smgrbufpersistence(const RelFileLocator rlocator,
+								   bool persistence);
 
 extern void smgr_redo(XLogReaderState *record);
 extern void smgr_desc(StringInfo buf, XLogReaderState *record);
diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h
index eb0fba4230..4267098080 100644
--- a/src/include/storage/bufmgr.h
+++ b/src/include/storage/bufmgr.h
@@ -19,6 +19,7 @@
 #include "storage/buf.h"
 #include "storage/bufpage.h"
 #include "storage/relfilelocator.h"
+#include "storage/smgr.h"
 #include "utils/relcache.h"
 #include "utils/snapmgr.h"
 
@@ -250,7 +251,14 @@ extern Buffer ExtendBufferedRelTo(BufferManagerRelation bmr,
 								  ReadBufferMode mode);
 
 extern void InitBufferManagerAccess(void);
+extern void PreSubCommit_Buffers(bool isCommit);
+extern void PreCommit_Buffers(bool isCommit);
 extern void AtEOXact_Buffers(bool isCommit);
+extern void SetRelationBuffersPersistenceRedo(SMgrRelation srel, bool permanent,
+											  TransactionId xid);
+extern void AtEOXact_Buffers_Redo(bool isCommit, TransactionId xid,
+								  int nchildren, TransactionId *children);
+extern void BufmgrDoCleanupRedo(void);
 extern char *DebugPrintBufferRefcount(Buffer buffer);
 extern void CheckPointBuffers(int flags);
 extern BlockNumber BufferGetBlockNumber(Buffer buffer);
@@ -269,6 +277,8 @@ extern void DropRelationBuffers(struct SMgrRelationData *smgr_reln,
 extern void DropRelationsAllBuffers(struct SMgrRelationData **smgr_reln,
 									int nlocators);
 extern void DropDatabaseBuffers(Oid dbid);
+extern void SetRelationBuffersPersistence(struct SMgrRelationData *srel,
+										  bool permanent);
 
 #define RelationGetNumberOfBlocks(reln) \
 	RelationGetNumberOfBlocksInFork(reln, MAIN_FORKNUM)
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index c182a65d4d..3975dd50ec 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -329,6 +329,7 @@ BtreeLastVisibleEntry
 BtreeLevel
 Bucket
 BufFile
+BufMgrCleanup
 Buffer
 BufferAccessStrategy
 BufferAccessStrategyType
@@ -4118,6 +4119,7 @@ xl_replorigin_set
 xl_restore_point
 xl_running_xacts
 xl_seq_rec
+xl_smgr_bufpersistence
 xl_smgr_create
 xl_smgr_truncate
 xl_standby_lock
-- 
2.43.5

