Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitabfb296

Browse files
Rename RBTXN_PREPARE to RBTXN_IS_PREPARE for better clarification.
RBTXN_PREPARE flag and rbtxn_prepared macro could be misinterpreted aseither indicating the transaction type (e.g. a prepared transaction ora normal transaction) or its currentstate (e.g. skipped or its preparemessage is sent), especially after commit072ee84 introduced theRBTXN_SENT_PREPARE flag and the rbtxn_sent_prepare macro.The RBTXN_PREPARE flag (and its corresponding macro) have been renamedto RBTXN_IS_PREPARE to explicitly indicate the transactiontype. Therefore, this commit also adds the RBTXN_IS_PREPARE flag tothe transaction that is a prepared transaction and has been skipped,which previously had only the RBTXN_SKIPPED_PREPARE flag.Reviewed-by: Amit Kapila, Peter SmithDiscussion:https://postgr.es/m/CAA4eK1KgNmBsG%3D155E7QQ6TX9RoWnM4z5Z20SvsbwxSe_QXYsg%40mail.gmail.com
1 parent072ee84 commitabfb296

File tree

4 files changed

+38
-24
lines changed

4 files changed

+38
-24
lines changed

‎src/backend/replication/logical/proto.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ logicalrep_write_prepare_common(StringInfo out, LogicalRepMsgType type,
164164
* which case we expect to have a valid GID.
165165
*/
166166
Assert(txn->gid!=NULL);
167-
Assert(rbtxn_prepared(txn));
167+
Assert(rbtxn_is_prepared(txn));
168168
Assert(TransactionIdIsValid(txn->xid));
169169

170170
/* send the flags field */

‎src/backend/replication/logical/reorderbuffer.c

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*/
28582859
bool
28592860
ReorderBufferRememberPrepareInfo(ReorderBuffer*rb,TransactionIdxid,
@@ -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
/*

‎src/backend/replication/logical/snapbuild.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ SnapBuildDistributeNewCatalogSnapshot(SnapBuild *builder, XLogRecPtr lsn)
761761
* We don't need to add snapshot to prepared transactions as they
762762
* should not see the new catalog contents.
763763
*/
764-
if (rbtxn_prepared(txn)||rbtxn_skip_prepared(txn))
764+
if (rbtxn_is_prepared(txn))
765765
continue;
766766

767767
elog(DEBUG2,"adding a new snapshot to %u at %X/%X",

‎src/include/replication/reorderbuffer.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,15 @@ typedef struct ReorderBufferChange
170170
#defineRBTXN_IS_SERIALIZED_CLEAR 0x0008
171171
#defineRBTXN_IS_STREAMED 0x0010
172172
#defineRBTXN_HAS_PARTIAL_CHANGE 0x0020
173-
#defineRBTXN_PREPARE0x0040
173+
#defineRBTXN_IS_PREPARED0x0040
174174
#defineRBTXN_SKIPPED_PREPARE 0x0080
175175
#defineRBTXN_HAS_STREAMABLE_CHANGE0x0100
176176
#defineRBTXN_SENT_PREPARE0x0200
177177
#defineRBTXN_IS_COMMITTED0x0400
178178
#defineRBTXN_IS_ABORTED0x0800
179179

180+
#defineRBTXN_PREPARE_STATUS_MASK(RBTXN_IS_PREPARED | RBTXN_SKIPPED_PREPARE | RBTXN_SENT_PREPARE)
181+
180182
/* Does the transaction have catalog changes? */
181183
#definerbtxn_has_catalog_changes(txn) \
182184
( \
@@ -234,9 +236,9 @@ typedef struct ReorderBufferChange
234236
* committed. To check whether a prepare or a stream_prepare has already
235237
* been sent for this transaction, we need to use rbtxn_sent_prepare().
236238
*/
237-
#definerbtxn_prepared(txn) \
239+
#definerbtxn_is_prepared(txn) \
238240
( \
239-
((txn)->txn_flags &RBTXN_PREPARE) != 0 \
241+
((txn)->txn_flags &RBTXN_IS_PREPARED) != 0 \
240242
)
241243

242244
/* Has a prepare or stream_prepare already been sent? */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp