diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c index 6dc54c72838..245e9be6f27 100644 --- a/src/backend/replication/logical/worker.c +++ b/src/backend/replication/logical/worker.c @@ -1133,7 +1133,17 @@ apply_handle_prepare(StringInfo s) CommitTransactionCommand(); pgstat_report_stat(false); - store_flush_position(prepare_data.end_lsn, XactLastCommitEnd); + /* + * It is okay not to set the local_end LSN for the prepare because we + * always flush the prepare record. So, we can send the acknowledgment of + * the remote_end LSN as soon as prepare is finished. + * + * XXX For the sake of consistency with commit, we could have set it with + * the LSN of prepare but as of now we don't track that value similar to + * XactLastCommitEnd, and adding it for this purpose doesn't seems worth + * it. + */ + store_flush_position(prepare_data.end_lsn, InvalidXLogRecPtr); in_remote_transaction = false; @@ -1251,7 +1261,12 @@ apply_handle_rollback_prepared(StringInfo s) pgstat_report_stat(false); - store_flush_position(rollback_data.rollback_end_lsn, XactLastCommitEnd); + /* + * It is okay not to set the local_end LSN for the rollback of prepared + * transaction because we always flush the WAL record for it. See + * apply_handle_prepare. + */ + store_flush_position(rollback_data.rollback_end_lsn, InvalidXLogRecPtr); in_remote_transaction = false; /* Process any tables that are being synchronized in parallel. */ @@ -1306,7 +1321,11 @@ apply_handle_stream_prepare(StringInfo s) CommitTransactionCommand(); - store_flush_position(prepare_data.end_lsn, XactLastCommitEnd); + /* + * It is okay not to set the local_end LSN for the prepare because + * we always flush the prepare record. See apply_handle_prepare. + */ + store_flush_position(prepare_data.end_lsn, InvalidXLogRecPtr); in_remote_transaction = false; @@ -1364,7 +1383,11 @@ apply_handle_stream_prepare(StringInfo s) CommitTransactionCommand(); - MyParallelShared->last_commit_end = XactLastCommitEnd; + /* + * It is okay not to set the local_end LSN for the prepare because + * we always flush the prepare record. See apply_handle_prepare. + */ + MyParallelShared->last_commit_end = InvalidXLogRecPtr; pa_set_xact_state(MyParallelShared, PARALLEL_TRANS_FINISHED); pa_unlock_transaction(MyParallelShared->xid, AccessExclusiveLock);