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

Commitfe7337f

Browse files
committed
Fix off-by-one in decoding causing one-record events to be skipped.
A ReorderBufferTransaction's end_lsn, the sentPtr advocated bywalsender keepalive messages, and the end location remembered by thedecoding get_*changes* SQL functions all use the location of the lastread record + 1. I.e. the LSN points to the beginning of the nextrecord. That cannot realistically be changed without changing thereplication protocol because that's how keepalive messages have workedsince 9.0.The bug is that the logic inside the snapshot builder, which decideswhether a transaction's contents should be decoded, assumed the startlocation would point towards the last byte of the last record. Thereason this didn't actually cause visible problems is that currentlythat decision is only made for commit records. Since interestingtransactions always have at least one additional record - containingactual data - we'd never skip a transaction.But if there ever were transactions, or other events, with just onerecord containing important information, we'd skip them after stoppingand restarting logical decoding.
1 parent5f93c37 commitfe7337f

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,11 @@ struct SnapBuild
153153
TransactionIdxmax;
154154

155155
/*
156-
* Don't replay commits from an LSN <= this LSN. This can be set
156+
* Don't replay commits from an LSN < this LSN. This can be set
157157
* externally but it will also be advanced (never retreat) from within
158158
* snapbuild.c.
159159
*/
160-
XLogRecPtrtransactions_after;
160+
XLogRecPtrstart_decoding_at;
161161

162162
/*
163163
* Don't start decoding WAL until the "xl_running_xacts" information
@@ -309,7 +309,7 @@ AllocateSnapshotBuilder(ReorderBuffer *reorder,
309309
builder->committed.includes_all_transactions= true;
310310

311311
builder->initial_xmin_horizon=xmin_horizon;
312-
builder->transactions_after=start_lsn;
312+
builder->start_decoding_at=start_lsn;
313313

314314
MemoryContextSwitchTo(oldcontext);
315315

@@ -375,7 +375,7 @@ SnapBuildCurrentState(SnapBuild *builder)
375375
bool
376376
SnapBuildXactNeedsSkip(SnapBuild*builder,XLogRecPtrptr)
377377
{
378-
returnptr <=builder->transactions_after;
378+
returnptr<builder->start_decoding_at;
379379
}
380380

381381
/*
@@ -955,8 +955,8 @@ SnapBuildCommitTxn(SnapBuild *builder, XLogRecPtr lsn, TransactionId xid,
955955
if (builder->state<SNAPBUILD_CONSISTENT)
956956
{
957957
/* ensure that only commits after this are getting replayed */
958-
if (builder->transactions_after<lsn)
959-
builder->transactions_after=lsn;
958+
if (builder->start_decoding_at <=lsn)
959+
builder->start_decoding_at=lsn+1;
960960

961961
/*
962962
* We could avoid treating !SnapBuildTxnIsRunning transactions as
@@ -1243,9 +1243,10 @@ SnapBuildFindSnapshot(SnapBuild *builder, XLogRecPtr lsn, xl_running_xacts *runn
12431243
*/
12441244
if (running->xcnt==0)
12451245
{
1246-
if (builder->transactions_after==InvalidXLogRecPtr||
1247-
builder->transactions_after<lsn)
1248-
builder->transactions_after=lsn;
1246+
if (builder->start_decoding_at==InvalidXLogRecPtr||
1247+
builder->start_decoding_at <=lsn)
1248+
/* can decode everything after this */
1249+
builder->start_decoding_at=lsn+1;
12491250

12501251
builder->xmin=running->oldestRunningXid;
12511252
builder->xmax=running->latestCompletedXid;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp