@@ -1793,7 +1793,7 @@ ReorderBufferCheckAndTruncateAbortedTXN(ReorderBuffer *rb, ReorderBufferTXN *txn
1793
1793
* and the toast reconstruction data. The full cleanup will happen as part
1794
1794
* of decoding ABORT record of this transaction.
1795
1795
*/
1796
- ReorderBufferTruncateTXN (rb , txn , rbtxn_prepared (txn ));
1796
+ ReorderBufferTruncateTXN (rb , txn , rbtxn_is_prepared (txn ));
1797
1797
ReorderBufferToastReset (rb , txn );
1798
1798
1799
1799
/* All changes should be discarded */
@@ -1968,7 +1968,7 @@ ReorderBufferStreamCommit(ReorderBuffer *rb, ReorderBufferTXN *txn)
1968
1968
1969
1969
ReorderBufferStreamTXN (rb , txn );
1970
1970
1971
- if (rbtxn_prepared (txn ))
1971
+ if (rbtxn_is_prepared (txn ))
1972
1972
{
1973
1973
/*
1974
1974
* Note, we send stream prepare even if a concurrent abort is
@@ -2150,7 +2150,7 @@ ReorderBufferResetTXN(ReorderBuffer *rb, ReorderBufferTXN *txn,
2150
2150
ReorderBufferChange * specinsert )
2151
2151
{
2152
2152
/* Discard the changes that we just streamed */
2153
- ReorderBufferTruncateTXN (rb , txn , rbtxn_prepared (txn ));
2153
+ ReorderBufferTruncateTXN (rb , txn , rbtxn_is_prepared (txn ));
2154
2154
2155
2155
/* Free all resources allocated for toast reconstruction */
2156
2156
ReorderBufferToastReset (rb , txn );
@@ -2238,7 +2238,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn,
2238
2238
*/
2239
2239
if (!streaming )
2240
2240
{
2241
- if (rbtxn_prepared (txn ))
2241
+ if (rbtxn_is_prepared (txn ))
2242
2242
rb -> begin_prepare (rb , txn );
2243
2243
else
2244
2244
rb -> begin (rb , txn );
@@ -2280,7 +2280,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn,
2280
2280
* required for the cases when we decode the changes before the
2281
2281
* COMMIT record is processed.
2282
2282
*/
2283
- if (streaming || rbtxn_prepared (change -> txn ))
2283
+ if (streaming || rbtxn_is_prepared (change -> txn ))
2284
2284
{
2285
2285
curtxn = change -> txn ;
2286
2286
SetupCheckXidLive (curtxn -> xid );
@@ -2625,7 +2625,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn,
2625
2625
* Call either PREPARE (for two-phase transactions) or COMMIT (for
2626
2626
* regular ones).
2627
2627
*/
2628
- if (rbtxn_prepared (txn ))
2628
+ if (rbtxn_is_prepared (txn ))
2629
2629
{
2630
2630
Assert (!rbtxn_sent_prepare (txn ));
2631
2631
rb -> prepare (rb , txn , commit_lsn );
@@ -2680,12 +2680,12 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn,
2680
2680
* For 4, as the entire txn has been decoded, we can fully clean up
2681
2681
* the TXN reorder buffer.
2682
2682
*/
2683
- if (streaming || rbtxn_prepared (txn ))
2683
+ if (streaming || rbtxn_is_prepared (txn ))
2684
2684
{
2685
2685
if (streaming )
2686
2686
ReorderBufferMaybeMarkTXNStreamed (rb , txn );
2687
2687
2688
- ReorderBufferTruncateTXN (rb , txn , rbtxn_prepared (txn ));
2688
+ ReorderBufferTruncateTXN (rb , txn , rbtxn_is_prepared (txn ));
2689
2689
/* Reset the CheckXidAlive */
2690
2690
CheckXidAlive = InvalidTransactionId ;
2691
2691
}
@@ -2729,7 +2729,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn,
2729
2729
* during a two-phase commit.
2730
2730
*/
2731
2731
if (errdata -> sqlerrcode == ERRCODE_TRANSACTION_ROLLBACK &&
2732
- (stream_started || rbtxn_prepared (txn )))
2732
+ (stream_started || rbtxn_is_prepared (txn )))
2733
2733
{
2734
2734
/* curtxn must be set for streaming or prepared transactions */
2735
2735
Assert (curtxn );
@@ -2816,7 +2816,7 @@ ReorderBufferReplay(ReorderBufferTXN *txn,
2816
2816
* Removing this txn before a commit might result in the computation
2817
2817
* of an incorrect restart_lsn. See SnapBuildProcessRunningXacts.
2818
2818
*/
2819
- if (!rbtxn_prepared (txn ))
2819
+ if (!rbtxn_is_prepared (txn ))
2820
2820
ReorderBufferCleanupTXN (rb , txn );
2821
2821
return ;
2822
2822
}
@@ -2853,7 +2853,8 @@ ReorderBufferCommit(ReorderBuffer *rb, TransactionId xid,
2853
2853
}
2854
2854
2855
2855
/*
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.
2857
2858
*/
2858
2859
bool
2859
2860
ReorderBufferRememberPrepareInfo (ReorderBuffer * rb , TransactionId xid ,
@@ -2879,6 +2880,10 @@ ReorderBufferRememberPrepareInfo(ReorderBuffer *rb, TransactionId xid,
2879
2880
txn -> origin_id = origin_id ;
2880
2881
txn -> origin_lsn = origin_lsn ;
2881
2882
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
+
2882
2887
return true;
2883
2888
}
2884
2889
@@ -2894,6 +2899,8 @@ ReorderBufferSkipPrepare(ReorderBuffer *rb, TransactionId xid)
2894
2899
if (txn == NULL )
2895
2900
return ;
2896
2901
2902
+ /* txn must have been marked as a prepared transaction */
2903
+ Assert ((txn -> txn_flags & RBTXN_PREPARE_STATUS_MASK ) == RBTXN_IS_PREPARED );
2897
2904
txn -> txn_flags |= RBTXN_SKIPPED_PREPARE ;
2898
2905
}
2899
2906
@@ -2915,12 +2922,16 @@ ReorderBufferPrepare(ReorderBuffer *rb, TransactionId xid,
2915
2922
if (txn == NULL )
2916
2923
return ;
2917
2924
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 );
2922
2931
Assert (txn -> final_lsn != InvalidXLogRecPtr );
2923
2932
2933
+ txn -> gid = pstrdup (gid );
2934
+
2924
2935
ReorderBufferReplay (txn , rb , xid , txn -> final_lsn , txn -> end_lsn ,
2925
2936
txn -> xact_time .prepare_time , txn -> origin_id , txn -> origin_lsn );
2926
2937
@@ -2976,12 +2987,13 @@ ReorderBufferFinishPrepared(ReorderBuffer *rb, TransactionId xid,
2976
2987
*/
2977
2988
if ((txn -> final_lsn < two_phase_at ) && is_commit )
2978
2989
{
2979
- txn -> txn_flags |= RBTXN_PREPARE ;
2980
-
2981
2990
/*
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.
2984
2994
*/
2995
+ Assert ((txn -> txn_flags & RBTXN_PREPARE_STATUS_MASK ) ==
2996
+ (RBTXN_IS_PREPARED | RBTXN_SKIPPED_PREPARE ));
2985
2997
Assert (txn -> final_lsn != InvalidXLogRecPtr );
2986
2998
2987
2999
/*
0 commit comments