From 126e9cc8da96ffa1a0c9842961db78b96d920917 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/13] 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 f2e0272ab1..b5502f2417 100644
--- a/src/backend/access/undo/undolog.c
+++ b/src/backend/access/undo/undolog.c
@@ -940,11 +940,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);
 		}
@@ -1284,8 +1284,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. */
@@ -1293,7 +1293,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();
@@ -2571,8 +2571,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 c4a6b29ef0..1c79c1ff32 100644
--- a/src/include/access/undolog.h
+++ b/src/include/access/undolog.h
@@ -211,16 +211,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;
 
 /*
@@ -241,6 +231,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;
 
 /*
-- 
2.16.2.windows.1

