From 880f25a543783f8dc3784a51ab1c29b72f6b5b27 Mon Sep 17 00:00:00 2001
From: Dilip Kumar <dilip.kumar@enterprisedb.com>
Date: Fri, 7 Jun 2019 15:03:37 +0530
Subject: [PATCH 06/14] Defect and enhancement in multi-log support

---
 src/backend/access/undo/undolog.c | 18 +++++++++---------
 src/include/access/undolog.h      | 20 ++++++++++----------
 2 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/src/backend/access/undo/undolog.c b/src/backend/access/undo/undolog.c
index 67b08e7..014480f 100644
--- a/src/backend/access/undo/undolog.c
+++ b/src/backend/access/undo/undolog.c
@@ -909,11 +909,11 @@ UndoLogAllocateInRecovery(UndoLogAllocContext *context,
 			context->recovery_logno = slot->logno;
 
 			/* Read log switch information from meta and reset it. */
-			*prevlog_xact_start = slot->meta.unlogged.prevlog_xact_start;
-			*prevlog_last_urp = slot->meta.unlogged.prevlog_last_urp;
+			*prevlog_xact_start = slot->meta.prevlog_xact_start;
+			*prevlog_last_urp = slot->meta.prevlog_last_urp;
 
-			slot->meta.unlogged.prevlog_xact_start = InvalidUndoRecPtr;
-			slot->meta.unlogged.prevlog_last_urp = InvalidUndoRecPtr;
+			slot->meta.prevlog_xact_start = InvalidUndoRecPtr;
+			slot->meta.prevlog_last_urp = InvalidUndoRecPtr;
 
 			return MakeUndoRecPtr(slot->logno, slot->meta.unlogged.insert);
 		}
@@ -1253,8 +1253,8 @@ UndoLogSwitchSetPrevLogInfo(UndoLogNumber logno, UndoRecPtr prevlog_xact_start,
 	Assert(AmAttachedToUndoLogSlot(slot));
 
 	LWLockAcquire(&slot->mutex, LW_EXCLUSIVE);
-	slot->meta.unlogged.prevlog_xact_start = prevlog_last_urp;
-	slot->meta.unlogged.prevlog_last_urp = prevlog_last_urp;
+	slot->meta.prevlog_xact_start = prevlog_xact_start;
+	slot->meta.prevlog_last_urp = prevlog_last_urp;
 	LWLockRelease(&slot->mutex);
 
 	/* Wal log the log switch. */
@@ -1262,7 +1262,7 @@ UndoLogSwitchSetPrevLogInfo(UndoLogNumber logno, UndoRecPtr prevlog_xact_start,
 		xl_undolog_switch xlrec;
 
 		xlrec.logno = logno;
-		xlrec.prevlog_xact_start = prevlog_last_urp;
+		xlrec.prevlog_xact_start = prevlog_xact_start;
 		xlrec.prevlog_last_urp = prevlog_xact_start;
 
 		XLogBeginInsert();
@@ -2543,8 +2543,8 @@ undolog_xlog_switch(XLogReaderState *record)
 	 * Restore the log switch information in the MyUndoLogState this will be
 	 * reset by following UndoLogAllocateDuringRecovery.
 	 */
-	slot->meta.unlogged.prevlog_xact_start = xlrec->prevlog_xact_start;
-	slot->meta.unlogged.prevlog_last_urp = xlrec->prevlog_last_urp;
+	slot->meta.prevlog_xact_start = xlrec->prevlog_xact_start;
+	slot->meta.prevlog_last_urp = xlrec->prevlog_last_urp;
 }
 
 void
diff --git a/src/include/access/undolog.h b/src/include/access/undolog.h
index f8f6f44..994c6a6 100644
--- a/src/include/access/undolog.h
+++ b/src/include/access/undolog.h
@@ -203,16 +203,6 @@ typedef struct UndoLogUnloggedMetaData
 	UndoLogOffset last_xact_start;	/* last transaction's first byte in this log */
 	UndoLogOffset this_xact_start;	/* this transaction's first byte in this log */
 	TransactionId xid;				/* currently attached/writing xid */
-
-	/*
-	 * Below two variable are used during recovery when transaction's undo
-	 * records are split across undo logs.  Replay of switch will restore
-	 * these two undo record pointers which will be reset on next allocation
-	 * during recovery. */
-	UndoRecPtr	prevlog_xact_start; /* Transaction's start undo record pointer
-									 * in the previous log. */
-	UndoRecPtr	prevlog_last_urp;	/* Transaction's last undo record pointer in
-									 * the previous log. */
 } UndoLogUnloggedMetaData;
 
 /*
@@ -233,6 +223,16 @@ typedef struct UndoLogMetaData
 	UndoLogStatus status;
 	UndoLogOffset end;				/* one past end of highest segment */
 	UndoLogOffset discard;			/* oldest data needed (tail) */
+
+	/*
+	 * Below two variable are used during recovery when transaction's undo
+	 * records are split across undo logs.  Replay of switch will restore
+	 * these two undo record pointers which will be reset on next allocation
+	 * during recovery. */
+	UndoRecPtr	prevlog_xact_start; /* Transaction's start undo record pointer
+									 * in the previous log. */
+	UndoRecPtr	prevlog_last_urp;	/* Transaction's last undo record pointer in
+									 * the previous log. */
 } UndoLogMetaData;
 
 /*
-- 
1.8.3.1

