@@ -1793,7 +1793,7 @@ ReorderBufferCheckAndTruncateAbortedTXN(ReorderBuffer *rb, ReorderBufferTXN *txn
17931793 * and the toast reconstruction data. The full cleanup will happen as part
17941794 * of decoding ABORT record of this transaction.
17951795 */
1796- ReorderBufferTruncateTXN (rb , txn , rbtxn_prepared (txn ));
1796+ ReorderBufferTruncateTXN (rb , txn , rbtxn_is_prepared (txn ));
17971797 ReorderBufferToastReset (rb , txn );
17981798
17991799 /* All changes should be discarded */
@@ -1968,7 +1968,7 @@ ReorderBufferStreamCommit(ReorderBuffer *rb, ReorderBufferTXN *txn)
19681968
19691969 ReorderBufferStreamTXN (rb , txn );
19701970
1971- if (rbtxn_prepared (txn ))
1971+ if (rbtxn_is_prepared (txn ))
19721972 {
19731973 /*
19741974 * Note, we send stream prepare even if a concurrent abort is
@@ -2150,7 +2150,7 @@ ReorderBufferResetTXN(ReorderBuffer *rb, ReorderBufferTXN *txn,
21502150 ReorderBufferChange * specinsert )
21512151{
21522152 /* Discard the changes that we just streamed */
2153- ReorderBufferTruncateTXN (rb , txn , rbtxn_prepared (txn ));
2153+ ReorderBufferTruncateTXN (rb , txn , rbtxn_is_prepared (txn ));
21542154
21552155 /* Free all resources allocated for toast reconstruction */
21562156 ReorderBufferToastReset (rb , txn );
@@ -2238,7 +2238,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn,
22382238 */
22392239 if (!streaming )
22402240 {
2241- if (rbtxn_prepared (txn ))
2241+ if (rbtxn_is_prepared (txn ))
22422242 rb -> begin_prepare (rb , txn );
22432243 else
22442244 rb -> begin (rb , txn );
@@ -2280,7 +2280,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn,
22802280 * required for the cases when we decode the changes before the
22812281 * COMMIT record is processed.
22822282 */
2283- if (streaming || rbtxn_prepared (change -> txn ))
2283+ if (streaming || rbtxn_is_prepared (change -> txn ))
22842284 {
22852285 curtxn = change -> txn ;
22862286 SetupCheckXidLive (curtxn -> xid );
@@ -2625,7 +2625,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn,
26252625 * Call either PREPARE (for two-phase transactions) or COMMIT (for
26262626 * regular ones).
26272627 */
2628- if (rbtxn_prepared (txn ))
2628+ if (rbtxn_is_prepared (txn ))
26292629 {
26302630 Assert (!rbtxn_sent_prepare (txn ));
26312631 rb -> prepare (rb , txn , commit_lsn );
@@ -2680,12 +2680,12 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn,
26802680 * For 4, as the entire txn has been decoded, we can fully clean up
26812681 * the TXN reorder buffer.
26822682 */
2683- if (streaming || rbtxn_prepared (txn ))
2683+ if (streaming || rbtxn_is_prepared (txn ))
26842684 {
26852685 if (streaming )
26862686 ReorderBufferMaybeMarkTXNStreamed (rb , txn );
26872687
2688- ReorderBufferTruncateTXN (rb , txn , rbtxn_prepared (txn ));
2688+ ReorderBufferTruncateTXN (rb , txn , rbtxn_is_prepared (txn ));
26892689 /* Reset the CheckXidAlive */
26902690 CheckXidAlive = InvalidTransactionId ;
26912691 }
@@ -2729,7 +2729,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn,
27292729 * during a two-phase commit.
27302730 */
27312731 if (errdata -> sqlerrcode == ERRCODE_TRANSACTION_ROLLBACK &&
2732- (stream_started || rbtxn_prepared (txn )))
2732+ (stream_started || rbtxn_is_prepared (txn )))
27332733 {
27342734 /* curtxn must be set for streaming or prepared transactions */
27352735 Assert (curtxn );
@@ -2816,7 +2816,7 @@ ReorderBufferReplay(ReorderBufferTXN *txn,
28162816 * Removing this txn before a commit might result in the computation
28172817 * of an incorrect restart_lsn. See SnapBuildProcessRunningXacts.
28182818 */
2819- if (!rbtxn_prepared (txn ))
2819+ if (!rbtxn_is_prepared (txn ))
28202820 ReorderBufferCleanupTXN (rb , txn );
28212821 return ;
28222822 }
@@ -2853,7 +2853,8 @@ ReorderBufferCommit(ReorderBuffer *rb, TransactionId xid,
28532853}
28542854
28552855/*
2856- * Record the prepare information for a transaction.
2856+ * Record the prepare information for a transaction. Also, mark the transaction
2857+ * as a prepared transaction.
28572858 */
28582859bool
28592860ReorderBufferRememberPrepareInfo (ReorderBuffer * rb , TransactionId xid ,
@@ -2879,6 +2880,10 @@ ReorderBufferRememberPrepareInfo(ReorderBuffer *rb, TransactionId xid,
28792880 txn -> origin_id = origin_id ;
28802881 txn -> origin_lsn = origin_lsn ;
28812882
2883+ /* Mark this transaction as a prepared transaction */
2884+ Assert ((txn -> txn_flags & RBTXN_PREPARE_STATUS_MASK ) == 0 );
2885+ txn -> txn_flags |= RBTXN_IS_PREPARED ;
2886+
28822887 return true;
28832888}
28842889
@@ -2894,6 +2899,8 @@ ReorderBufferSkipPrepare(ReorderBuffer *rb, TransactionId xid)
28942899 if (txn == NULL )
28952900 return ;
28962901
2902+ /* txn must have been marked as a prepared transaction */
2903+ Assert ((txn -> txn_flags & RBTXN_PREPARE_STATUS_MASK ) == RBTXN_IS_PREPARED );
28972904 txn -> txn_flags |= RBTXN_SKIPPED_PREPARE ;
28982905}
28992906
@@ -2915,12 +2922,16 @@ ReorderBufferPrepare(ReorderBuffer *rb, TransactionId xid,
29152922 if (txn == NULL )
29162923 return ;
29172924
2918- txn -> txn_flags |= RBTXN_PREPARE ;
2919- txn -> gid = pstrdup (gid );
2920-
2921- /* The prepare info must have been updated in txn by now. */
2925+ /*
2926+ * txn must have been marked as a prepared transaction and must have
2927+ * neither been skipped nor sent a prepare. Also, the prepare info must
2928+ * have been updated in it by now.
2929+ */
2930+ Assert ((txn -> txn_flags & RBTXN_PREPARE_STATUS_MASK ) == RBTXN_IS_PREPARED );
29222931 Assert (txn -> final_lsn != InvalidXLogRecPtr );
29232932
2933+ txn -> gid = pstrdup (gid );
2934+
29242935 ReorderBufferReplay (txn , rb , xid , txn -> final_lsn , txn -> end_lsn ,
29252936 txn -> xact_time .prepare_time , txn -> origin_id , txn -> origin_lsn );
29262937
@@ -2976,12 +2987,13 @@ ReorderBufferFinishPrepared(ReorderBuffer *rb, TransactionId xid,
29762987 */
29772988 if ((txn -> final_lsn < two_phase_at ) && is_commit )
29782989 {
2979- txn -> txn_flags |= RBTXN_PREPARE ;
2980-
29812990 /*
2982- * The prepare info must have been updated in txn even if we skip
2983- * prepare.
2991+ * txn must have been marked as a prepared transaction and skipped but
2992+ * not sent a prepare. Also, the prepare info must have been updated
2993+ * in txn even if we skip prepare.
29842994 */
2995+ Assert ((txn -> txn_flags & RBTXN_PREPARE_STATUS_MASK ) ==
2996+ (RBTXN_IS_PREPARED | RBTXN_SKIPPED_PREPARE ));
29852997 Assert (txn -> final_lsn != InvalidXLogRecPtr );
29862998
29872999 /*
0 commit comments