From 0e3741181c354932a914161f84a740d8c21bf218 Mon Sep 17 00:00:00 2001
From: David Rowley <dgrowley@gmail.com>
Date: Mon, 20 Mar 2017 20:52:27 +1300
Subject: [PATCH 3/4] Get rid of StandbyReleaseLockTree

This function didn't really have to release the lock tree as the locks
were really only stored against the top level transaction. Instead let's
just use StandbyReleaseLocks(), which should help clear up any confusion.

Author: David Rowley
---
 src/backend/access/transam/twophase.c |  2 +-
 src/backend/access/transam/xact.c     |  8 +++-----
 src/backend/storage/ipc/standby.c     | 29 +++++++----------------------
 src/include/storage/standby.h         |  3 +--
 4 files changed, 12 insertions(+), 30 deletions(-)

diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c
index 4b4999f..14c8be9 100644
--- a/src/backend/access/transam/twophase.c
+++ b/src/backend/access/transam/twophase.c
@@ -2014,7 +2014,7 @@ RecoverPreparedTransactions(void)
 			 * additional locks at any one time.
 			 */
 			if (InHotStandby)
-				StandbyReleaseLockTree(xid, hdr->nsubxacts, subxids);
+				StandbyReleaseLocks(xid);
 
 			/*
 			 * We're done with recovering this transaction. Clear
diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c
index c8751c6..02a864e 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -5430,12 +5430,10 @@ xact_redo_commit(xl_xact_parsed_commit *parsed,
 		/*
 		 * Release locks, if any. We do this for both two phase and normal one
 		 * phase transactions. In effect we are ignoring the prepare phase and
-		 * just going straight to lock release. At commit we release all locks
-		 * via their top-level xid only, so no need to provide subxact list,
-		 * which will save time when replaying commits.
+		 * just going straight to lock release.
 		 */
 		if (parsed->xinfo & XACT_XINFO_HAS_AE_LOCKS)
-			StandbyReleaseLockTree(xid, 0, NULL);
+			StandbyReleaseLocks(xid);
 	}
 
 	if (parsed->xinfo & XACT_XINFO_HAS_ORIGIN)
@@ -5572,7 +5570,7 @@ xact_redo_abort(xl_xact_parsed_abort *parsed, TransactionId xid)
 		 * Release locks, if any. There are no invalidations to send.
 		 */
 		if (parsed->xinfo & XACT_XINFO_HAS_AE_LOCKS)
-			StandbyReleaseLockTree(xid, parsed->nsubxacts, parsed->subxacts);
+			StandbyReleaseLocks(xid);
 	}
 
 	/* Make sure files supposed to be dropped are dropped */
diff --git a/src/backend/storage/ipc/standby.c b/src/backend/storage/ipc/standby.c
index 60b0513..26f6671 100644
--- a/src/backend/storage/ipc/standby.c
+++ b/src/backend/storage/ipc/standby.c
@@ -631,7 +631,13 @@ StandbyAcquireAccessExclusiveLock(TransactionId xid, Oid dbOid, Oid relOid)
 	LockAcquireExtended(&locktag, AccessExclusiveLock, true, false, false);
 }
 
-static void
+/*
+ * Release locks for a transaction.
+ *
+ * Called during WAL replay of COMMIT/ROLLBACK when in hot standby mode,
+ * to remove any AccessExclusiveLocks requested by a transaction.
+ */
+void
 StandbyReleaseLocks(TransactionId xid)
 {
 	ListCell   *cell,
@@ -670,27 +676,6 @@ StandbyReleaseLocks(TransactionId xid)
 }
 
 /*
- * Release locks for a transaction tree.
- *
- * Technically we only track Access Exclusive Locks against the top level
- * transaction, so all we must do here is release the locks for a single
- * transaction ID, and ignore any subtransactions.
- *
- * Called during WAL replay of COMMIT/ROLLBACK when in hot standby mode,
- * to remove any AccessExclusiveLocks requested by a transaction.
- */
-void
-StandbyReleaseLockTree(TransactionId xid, int nsubxids, TransactionId *subxids)
-{
-	StandbyReleaseLocks(xid);
-
-	/*
-	 * If we ever are to track AELs on the subxact which the lock belongs to
-	 * then here marks the spot of where those should be released.
-	 */
-}
-
-/*
  * Called at end of recovery and when we see a shutdown checkpoint.
  */
 void
diff --git a/src/include/storage/standby.h b/src/include/storage/standby.h
index 3ecc446..4246c93 100644
--- a/src/include/storage/standby.h
+++ b/src/include/storage/standby.h
@@ -47,8 +47,7 @@ extern void StandbyLockTimeoutHandler(void);
  * by transactions and running-xacts snapshots.
  */
 extern void StandbyAcquireAccessExclusiveLock(TransactionId xid, Oid dbOid, Oid relOid);
-extern void StandbyReleaseLockTree(TransactionId xid,
-					   int nsubxids, TransactionId *subxids);
+extern void StandbyReleaseLocks(TransactionId xid);
 extern void StandbyReleaseAllLocks(void);
 extern void StandbyReleaseOldLocks(int nxids, TransactionId *xids);
 
-- 
1.9.5.msysgit.1

