aborted_contrec_reset.diff

text/x-patch

Filename: aborted_contrec_reset.diff
Type: text/x-patch
Part: 1
Message: Re: [BUG] Panic due to incorrect missingContrecPtr after promotion

Patch

Format: unified
File+
src/backend/access/transam/xlogrecovery.c 13 0
diff --git a/src/backend/access/transam/xlogrecovery.c b/src/backend/access/transam/xlogrecovery.c
index 6eba626420..6b026af74e 100644
--- a/src/backend/access/transam/xlogrecovery.c
+++ b/src/backend/access/transam/xlogrecovery.c
@@ -3025,6 +3025,19 @@ ReadRecord(XLogPrefetcher *xlogprefetcher, int emode,
 
 		if (record)
 		{
+			/*
+			 * If we see an complete record after recorded aborted contrecord,
+			 * that means the aborted contrecord is a false one.  This happens
+			 * when we can continue archive recovery after crash recovery ended
+			 * with aborted contrecord.
+			 */
+			if (abortedRecPtr != InvalidXLogRecPtr &&
+				abortedRecPtr < xlogreader->EndRecPtr)
+			{
+				abortedRecPtr = InvalidXLogRecPtr;
+				missingContrecPtr = InvalidXLogRecPtr;
+			}
+
 			/* Great, got a record */
 			return record;
 		}