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

Commit20a1dc1

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 parent9be6fcb commit20a1dc1

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

17951795
if (TransactionIdPrecedes(txn->xid,oldestRunningXid))
17961796
{
1797-
/*
1798-
* We set final_lsn on a transaction when we decode its commit or
1799-
* abort record, but we never see those records for crashed
1800-
* transactions. To ensure cleanup of these transactions, set
1801-
* final_lsn to that of their last change; this causes
1802-
* ReorderBufferRestoreCleanup to do the right thing.
1803-
*/
1804-
if (txn->serialized&&txn->final_lsn==0)
1805-
{
1806-
ReorderBufferChange*last=
1807-
dlist_tail_element(ReorderBufferChange,node,&txn->changes);
1808-
1809-
txn->final_lsn=last->lsn;
1810-
}
1811-
18121797
elog(DEBUG2,"aborting old transaction %u",txn->xid);
18131798

18141799
/* remove potential on-disk data, and deallocate this tx */
@@ -2288,8 +2273,7 @@ ReorderBufferSerializeChange(ReorderBuffer *rb, ReorderBufferTXN *txn,
22882273

22892274
sz+=sizeof(SnapshotData)+
22902275
sizeof(TransactionId)*snap->xcnt+
2291-
sizeof(TransactionId)*snap->subxcnt
2292-
;
2276+
sizeof(TransactionId)*snap->subxcnt;
22932277

22942278
/* make sure we have enough space */
22952279
ReorderBufferSerializeReserve(rb,sz);
@@ -2340,6 +2324,17 @@ ReorderBufferSerializeChange(ReorderBuffer *rb, ReorderBufferTXN *txn,
23402324
txn->xid)));
23412325
}
23422326

2327+
/*
2328+
* Keep the transaction's final_lsn up to date with each change we send to
2329+
* disk, so that ReorderBufferRestoreCleanup works correctly. (We used to
2330+
* only do this on commit and abort records, but that doesn't work if a
2331+
* system crash leaves a transaction without its abort record).
2332+
*
2333+
* Make sure not to move it backwards.
2334+
*/
2335+
if (txn->final_lsn<change->lsn)
2336+
txn->final_lsn=change->lsn;
2337+
23432338
Assert(ondisk->change.action==change->action);
23442339
}
23452340

‎src/include/replication/reorderbuffer.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,10 @@ typedef struct ReorderBufferTXN
151151
* * prepared transaction commit
152152
* * plain abort record
153153
* * prepared transaction abort
154-
* * error during decoding
155-
* * for a crashed transaction, the LSN of the last change, regardless of
156-
* what it was.
154+
*
155+
* This can also become set to earlier values than transaction end when
156+
* a transaction is spilled to disk; specifically it's set to the LSN of
157+
* the latest change written to disk so far.
157158
* ----
158159
*/
159160
XLogRecPtrfinal_lsn;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp