@@ -303,8 +303,7 @@ static void RemoveGXact(GlobalTransaction gxact);
303303static void XlogReadTwoPhaseData (XLogRecPtr lsn , char * * buf , int * len );
304304static char * ProcessTwoPhaseBuffer (TransactionId xid ,
305305 XLogRecPtr prepare_start_lsn ,
306- bool fromdisk , bool overwriteOK , bool setParent ,
307- bool setNextXid );
306+ bool fromdisk , bool setParent , bool setNextXid );
308307static void MarkAsPreparingGuts (GlobalTransaction gxact , TransactionId xid ,
309308 const char * gid , TimestampTz prepared_at , Oid owner ,
310309 Oid databaseid );
@@ -1930,8 +1929,7 @@ restoreTwoPhaseData(void)
19301929 xid = (TransactionId ) strtoul (clde -> d_name , NULL , 16 );
19311930
19321931 buf = ProcessTwoPhaseBuffer (xid , InvalidXLogRecPtr ,
1933- true, false, false,
1934- false);
1932+ true, false, false);
19351933 if (buf == NULL )
19361934 continue ;
19371935
@@ -1992,8 +1990,7 @@ PrescanPreparedTransactions(TransactionId **xids_p, int *nxids_p)
19921990
19931991 buf = ProcessTwoPhaseBuffer (xid ,
19941992 gxact -> prepare_start_lsn ,
1995- gxact -> ondisk , false, false,
1996- true);
1993+ gxact -> ondisk , false, true);
19971994
19981995 if (buf == NULL )
19991996 continue ;
@@ -2046,12 +2043,12 @@ PrescanPreparedTransactions(TransactionId **xids_p, int *nxids_p)
20462043 * This is never called at the end of recovery - we use
20472044 * RecoverPreparedTransactions() at that point.
20482045 *
2049- * Currently we simply call SubTransSetParent() for any subxids of prepared
2050- * transactions. If overwriteOK is true, it's OK if some XIDs have already
2051- * been marked in pg_subtrans .
2046+ * The lack of calls to SubTransSetParent() calls here is by design;
2047+ * those calls are made by RecoverPreparedTransactions() at the end of recovery
2048+ * for those xacts that need this .
20522049 */
20532050void
2054- StandbyRecoverPreparedTransactions (bool overwriteOK )
2051+ StandbyRecoverPreparedTransactions (void )
20552052{
20562053 int i ;
20572054
@@ -2068,8 +2065,7 @@ StandbyRecoverPreparedTransactions(bool overwriteOK)
20682065
20692066 buf = ProcessTwoPhaseBuffer (xid ,
20702067 gxact -> prepare_start_lsn ,
2071- gxact -> ondisk , overwriteOK , true,
2072- false);
2068+ gxact -> ondisk , false, false);
20732069 if (buf != NULL )
20742070 pfree (buf );
20752071 }
@@ -2082,8 +2078,7 @@ StandbyRecoverPreparedTransactions(bool overwriteOK)
20822078 * Scan the shared memory entries of TwoPhaseState and reload the state for
20832079 * each prepared transaction (reacquire locks, etc).
20842080 *
2085- * This is run at the end of recovery, but before we allow backends to write
2086- * WAL.
2081+ * This is run during database startup.
20872082 *
20882083 * At the end of recovery the way we take snapshots will change. We now need
20892084 * to mark all running transactions with their full SubTransSetParent() info
@@ -2107,15 +2102,21 @@ RecoverPreparedTransactions(void)
21072102 TwoPhaseFileHeader * hdr ;
21082103 TransactionId * subxids ;
21092104 const char * gid ;
2110- bool overwriteOK = false;
2111- int i ;
21122105
21132106 xid = gxact -> xid ;
21142107
2108+ /*
2109+ * Reconstruct subtrans state for the transaction --- needed
2110+ * because pg_subtrans is not preserved over a restart. Note that
2111+ * we are linking all the subtransactions directly to the
2112+ * top-level XID; there may originally have been a more complex
2113+ * hierarchy, but there's no need to restore that exactly.
2114+ * It's possible that SubTransSetParent has been set before, if
2115+ * the prepared transaction generated xid assignment records.
2116+ */
21152117 buf = ProcessTwoPhaseBuffer (xid ,
21162118 gxact -> prepare_start_lsn ,
2117- gxact -> ondisk , false, false,
2118- false);
2119+ gxact -> ondisk , true, false);
21192120 if (buf == NULL )
21202121 continue ;
21212122
@@ -2133,25 +2134,6 @@ RecoverPreparedTransactions(void)
21332134 bufptr += MAXALIGN (hdr -> nabortrels * sizeof (RelFileNode ));
21342135 bufptr += MAXALIGN (hdr -> ninvalmsgs * sizeof (SharedInvalidationMessage ));
21352136
2136- /*
2137- * It's possible that SubTransSetParent has been set before, if
2138- * the prepared transaction generated xid assignment records. Test
2139- * here must match one used in AssignTransactionId().
2140- */
2141- if (InHotStandby && (hdr -> nsubxacts >= PGPROC_MAX_CACHED_SUBXIDS ||
2142- XLogLogicalInfoActive ()))
2143- overwriteOK = true;
2144-
2145- /*
2146- * Reconstruct subtrans state for the transaction --- needed
2147- * because pg_subtrans is not preserved over a restart. Note that
2148- * we are linking all the subtransactions directly to the
2149- * top-level XID; there may originally have been a more complex
2150- * hierarchy, but there's no need to restore that exactly.
2151- */
2152- for (i = 0 ; i < hdr -> nsubxacts ; i ++ )
2153- SubTransSetParent (subxids [i ], xid , true);
2154-
21552137 /*
21562138 * Recreate its GXACT and dummy PGPROC. But, check whether
21572139 * it was added in redo and already has a shmem entry for
@@ -2203,16 +2185,15 @@ RecoverPreparedTransactions(void)
22032185 * Given a transaction id, read it either from disk or read it directly
22042186 * via shmem xlog record pointer using the provided "prepare_start_lsn".
22052187 *
2206- * If setParent is true, then use the overwriteOK parameter to set up
2207- * subtransaction parent linkages.
2188+ * If setParent is true, set up subtransaction parent linkages.
22082189 *
22092190 * If setNextXid is true, set ShmemVariableCache->nextXid to the newest
22102191 * value scanned.
22112192 */
22122193static char *
22132194ProcessTwoPhaseBuffer (TransactionId xid ,
22142195 XLogRecPtr prepare_start_lsn ,
2215- bool fromdisk , bool overwriteOK ,
2196+ bool fromdisk ,
22162197 bool setParent , bool setNextXid )
22172198{
22182199 TransactionId origNextXid = ShmemVariableCache -> nextXid ;
@@ -2341,7 +2322,7 @@ ProcessTwoPhaseBuffer(TransactionId xid,
23412322 }
23422323
23432324 if (setParent )
2344- SubTransSetParent (subxid , xid , overwriteOK );
2325+ SubTransSetParent (subxid , xid );
23452326 }
23462327
23472328 return buf ;
0 commit comments