diff options
author | Simon Riggs <simon@2ndQuadrant.com> | 2012-11-29 23:52:17 +0000 |
---|---|---|
committer | Simon Riggs <simon@2ndQuadrant.com> | 2012-11-29 23:52:17 +0000 |
commit | 6f9a9da85c9015e773d12e8571c469e5a2a6b3fb (patch) | |
tree | a1fe8668551aef6305df94cf3b5acbd32e2eb9c1 | |
parent | 1da5bef3174170a6768bea6621afcbf72dd02a87 (diff) | |
download | postgresql-6f9a9da85c9015e773d12e8571c469e5a2a6b3fb.tar.gz postgresql-6f9a9da85c9015e773d12e8571c469e5a2a6b3fb.zip |
Correctly init/deinit recovery xact environment.
Previously we performed VirtualXactLockTableInsert
but didn't set MyProc->lxid for Startup process.
pg_locks now correctly shows "1/1" for vxid
of Startup process during Hot Standby.
At end of Hot Standby the Virtual Transaction
was not deleted, leading to problems after
promoting to normal running for some commands,
such as CREATE INDEX CONCURRENTLY.
-rw-r--r-- | src/backend/storage/ipc/standby.c | 9 | ||||
-rw-r--r-- | src/backend/storage/lmgr/lmgr.c | 18 | ||||
-rw-r--r-- | src/include/storage/lmgr.h | 1 |
3 files changed, 27 insertions, 1 deletions
diff --git a/src/backend/storage/ipc/standby.c b/src/backend/storage/ipc/standby.c index fdec0eb2250..e1a9fbb7262 100644 --- a/src/backend/storage/ipc/standby.c +++ b/src/backend/storage/ipc/standby.c @@ -81,7 +81,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; @@ -97,11 +97,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 859b3852dbd..f49222e69d9 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 bd44d92be3c..23cb5aee46f 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); |