From 8da372b5bbae38d162a01edc63094f9099e138e8 Mon Sep 17 00:00:00 2001
From: Andrey Borodin <amborodin@acm.org>
Date: Fri, 30 Jul 2021 15:06:30 +0500
Subject: [PATCH v8 4/4] Debug suff

---
 contrib/amcheck/verify_nbtree.c  | 17 +++++++++++++++--
 src/backend/commands/indexcmds.c |  8 +++++++-
 src/backend/storage/lmgr/lock.c  |  1 +
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/contrib/amcheck/verify_nbtree.c b/contrib/amcheck/verify_nbtree.c
index fdfc320e84..ac2cfe19c6 100644
--- a/contrib/amcheck/verify_nbtree.c
+++ b/contrib/amcheck/verify_nbtree.c
@@ -2471,16 +2471,29 @@ bt_tuple_present_callback(Relation index, ItemPointer tid, Datum *values,
 	/* Probe Bloom filter -- tuple should be present */
 	if (bloom_lacks_element(state->filter, (unsigned char *) norm,
 							IndexTupleSize(norm)))
+{
+		BlockIdData bid = tid->ip_blkid;
+		Buffer buf = ReadBufferExtended(state->heaprel, MAIN_FORKNUM, BlockIdGetBlockNumber(&bid), RBM_NORMAL, NULL);
+		LockBuffer(buf, BUFFER_LOCK_SHARE);
+		Page page = BufferGetPage(buf);
+
+		HeapTupleHeader tuphdr = (HeapTupleHeader) PageGetItem(page, PageGetItemId(page,tid->ip_posid));
+
+		LockBuffer(buf, BUFFER_LOCK_UNLOCK);
+		ReleaseBuffer(buf);
 		ereport(ERROR,
 				(errcode(ERRCODE_DATA_CORRUPTED),
-				 errmsg("heap tuple (%u,%u) from table \"%s\" lacks matching index tuple within index \"%s\"",
+				 errmsg("heap tuple (%u,%u) from table \"%s\" lacks matching index tuple within index \"%s\" xmin %d xmax %d",
 						ItemPointerGetBlockNumber(&(itup->t_tid)),
 						ItemPointerGetOffsetNumber(&(itup->t_tid)),
 						RelationGetRelationName(state->heaprel),
-						RelationGetRelationName(state->rel)),
+						RelationGetRelationName(state->rel),
+						HeapTupleHeaderGetRawXmin(tuphdr),
+						HeapTupleHeaderGetRawXmax(tuphdr)),
 				 !state->readonly
 				 ? errhint("Retrying verification using the function bt_index_parent_check() might provide a more specific error.")
 				 : 0));
+	}
 
 	state->heaptuplespresent++;
 	pfree(itup);
diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c
index 76774dce06..8a4a17d81b 100644
--- a/src/backend/commands/indexcmds.c
+++ b/src/backend/commands/indexcmds.c
@@ -3519,6 +3519,7 @@ ReindexRelationConcurrently(Oid relationOid, ReindexParams *params)
 	 * for efficiency.
 	 */
 
+	elog(WARNING, "Phase 1");
 	/*
 	 * Phase 1 of REINDEX CONCURRENTLY
 	 *
@@ -3668,7 +3669,7 @@ ReindexRelationConcurrently(Oid relationOid, ReindexParams *params)
 	 * Because we don't take a snapshot in this transaction, there's no need
 	 * to set the PROC_IN_SAFE_IC flag here.
 	 */
-
+	elog(WARNING, "Phase 2");
 	/*
 	 * Phase 2 of REINDEX CONCURRENTLY
 	 *
@@ -3730,6 +3731,7 @@ ReindexRelationConcurrently(Oid relationOid, ReindexParams *params)
 	 * need to set the PROC_IN_SAFE_IC flag here.
 	 */
 
+	elog(WARNING, "Phase 3");
 	/*
 	 * Phase 3 of REINDEX CONCURRENTLY
 	 *
@@ -3816,6 +3818,7 @@ ReindexRelationConcurrently(Oid relationOid, ReindexParams *params)
 		CommitTransactionCommand();
 	}
 
+	elog(WARNING, "Phase 4");
 	/*
 	 * Phase 4 of REINDEX CONCURRENTLY
 	 *
@@ -3889,6 +3892,7 @@ ReindexRelationConcurrently(Oid relationOid, ReindexParams *params)
 	 * done, and that lasts for a very short period.
 	 */
 
+	elog(WARNING, "Phase 5");
 	/*
 	 * Phase 5 of REINDEX CONCURRENTLY
 	 *
@@ -3925,6 +3929,7 @@ ReindexRelationConcurrently(Oid relationOid, ReindexParams *params)
 	 * done, and that lasts for a very short period.
 	 */
 
+	elog(WARNING, "Phase 6");
 	/*
 	 * Phase 6 of REINDEX CONCURRENTLY
 	 *
@@ -4010,6 +4015,7 @@ ReindexRelationConcurrently(Oid relationOid, ReindexParams *params)
 	MemoryContextDelete(private_context);
 
 	pgstat_progress_end_command();
+	elog(WARNING, "Phase Final");
 
 	return true;
 }
diff --git a/src/backend/storage/lmgr/lock.c b/src/backend/storage/lmgr/lock.c
index becddef7fe..e56bee66bd 100644
--- a/src/backend/storage/lmgr/lock.c
+++ b/src/backend/storage/lmgr/lock.c
@@ -4547,6 +4547,7 @@ VirtualXactLock(VirtualTransactionId vxid, bool wait)
 	TransactionId	xid = InvalidTransactionId;
 
 	Assert(VirtualTransactionIdIsValid(vxid));
+	elog(WARNING,"XXX: VirtualXactLock vxid %d/%d", vxid.backendId, vxid.localTransactionId);	// Remove this line
 
 	/*
 	 * Already prepared transactions don't hold vxid locks.  The
-- 
2.24.3 (Apple Git-128)

