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

Commit4df581f

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 parent906356c commit4df581f

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
@@ -514,7 +514,7 @@ DecodeLogicalMsgOp(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
514514
TransactionIdxid=XLogRecGetXid(r);
515515
uint8info=XLogRecGetInfo(r)& ~XLR_INFO_MASK;
516516
RepOriginIdorigin_id=XLogRecGetOrigin(r);
517-
Snapshotsnapshot;
517+
Snapshotsnapshot=NULL;
518518
xl_logical_message*message;
519519

520520
if (info!=XLOG_LOGICAL_MESSAGE)
@@ -544,7 +544,17 @@ DecodeLogicalMsgOp(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
544544
SnapBuildXactNeedsSkip(builder,buf->origptr)))
545545
return;
546546

547-
snapshot=SnapBuildGetOrBuildSnapshot(builder,xid);
547+
/*
548+
* If this is a non-transactional change, get the snapshot we're expected
549+
* to use. We only get here when the snapshot is consistent, and the
550+
* change is not meant to be skipped.
551+
*
552+
* For transactional changes we don't need a snapshot, we'll use the
553+
* regular snapshot maintained by ReorderBuffer. We just leave it NULL.
554+
*/
555+
if (!message->transactional)
556+
snapshot=SnapBuildGetOrBuildSnapshot(builder,xid);
557+
548558
ReorderBufferQueueMessage(ctx->reorder,xid,snapshot,buf->endptr,
549559
message->transactional,
550560
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
@@ -672,6 +672,13 @@ ReorderBufferQueueMessage(ReorderBuffer *rb, TransactionId xid,
672672

673673
Assert(xid!=InvalidTransactionId);
674674

675+
/*
676+
* We don't expect snapshots for transactional changes - we'll use the
677+
* snapshot derived later during apply (unless the change gets
678+
* skipped).
679+
*/
680+
Assert(!snapshot);
681+
675682
oldcontext=MemoryContextSwitchTo(rb->context);
676683

677684
change=ReorderBufferGetChange(rb);
@@ -690,6 +697,9 @@ ReorderBufferQueueMessage(ReorderBuffer *rb, TransactionId xid,
690697
ReorderBufferTXN*txn=NULL;
691698
volatileSnapshotsnapshot_now=snapshot;
692699

700+
/* Non-transactional changes require a valid snapshot. */
701+
Assert(snapshot_now);
702+
693703
if (xid!=InvalidTransactionId)
694704
txn=ReorderBufferTXNByXid(rb,xid, true,NULL,lsn, true);
695705

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp