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

Commitbc21406

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 parent162c951 commitbc21406

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
@@ -1916,21 +1916,6 @@ ReorderBufferAbortOld(ReorderBuffer *rb, TransactionId oldestRunningXid)
19161916

19171917
if (TransactionIdPrecedes(txn->xid,oldestRunningXid))
19181918
{
1919-
/*
1920-
* We set final_lsn on a transaction when we decode its commit or
1921-
* abort record, but we never see those records for crashed
1922-
* transactions. To ensure cleanup of these transactions, set
1923-
* final_lsn to that of their last change; this causes
1924-
* ReorderBufferRestoreCleanup to do the right thing.
1925-
*/
1926-
if (txn->serialized&&txn->final_lsn==0)
1927-
{
1928-
ReorderBufferChange*last=
1929-
dlist_tail_element(ReorderBufferChange,node,&txn->changes);
1930-
1931-
txn->final_lsn=last->lsn;
1932-
}
1933-
19341919
elog(DEBUG2,"aborting old transaction %u",txn->xid);
19351920

19361921
/* remove potential on-disk data, and deallocate this tx */
@@ -2453,8 +2438,7 @@ ReorderBufferSerializeChange(ReorderBuffer *rb, ReorderBufferTXN *txn,
24532438

24542439
sz+=sizeof(SnapshotData)+
24552440
sizeof(TransactionId)*snap->xcnt+
2456-
sizeof(TransactionId)*snap->subxcnt
2457-
;
2441+
sizeof(TransactionId)*snap->subxcnt;
24582442

24592443
/* make sure we have enough space */
24602444
ReorderBufferSerializeReserve(rb,sz);
@@ -2527,6 +2511,17 @@ ReorderBufferSerializeChange(ReorderBuffer *rb, ReorderBufferTXN *txn,
25272511
}
25282512
pgstat_report_wait_end();
25292513

2514+
/*
2515+
* Keep the transaction's final_lsn up to date with each change we send to
2516+
* disk, so that ReorderBufferRestoreCleanup works correctly. (We used to
2517+
* only do this on commit and abort records, but that doesn't work if a
2518+
* system crash leaves a transaction without its abort record).
2519+
*
2520+
* Make sure not to move it backwards.
2521+
*/
2522+
if (txn->final_lsn<change->lsn)
2523+
txn->final_lsn=change->lsn;
2524+
25302525
Assert(ondisk->change.action==change->action);
25312526
}
25322527

‎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