@@ -303,8 +303,7 @@ static void RemoveGXact(GlobalTransaction gxact);
303
303
static void XlogReadTwoPhaseData (XLogRecPtr lsn , char * * buf , int * len );
304
304
static char * ProcessTwoPhaseBuffer (TransactionId xid ,
305
305
XLogRecPtr prepare_start_lsn ,
306
- bool fromdisk , bool overwriteOK , bool setParent ,
307
- bool setNextXid );
306
+ bool fromdisk , bool setParent , bool setNextXid );
308
307
static void MarkAsPreparingGuts (GlobalTransaction gxact , TransactionId xid ,
309
308
const char * gid , TimestampTz prepared_at , Oid owner ,
310
309
Oid databaseid );
@@ -1930,8 +1929,7 @@ restoreTwoPhaseData(void)
1930
1929
xid = (TransactionId ) strtoul (clde -> d_name , NULL , 16 );
1931
1930
1932
1931
buf = ProcessTwoPhaseBuffer (xid , InvalidXLogRecPtr ,
1933
- true, false, false,
1934
- false);
1932
+ true, false, false);
1935
1933
if (buf == NULL )
1936
1934
continue ;
1937
1935
@@ -1992,8 +1990,7 @@ PrescanPreparedTransactions(TransactionId **xids_p, int *nxids_p)
1992
1990
1993
1991
buf = ProcessTwoPhaseBuffer (xid ,
1994
1992
gxact -> prepare_start_lsn ,
1995
- gxact -> ondisk , false, false,
1996
- true);
1993
+ gxact -> ondisk , false, true);
1997
1994
1998
1995
if (buf == NULL )
1999
1996
continue ;
@@ -2046,12 +2043,12 @@ PrescanPreparedTransactions(TransactionId **xids_p, int *nxids_p)
2046
2043
* This is never called at the end of recovery - we use
2047
2044
* RecoverPreparedTransactions() at that point.
2048
2045
*
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 .
2052
2049
*/
2053
2050
void
2054
- StandbyRecoverPreparedTransactions (bool overwriteOK )
2051
+ StandbyRecoverPreparedTransactions (void )
2055
2052
{
2056
2053
int i ;
2057
2054
@@ -2068,8 +2065,7 @@ StandbyRecoverPreparedTransactions(bool overwriteOK)
2068
2065
2069
2066
buf = ProcessTwoPhaseBuffer (xid ,
2070
2067
gxact -> prepare_start_lsn ,
2071
- gxact -> ondisk , overwriteOK , true,
2072
- false);
2068
+ gxact -> ondisk , false, false);
2073
2069
if (buf != NULL )
2074
2070
pfree (buf );
2075
2071
}
@@ -2082,8 +2078,7 @@ StandbyRecoverPreparedTransactions(bool overwriteOK)
2082
2078
* Scan the shared memory entries of TwoPhaseState and reload the state for
2083
2079
* each prepared transaction (reacquire locks, etc).
2084
2080
*
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.
2087
2082
*
2088
2083
* At the end of recovery the way we take snapshots will change. We now need
2089
2084
* to mark all running transactions with their full SubTransSetParent() info
@@ -2107,15 +2102,21 @@ RecoverPreparedTransactions(void)
2107
2102
TwoPhaseFileHeader * hdr ;
2108
2103
TransactionId * subxids ;
2109
2104
const char * gid ;
2110
- bool overwriteOK = false;
2111
- int i ;
2112
2105
2113
2106
xid = gxact -> xid ;
2114
2107
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
+ */
2115
2117
buf = ProcessTwoPhaseBuffer (xid ,
2116
2118
gxact -> prepare_start_lsn ,
2117
- gxact -> ondisk , false, false,
2118
- false);
2119
+ gxact -> ondisk , true, false);
2119
2120
if (buf == NULL )
2120
2121
continue ;
2121
2122
@@ -2133,25 +2134,6 @@ RecoverPreparedTransactions(void)
2133
2134
bufptr += MAXALIGN (hdr -> nabortrels * sizeof (RelFileNode ));
2134
2135
bufptr += MAXALIGN (hdr -> ninvalmsgs * sizeof (SharedInvalidationMessage ));
2135
2136
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
-
2155
2137
/*
2156
2138
* Recreate its GXACT and dummy PGPROC. But, check whether
2157
2139
* it was added in redo and already has a shmem entry for
@@ -2203,16 +2185,15 @@ RecoverPreparedTransactions(void)
2203
2185
* Given a transaction id, read it either from disk or read it directly
2204
2186
* via shmem xlog record pointer using the provided "prepare_start_lsn".
2205
2187
*
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.
2208
2189
*
2209
2190
* If setNextXid is true, set ShmemVariableCache->nextXid to the newest
2210
2191
* value scanned.
2211
2192
*/
2212
2193
static char *
2213
2194
ProcessTwoPhaseBuffer (TransactionId xid ,
2214
2195
XLogRecPtr prepare_start_lsn ,
2215
- bool fromdisk , bool overwriteOK ,
2196
+ bool fromdisk ,
2216
2197
bool setParent , bool setNextXid )
2217
2198
{
2218
2199
TransactionId origNextXid = ShmemVariableCache -> nextXid ;
@@ -2341,7 +2322,7 @@ ProcessTwoPhaseBuffer(TransactionId xid,
2341
2322
}
2342
2323
2343
2324
if (setParent )
2344
- SubTransSetParent (subxid , xid , overwriteOK );
2325
+ SubTransSetParent (subxid , xid );
2345
2326
}
2346
2327
2347
2328
return buf ;
0 commit comments