@@ -192,9 +192,9 @@ static bool twophaseExitRegistered = false;
192
192
*
193
193
* Replay of twophase records happens by the following rules:
194
194
** On PREPARE redo KnownPreparedAdd() is called to add that transaction to
195
- * KnownPreparedList and no more actions taken.
196
- ** On checkpoint we iterate through KnownPreparedList, move all prepare
197
- * records that behind redo_horizon tofile and deletingitems from list.
195
+ * KnownPreparedList and no more actionsare taken.
196
+ ** On checkpointredo we iterate through KnownPreparedList and move all prepare
197
+ * records that behind redo_horizon tofiles and deletingthem from list.
198
198
** On COMMIT/ABORT we delete file or entry in KnownPreparedList.
199
199
** At the end of recovery we move all known prepared transactions to disk
200
200
* to allow RecoverPreparedTransactions/StandbyRecoverPreparedTransactions
@@ -1270,9 +1270,9 @@ ReadTwoPhaseFile(TransactionId xid, bool give_warnings)
1270
1270
* Reads 2PC data from xlog. During checkpoint this data will be moved to
1271
1271
* twophase files and ReadTwoPhaseFile should be used instead.
1272
1272
*
1273
- * Note clearly that this functionaccesses WAL during normal operation, similarly
1274
- * to the way WALSender or Logical Decoding would do. It does not run during
1275
- * crash recovery or standby processing.
1273
+ * Note clearly that this functioncan access WAL during normal operation, similarly
1274
+ * to the way WALSender or Logical Decoding would do.
1275
+ *
1276
1276
*/
1277
1277
static void
1278
1278
XlogReadTwoPhaseData (XLogRecPtr lsn ,char * * buf ,int * len )
@@ -1281,8 +1281,6 @@ XlogReadTwoPhaseData(XLogRecPtr lsn, char **buf, int *len)
1281
1281
XLogReaderState * xlogreader ;
1282
1282
char * errormsg ;
1283
1283
1284
- // Assert(!RecoveryInProgress());
1285
-
1286
1284
xlogreader = XLogReaderAllocate (& read_local_xlog_page ,NULL );
1287
1285
if (!xlogreader )
1288
1286
ereport (ERROR ,
@@ -1682,27 +1680,6 @@ CheckPointTwoPhase(XLogRecPtr redo_horizon)
1682
1680
serialized_xacts )));
1683
1681
}
1684
1682
1685
- /*
1686
- * KnownPreparedAdd.
1687
- *
1688
- * Store correspondence of start/end lsn and xid in KnownPreparedList.
1689
- * This is called during redo of prepare record to have list of prepared
1690
- * transactions that aren't yet moved to 2PC files by the end of recovery.
1691
- */
1692
- void
1693
- KnownPreparedAdd (XLogReaderState * record )
1694
- {
1695
- KnownPreparedXact * xact ;
1696
- TwoPhaseFileHeader * hdr = (TwoPhaseFileHeader * )XLogRecGetData (record );
1697
-
1698
- xact = (KnownPreparedXact * )palloc (sizeof (KnownPreparedXact ));
1699
- xact -> xid = hdr -> xid ;
1700
- xact -> prepare_start_lsn = record -> ReadRecPtr ;
1701
- xact -> prepare_end_lsn = record -> EndRecPtr ;
1702
-
1703
- dlist_push_tail (& KnownPreparedList ,& xact -> list_node );
1704
- }
1705
-
1706
1683
/*
1707
1684
* PrescanPreparedTransactions
1708
1685
*
@@ -1741,6 +1718,13 @@ PrescanPreparedTransactions(TransactionId **xids_p, int *nxids_p)
1741
1718
int nxids = 0 ;
1742
1719
int allocsize = 0 ;
1743
1720
1721
+ /*
1722
+ * Move prepared transactions from KnownPreparedList to files, if any.
1723
+ * It is possible to skip that step and teach subsequent code about
1724
+ * KnownPreparedList, but whole PrescanPreparedTransactions() happens
1725
+ * once during end of recovery or promote, so probably it isn't worth
1726
+ * complications.
1727
+ */
1744
1728
KnownPreparedRecreateFiles (InvalidXLogRecPtr );
1745
1729
1746
1730
cldir = AllocateDir (TWOPHASE_DIR );
@@ -2215,10 +2199,33 @@ RecordTransactionAbortPrepared(TransactionId xid,
2215
2199
SyncRepWaitForLSN (recptr , false);
2216
2200
}
2217
2201
2202
+ /*
2203
+ * KnownPreparedAdd.
2204
+ *
2205
+ * Store correspondence of start/end lsn and xid in KnownPreparedList.
2206
+ * This is called during redo of prepare record to have list of prepared
2207
+ * transactions that aren't yet moved to 2PC files by the end of recovery.
2208
+ */
2209
+ void
2210
+ KnownPreparedAdd (XLogReaderState * record )
2211
+ {
2212
+ KnownPreparedXact * xact ;
2213
+ TwoPhaseFileHeader * hdr = (TwoPhaseFileHeader * )XLogRecGetData (record );
2214
+
2215
+ Assert (RecoveryInProgress ());
2216
+
2217
+ xact = (KnownPreparedXact * )palloc (sizeof (KnownPreparedXact ));
2218
+ xact -> xid = hdr -> xid ;
2219
+ xact -> prepare_start_lsn = record -> ReadRecPtr ;
2220
+ xact -> prepare_end_lsn = record -> EndRecPtr ;
2221
+
2222
+ dlist_push_tail (& KnownPreparedList ,& xact -> list_node );
2223
+ }
2224
+
2218
2225
/*
2219
2226
* KnownPreparedRemoveByXid
2220
2227
*
2221
- * Forget about prepared transaction. Calleddurind commit/abort.
2228
+ * Forget about prepared transaction. Calledduring commit/abort redo .
2222
2229
*/
2223
2230
void
2224
2231
KnownPreparedRemoveByXid (TransactionId xid )
@@ -2254,7 +2261,7 @@ KnownPreparedRemoveByXid(TransactionId xid)
2254
2261
/*
2255
2262
* KnownPreparedRecreateFiles
2256
2263
*
2257
- * Moves prepare records from WAL to files.Callend during checkpoint replay
2264
+ * Moves prepare records from WAL to files.Called during checkpoint replay
2258
2265
* or PrescanPreparedTransactions.
2259
2266
*
2260
2267
* redo_horizon = InvalidXLogRecPtr indicates that all transactions from