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

Commit8b9cbd4

Browse files
committed
Fix snapshot handling in logicalmsg_decode
Whe decoding a transactional logical message, logicalmsg_decode calledSnapBuildGetOrBuildSnapshot. But we may not have a consistent snapshotyet at that point. We don't actually need the snapshot in this case(during replay we'll have the snapshot from the transaction), so inpractice this is harmless. But in assert-enabled build this crashes.Fixed by requesting the snapshot only in non-transactional case, wherewe are guaranteed to have SNAPBUILD_CONSISTENT.Backpatch to 11. The issue exists since 9.6.Backpatch-through: 11Reviewed-by: Andres FreundDiscussion:https://postgr.es/m/84d60912-6eab-9b84-5de3-41765a5449e8@enterprisedb.com
1 parent482ab3e commit8b9cbd4

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ DecodeLogicalMsgOp(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
628628
TransactionIdxid=XLogRecGetXid(r);
629629
uint8info=XLogRecGetInfo(r)& ~XLR_INFO_MASK;
630630
RepOriginIdorigin_id=XLogRecGetOrigin(r);
631-
Snapshotsnapshot;
631+
Snapshotsnapshot=NULL;
632632
xl_logical_message*message;
633633

634634
if (info!=XLOG_LOGICAL_MESSAGE)
@@ -658,7 +658,17 @@ DecodeLogicalMsgOp(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
658658
SnapBuildXactNeedsSkip(builder,buf->origptr)))
659659
return;
660660

661-
snapshot=SnapBuildGetOrBuildSnapshot(builder,xid);
661+
/*
662+
* If this is a non-transactional change, get the snapshot we're expected
663+
* to use. We only get here when the snapshot is consistent, and the
664+
* change is not meant to be skipped.
665+
*
666+
* For transactional changes we don't need a snapshot, we'll use the
667+
* regular snapshot maintained by ReorderBuffer. We just leave it NULL.
668+
*/
669+
if (!message->transactional)
670+
snapshot=SnapBuildGetOrBuildSnapshot(builder,xid);
671+
662672
ReorderBufferQueueMessage(ctx->reorder,xid,snapshot,buf->endptr,
663673
message->transactional,
664674
message->message,/* first part of message is

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,13 @@ ReorderBufferQueueMessage(ReorderBuffer *rb, TransactionId xid,
821821

822822
Assert(xid!=InvalidTransactionId);
823823

824+
/*
825+
* We don't expect snapshots for transactional changes - we'll use the
826+
* snapshot derived later during apply (unless the change gets
827+
* skipped).
828+
*/
829+
Assert(!snapshot);
830+
824831
oldcontext=MemoryContextSwitchTo(rb->context);
825832

826833
change=ReorderBufferGetChange(rb);
@@ -839,6 +846,9 @@ ReorderBufferQueueMessage(ReorderBuffer *rb, TransactionId xid,
839846
ReorderBufferTXN*txn=NULL;
840847
volatileSnapshotsnapshot_now=snapshot;
841848

849+
/* Non-transactional changes require a valid snapshot. */
850+
Assert(snapshot_now);
851+
842852
if (xid!=InvalidTransactionId)
843853
txn=ReorderBufferTXNByXid(rb,xid, true,NULL,lsn, true);
844854

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp