From d541acd6dbe253d62ca6d14cc10fd12e30c1583f Mon Sep 17 00:00:00 2001
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
Date: Fri, 3 Sep 2021 17:56:11 -0400
Subject: [PATCH v4 2/4] crosscheck that FIRST_IS_CONTRECORD is not together
 with FIRST_IS_ABORTED_PARTIAL

---
 src/backend/access/transam/xlogreader.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/src/backend/access/transam/xlogreader.c b/src/backend/access/transam/xlogreader.c
index dbfa6d3562..0098c42d2b 100644
--- a/src/backend/access/transam/xlogreader.c
+++ b/src/backend/access/transam/xlogreader.c
@@ -464,6 +464,26 @@ restart:
 			 */
 			if (pageHeader->xlp_info & XLP_FIRST_IS_ABORTED_PARTIAL)
 			{
+				/*
+				 * If we see XLP_FIRST_IS_CONTRECORD together with
+				 * XLP_FIRST_IS_ABORTED_PARTIAL, something has gone wrong
+				 * while writing this record.  However, we don't get too angry
+				 * about it for now.  (If the record is really corrupt, the
+				 * header will fail the CRC check later.)
+				 */
+				if (pageHeader->xlp_info & XLP_FIRST_IS_CONTRECORD)
+				{
+#ifndef FRONTEND
+					ereport(WARNING,
+							(errmsg_internal("unexpected flag XLP_FIRST_IS_CONTRECORD found together with XLP_FIRST_IS_ABORTED_PARTIAL in %X/%X",
+											 LSN_FORMAT_ARGS(targetPagePtr))));
+#else
+					fprintf(stderr,
+							"unexpected flag XLP_FIRST_IS_CONTRECORD found together with XLP_FIRST_IS_ABORTED_PARTIAL in %X/%X\n",
+							LSN_FORMAT_ARGS(targetPagePtr));
+#endif
+				}
+
 				ResetDecoder(state);
 				RecPtr = targetPagePtr;
 				goto restart;
-- 
2.30.2

