summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/backend/storage/ipc/standby.c9
-rw-r--r--src/backend/storage/lmgr/lmgr.c18
-rw-r--r--src/include/storage/lmgr.h1
3 files changed, 27 insertions, 1 deletions
diff --git a/src/backend/storage/ipc/standby.c b/src/backend/storage/ipc/standby.c
index df9a9a495b6..9d0c27219b9 100644
--- a/src/backend/storage/ipc/standby.c
+++ b/src/backend/storage/ipc/standby.c
@@ -82,7 +82,7 @@ InitRecoveryTransactionEnvironment(void)
* hold AccessShareLocks so never block while we write or lock new rows.
*/
vxid.backendId = MyBackendId;
- vxid.localTransactionId = GetNextLocalTransactionId();
+ vxid.localTransactionId = MyProc->lxid = GetNextLocalTransactionId();
VirtualXactLockTableInsert(vxid);
standbyState = STANDBY_INITIALIZED;
@@ -98,11 +98,18 @@ InitRecoveryTransactionEnvironment(void)
void
ShutdownRecoveryTransactionEnvironment(void)
{
+ VirtualTransactionId vxid;
+
/* Mark all tracked in-progress transactions as finished. */
ExpireAllKnownAssignedTransactionIds();
/* Release all locks the tracked transactions were holding */
StandbyReleaseAllLocks();
+
+ /* Cleanup our VirtualTransaction */
+ vxid.backendId = MyBackendId;
+ vxid.localTransactionId = MyProc->lxid;
+ VirtualXactLockTableDelete(vxid);
}
diff --git a/src/backend/storage/lmgr/lmgr.c b/src/backend/storage/lmgr/lmgr.c
index 75f2f2666e0..9a41d47fbbf 100644
--- a/src/backend/storage/lmgr/lmgr.c
+++ b/src/backend/storage/lmgr/lmgr.c
@@ -535,6 +535,24 @@ VirtualXactLockTableInsert(VirtualTransactionId vxid)
}
/*
+ * VirtualXactLockTableDelete
+ *
+ * Release a Virtual Transaction lock. Only called by Startup process
+ * at end of Hot Standby.
+ */
+void
+VirtualXactLockTableDelete(VirtualTransactionId vxid)
+{
+ LOCKTAG tag;
+
+ Assert(VirtualTransactionIdIsValid(vxid));
+
+ SET_LOCKTAG_VIRTUALTRANSACTION(tag, vxid);
+
+ (void) LockRelease(&tag, ExclusiveLock, false);
+}
+
+/*
* VirtualXactLockTableWait
*
* Waits until the lock on the given VXID is released, which shows that
diff --git a/src/include/storage/lmgr.h b/src/include/storage/lmgr.h
index 64b19e334c7..e40dcb6fe7e 100644
--- a/src/include/storage/lmgr.h
+++ b/src/include/storage/lmgr.h
@@ -58,6 +58,7 @@ extern bool ConditionalXactLockTableWait(TransactionId xid);
/* Lock a VXID (used to wait for a transaction to finish) */
extern void VirtualXactLockTableInsert(VirtualTransactionId vxid);
+extern void VirtualXactLockTableDelete(VirtualTransactionId vxid);
extern void VirtualXactLockTableWait(VirtualTransactionId vxid);
extern bool ConditionalVirtualXactLockTableWait(VirtualTransactionId vxid);