mirror of
https://github.com/postgres/postgres.git
synced 2025-07-21 16:02:15 +03:00
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.
This commit is contained in:
@ -82,7 +82,7 @@ InitRecoveryTransactionEnvironment(void)
|
|||||||
* hold AccessShareLocks so never block while we write or lock new rows.
|
* hold AccessShareLocks so never block while we write or lock new rows.
|
||||||
*/
|
*/
|
||||||
vxid.backendId = MyBackendId;
|
vxid.backendId = MyBackendId;
|
||||||
vxid.localTransactionId = GetNextLocalTransactionId();
|
vxid.localTransactionId = MyProc->lxid = GetNextLocalTransactionId();
|
||||||
VirtualXactLockTableInsert(vxid);
|
VirtualXactLockTableInsert(vxid);
|
||||||
|
|
||||||
standbyState = STANDBY_INITIALIZED;
|
standbyState = STANDBY_INITIALIZED;
|
||||||
@ -98,11 +98,18 @@ InitRecoveryTransactionEnvironment(void)
|
|||||||
void
|
void
|
||||||
ShutdownRecoveryTransactionEnvironment(void)
|
ShutdownRecoveryTransactionEnvironment(void)
|
||||||
{
|
{
|
||||||
|
VirtualTransactionId vxid;
|
||||||
|
|
||||||
/* Mark all tracked in-progress transactions as finished. */
|
/* Mark all tracked in-progress transactions as finished. */
|
||||||
ExpireAllKnownAssignedTransactionIds();
|
ExpireAllKnownAssignedTransactionIds();
|
||||||
|
|
||||||
/* Release all locks the tracked transactions were holding */
|
/* Release all locks the tracked transactions were holding */
|
||||||
StandbyReleaseAllLocks();
|
StandbyReleaseAllLocks();
|
||||||
|
|
||||||
|
/* Cleanup our VirtualTransaction */
|
||||||
|
vxid.backendId = MyBackendId;
|
||||||
|
vxid.localTransactionId = MyProc->lxid;
|
||||||
|
VirtualXactLockTableDelete(vxid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -534,6 +534,24 @@ VirtualXactLockTableInsert(VirtualTransactionId vxid)
|
|||||||
(void) LockAcquire(&tag, ExclusiveLock, false, false);
|
(void) LockAcquire(&tag, ExclusiveLock, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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
|
* VirtualXactLockTableWait
|
||||||
*
|
*
|
||||||
|
@ -58,6 +58,7 @@ extern bool ConditionalXactLockTableWait(TransactionId xid);
|
|||||||
|
|
||||||
/* Lock a VXID (used to wait for a transaction to finish) */
|
/* Lock a VXID (used to wait for a transaction to finish) */
|
||||||
extern void VirtualXactLockTableInsert(VirtualTransactionId vxid);
|
extern void VirtualXactLockTableInsert(VirtualTransactionId vxid);
|
||||||
|
extern void VirtualXactLockTableDelete(VirtualTransactionId vxid);
|
||||||
extern void VirtualXactLockTableWait(VirtualTransactionId vxid);
|
extern void VirtualXactLockTableWait(VirtualTransactionId vxid);
|
||||||
extern bool ConditionalVirtualXactLockTableWait(VirtualTransactionId vxid);
|
extern bool ConditionalVirtualXactLockTableWait(VirtualTransactionId vxid);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user