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

Commitfe955eb

Browse files
committed
Set ReorderBufferTXN->final_lsn more eagerly
... specifically, set it incrementally as each individual change isspilled down to disk. This way, it is set correctly when thetransaction disappears without trace, ie. without leaving an XACT_ABORTwal record. (This happens when the server crashes midway through atransaction.)Failing to have final_lsn prevents ReorderBufferRestoreCleanup() fromworking, since it needs the final_lsn in order to know the endpoint ofits iteration through spilled files.Commitdf9f682 already tried to fix the problem, but it didn't setthe final_lsn in all cases. Revert that, since it's no longer needed.Author: Vignesh CReviewed-by: Amit Kapila, Dilip KumarDiscussion:https://postgr.es/m/CALDaNm2CLk+K9JDwjYST0sPbGg5AQdvhUt0jbKyX_HdAE0jk3A@mail.gmail.com
1 parent8c37e44 commitfe955eb

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

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

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1908,21 +1908,6 @@ ReorderBufferAbortOld(ReorderBuffer *rb, TransactionId oldestRunningXid)
19081908

19091909
if (TransactionIdPrecedes(txn->xid,oldestRunningXid))
19101910
{
1911-
/*
1912-
* We set final_lsn on a transaction when we decode its commit or
1913-
* abort record, but we never see those records for crashed
1914-
* transactions. To ensure cleanup of these transactions, set
1915-
* final_lsn to that of their last change; this causes
1916-
* ReorderBufferRestoreCleanup to do the right thing.
1917-
*/
1918-
if (txn->serialized&&txn->final_lsn==0)
1919-
{
1920-
ReorderBufferChange*last=
1921-
dlist_tail_element(ReorderBufferChange,node,&txn->changes);
1922-
1923-
txn->final_lsn=last->lsn;
1924-
}
1925-
19261911
elog(DEBUG2,"aborting old transaction %u",txn->xid);
19271912

19281913
/* remove potential on-disk data, and deallocate this tx */
@@ -2445,8 +2430,7 @@ ReorderBufferSerializeChange(ReorderBuffer *rb, ReorderBufferTXN *txn,
24452430

24462431
sz+=sizeof(SnapshotData)+
24472432
sizeof(TransactionId)*snap->xcnt+
2448-
sizeof(TransactionId)*snap->subxcnt
2449-
;
2433+
sizeof(TransactionId)*snap->subxcnt;
24502434

24512435
/* make sure we have enough space */
24522436
ReorderBufferSerializeReserve(rb,sz);
@@ -2519,6 +2503,17 @@ ReorderBufferSerializeChange(ReorderBuffer *rb, ReorderBufferTXN *txn,
25192503
}
25202504
pgstat_report_wait_end();
25212505

2506+
/*
2507+
* Keep the transaction's final_lsn up to date with each change we send to
2508+
* disk, so that ReorderBufferRestoreCleanup works correctly. (We used to
2509+
* only do this on commit and abort records, but that doesn't work if a
2510+
* system crash leaves a transaction without its abort record).
2511+
*
2512+
* Make sure not to move it backwards.
2513+
*/
2514+
if (txn->final_lsn<change->lsn)
2515+
txn->final_lsn=change->lsn;
2516+
25222517
Assert(ondisk->change.action==change->action);
25232518
}
25242519

‎src/include/replication/reorderbuffer.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,10 @@ typedef struct ReorderBufferTXN
179179
* * prepared transaction commit
180180
* * plain abort record
181181
* * prepared transaction abort
182-
* * error during decoding
183-
* * for a crashed transaction, the LSN of the last change, regardless of
184-
* what it was.
182+
*
183+
* This can also become set to earlier values than transaction end when
184+
* a transaction is spilled to disk; specifically it's set to the LSN of
185+
* the latest change written to disk so far.
185186
* ----
186187
*/
187188
XLogRecPtrfinal_lsn;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp