On Sat, Feb 27, 2021 at 8:10 PM Peter Smith <smithpb2...@gmail.com> wrote: > > Please find attached the latest patch set v45* > > Differences from v44*: > > * Rebased to HEAD > > * Addressed some feedback comments for the 0007 ("empty prepare") patch. > > [ak1] #1 - TODO > [ak1] #2 - Fixed. Removed #if 0 debugging > [ak1] #3 - TODO > [ak1] #4 - Fixed. Now BEGIN_PREPARE and PREPARE msgs are spooled. The > lsns are obtained from them. >
@@ -774,6 +891,38 @@ apply_handle_prepare(StringInfo s) { LogicalRepPreparedTxnData prepare_data; + /* + * If we were using a psf spoolfile, then write the PREPARE as the final + * message. This prepare information will be used at commit_prepared time. + */ + if (psf_fd) + { + /* Write the PREPARE info to the psf file. */ + Assert(prepare_spoolfile_handler(LOGICAL_REP_MSG_PREPARE, s)); Why writing prepare is under Assert? Similarly, the commit_prepared code as below still does prepare: + /* + * 2. mark as PREPARED (use prepare_data info from the psf file) + */ + + /* + * BeginTransactionBlock is necessary to balance the + * EndTransactionBlock called within the PrepareTransactionBlock + * below. + */ + BeginTransactionBlock(); + CommitTransactionCommand(); + + /* + * Update origin state so we can restart streaming from correct + * position in case of crash. + */ + replorigin_session_origin_lsn = pdata.end_lsn; + replorigin_session_origin_timestamp = pdata.preparetime; + + PrepareTransactionBlock(pdata.gid); + CommitTransactionCommand(); + pgstat_report_stat(false); + + store_flush_position(pdata.end_lsn); This should automatically happen via apply_handle_prepare if we write it to spool file. * prepare_spoolfile_replay_messages() shouldn't handle special cases for BEGIN_PREPARE and PREPARE messages. Those should be handled by there corresponding apply_handle_* functions. Before processing the messages remote_final_lsn needs to be set as commit_prepared's commit_lsn (aka prepare_data.prepare_lsn) -- With Regards, Amit Kapila.