1
0
mirror of https://github.com/postgres/postgres.git synced 2025-04-29 13:56:47 +03:00

Change the misleading local end_lsn for prepared transactions.

The apply worker was using XactLastCommitEnd as local end_lsn for applying
prepare and rollback_prepare. The XactLastCommitEnd value is the end lsn
of the last commit applied before the prepare transaction which makes no
sense. This LSN is used to decide whether we can send the acknowledgment
of the corresponding remote LSN to the server.

It is okay not to set the local_end LSN with the actual WAL position 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.

The current code is misleading but as such doesn't create any problem, so
decided not to backpatch.

Author: Hayato Kuroda
Reviewed-by: Shveta Malik, Amit Kapila
Discussion: https://postgr.es/m/TYAPR01MB5692FA4926754B91E9D7B5F0F5AA2@TYAPR01MB5692.jpnprd01.prod.outlook.com
This commit is contained in:
Amit Kapila 2024-08-09 10:23:57 +05:30
parent 4eb179e5bf
commit 701cf1e317

View File

@ -1133,7 +1133,17 @@ apply_handle_prepare(StringInfo s)
CommitTransactionCommand(); CommitTransactionCommand();
pgstat_report_stat(false); 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; in_remote_transaction = false;
@ -1251,7 +1261,12 @@ apply_handle_rollback_prepared(StringInfo s)
pgstat_report_stat(false); 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; in_remote_transaction = false;
/* Process any tables that are being synchronized in parallel. */ /* Process any tables that are being synchronized in parallel. */
@ -1306,7 +1321,11 @@ apply_handle_stream_prepare(StringInfo s)
CommitTransactionCommand(); 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; in_remote_transaction = false;
@ -1364,7 +1383,11 @@ apply_handle_stream_prepare(StringInfo s)
CommitTransactionCommand(); 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_set_xact_state(MyParallelShared, PARALLEL_TRANS_FINISHED);
pa_unlock_transaction(MyParallelShared->xid, AccessExclusiveLock); pa_unlock_transaction(MyParallelShared->xid, AccessExclusiveLock);