Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Correctly init/deinit recovery xact environment.
authorSimon Riggs <simon@2ndQuadrant.com>
Thu, 29 Nov 2012 23:52:17 +0000 (23:52 +0000)
committerSimon Riggs <simon@2ndQuadrant.com>
Thu, 29 Nov 2012 23:52:17 +0000 (23:52 +0000)
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.

src/backend/storage/ipc/standby.c
src/backend/storage/lmgr/lmgr.c
src/include/storage/lmgr.h

index fdec0eb22505a9b61f1bcecd20ef14526086cc6d..e1a9fbb7262ed7d1dcb2a13c65a85d16b2b9fb3a 100644 (file)
@@ -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);
 }
 
 
index 859b3852dbd112dcddb776bf1e44f64613027e4a..f49222e69d994d4ad204fff744c5b6c37292f55b 100644 (file)
@@ -534,6 +534,24 @@ VirtualXactLockTableInsert(VirtualTransactionId vxid)
    (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
  *
index bd44d92be3c07db32923f0d4b5901c3477fee9de..23cb5aee46fca85a5d4acc0917f03db4acfcf535 100644 (file)
@@ -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);