Skip to content

Commit 9189353

Browse files
committed
clean snapshot
1 parent f04783a commit 9189353

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

src/backend/replication/logical/decode.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ DecodePrepare(LogicalDecodingContext *ctx, XLogRecordBuffer *buf,
663663
ReorderBufferXidSetCatalogChanges(ctx->reorder, xid, buf->origptr);
664664
}
665665

666-
SnapBuildCommitTxn(ctx->snapshot_builder, buf->origptr, xid,
666+
SnapBuildPrepareTxnStart(ctx->snapshot_builder, buf->origptr, xid,
667667
parsed->nsubxacts, parsed->subxacts);
668668

669669
if (SnapBuildXactNeedsSkip(ctx->snapshot_builder, buf->origptr) ||
@@ -689,6 +689,8 @@ DecodePrepare(LogicalDecodingContext *ctx, XLogRecordBuffer *buf,
689689
/* replay actions of all transaction + subtransactions in order */
690690
ReorderBufferPrepare(ctx->reorder, xid, buf->origptr, buf->endptr,
691691
commit_time, origin_id, origin_lsn, parsed->twophase_gid);
692+
693+
SnapBuildPrepareTxnFinish(ctx->snapshot_builder, xid);
692694
}
693695

694696
/*

src/backend/replication/logical/snapbuild.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ SnapBuildPurgeCommittedTxn(SnapBuild *builder)
868868
/* copy xids that still are interesting to workspace */
869869
for (off = 0; off < builder->committed.xcnt; off++)
870870
{
871-
if (NormalTransactionIdPrecedes(builder->committed.xip[off],
871+
if (TransactionIdPrecedes(builder->committed.xip[off],
872872
builder->xmin))
873873
; /* remove */
874874
else
@@ -1101,6 +1101,29 @@ SnapBuildCommitTxn(SnapBuild *builder, XLogRecPtr lsn, TransactionId xid,
11011101
}
11021102
}
11031103

1104+
void
1105+
SnapBuildPrepareTxnStart(SnapBuild *builder, XLogRecPtr lsn, TransactionId xid,
1106+
int nsubxacts, TransactionId *subxacts)
1107+
{
1108+
SnapBuildCommitTxn(builder, lsn, xid, nsubxacts, subxacts);
1109+
}
1110+
1111+
void
1112+
SnapBuildPrepareTxnFinish(SnapBuild *builder, TransactionId xid)
1113+
{
1114+
TransactionId *search = bsearch(&xid, builder->running.xip,
1115+
builder->running.xcnt_space, sizeof(TransactionId), xidComparator);
1116+
1117+
if (search == NULL)
1118+
return;
1119+
1120+
/* delete that xid */
1121+
memmove(search, search + 1,
1122+
((builder->running.xip + builder->running.xcnt - 1) - search) * sizeof(TransactionId));
1123+
builder->running.xcnt--;
1124+
builder->running.xmin = builder->running.xip[0];
1125+
builder->running.xmax = builder->running.xip[builder->running.xcnt - 1];
1126+
}
11041127

11051128
/* -----------------------------------
11061129
* Snapshot building functions dealing with xlog records

src/include/replication/snapbuild.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ extern bool SnapBuildXactNeedsSkip(SnapBuild *snapstate, XLogRecPtr ptr);
7171
extern void SnapBuildCommitTxn(SnapBuild *builder, XLogRecPtr lsn,
7272
TransactionId xid, int nsubxacts,
7373
TransactionId *subxacts);
74+
extern void SnapBuildPrepareTxnStart(SnapBuild *builder, XLogRecPtr lsn,
75+
TransactionId xid, int nsubxacts,
76+
TransactionId *subxacts);
77+
extern void SnapBuildPrepareTxnFinish(SnapBuild *builder, TransactionId xid);
7478
extern void SnapBuildAbortTxn(SnapBuild *builder, XLogRecPtr lsn,
7579
TransactionId xid, int nsubxacts,
7680
TransactionId *subxacts);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy