Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a19c262

Browse files
committed
Fix failure to delete spill files of aborted transactions
Logical decoding's reorderbuffer.c may spill transaction files to disk when transactions are large. These are supposed to be removed when they become "too old" by xid; but file removal requires the boundary LSNs of the transaction to be known. The final_lsn is only set when we see the commit or abort record for the transaction, but nothing sets the value for transactions that crash, so the removal code misbehaves -- in assertion-enabled builds, it crashes by a failed assertion. To fix, modify the final_lsn of transactions that don't have a value set, to the LSN of the very latest change in the transaction. This causes the spilled files to be removed appropriately. Author: Atsushi Torikoshi Reviewed-by: Kyotaro HORIGUCHI, Craig Ringer, Masahiko Sawada Discussion: https://postgr.es/m/54e4e488-186b-a056-6628-50628e4e4ebc@lab.ntt.co.jp
1 parent 0dc5dfc commit a19c262

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/backend/replication/logical/reorderbuffer.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,8 +1713,8 @@ ReorderBufferAbortOld(ReorderBuffer *rb, TransactionId oldestRunningXid)
17131713
* Iterate through all (potential) toplevel TXNs and abort all that are
17141714
* older than what possibly can be running. Once we've found the first
17151715
* that is alive we stop, there might be some that acquired an xid earlier
1716-
* but started writing later, but it's unlikely and they will cleaned up
1717-
* in a later call to ReorderBufferAbortOld().
1716+
* but started writing later, but it's unlikely and they will be cleaned
1717+
* up in a later call to this function.
17181718
*/
17191719
dlist_foreach_modify(it, &rb->toplevel_by_lsn)
17201720
{
@@ -1724,6 +1724,21 @@ ReorderBufferAbortOld(ReorderBuffer *rb, TransactionId oldestRunningXid)
17241724

17251725
if (TransactionIdPrecedes(txn->xid, oldestRunningXid))
17261726
{
1727+
/*
1728+
* We set final_lsn on a transaction when we decode its commit or
1729+
* abort record, but we never see those records for crashed
1730+
* transactions. To ensure cleanup of these transactions, set
1731+
* final_lsn to that of their last change; this causes
1732+
* ReorderBufferRestoreCleanup to do the right thing.
1733+
*/
1734+
if (txn->serialized && txn->final_lsn == 0)
1735+
{
1736+
ReorderBufferChange *last =
1737+
dlist_tail_element(ReorderBufferChange, node, &txn->changes);
1738+
1739+
txn->final_lsn = last->lsn;
1740+
}
1741+
17271742
elog(DEBUG2, "aborting old transaction %u", txn->xid);
17281743

17291744
/* remove potential on-disk data, and deallocate this tx */

src/include/replication/reorderbuffer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ typedef struct ReorderBufferTXN
168168
* * plain abort record
169169
* * prepared transaction abort
170170
* * error during decoding
171+
* * for a crashed transaction, the LSN of the last change, regardless of
172+
* what it was.
171173
* ----
172174
*/
173175
XLogRecPtr final_lsn;

0 commit comments

Comments
 (0)