Skip to content

Commit f68c49f

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 2d03daa commit f68c49f

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
@@ -1617,8 +1617,8 @@ ReorderBufferAbortOld(ReorderBuffer *rb, TransactionId oldestRunningXid)
16171617
* Iterate through all (potential) toplevel TXNs and abort all that are
16181618
* older than what possibly can be running. Once we've found the first
16191619
* that is alive we stop, there might be some that acquired an xid earlier
1620-
* but started writing later, but it's unlikely and they will cleaned up
1621-
* in a later call to ReorderBufferAbortOld().
1620+
* but started writing later, but it's unlikely and they will be cleaned
1621+
* up in a later call to this function.
16221622
*/
16231623
dlist_foreach_modify(it, &rb->toplevel_by_lsn)
16241624
{
@@ -1628,6 +1628,21 @@ ReorderBufferAbortOld(ReorderBuffer *rb, TransactionId oldestRunningXid)
16281628

16291629
if (TransactionIdPrecedes(txn->xid, oldestRunningXid))
16301630
{
1631+
/*
1632+
* We set final_lsn on a transaction when we decode its commit or
1633+
* abort record, but we never see those records for crashed
1634+
* transactions. To ensure cleanup of these transactions, set
1635+
* final_lsn to that of their last change; this causes
1636+
* ReorderBufferRestoreCleanup to do the right thing.
1637+
*/
1638+
if (txn->serialized && txn->final_lsn == 0)
1639+
{
1640+
ReorderBufferChange *last =
1641+
dlist_tail_element(ReorderBufferChange, node, &txn->changes);
1642+
1643+
txn->final_lsn = last->lsn;
1644+
}
1645+
16311646
elog(DEBUG2, "aborting old transaction %u", txn->xid);
16321647

16331648
/* 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
@@ -153,6 +153,8 @@ typedef struct ReorderBufferTXN
153153
* * plain abort record
154154
* * prepared transaction abort
155155
* * error during decoding
156+
* * for a crashed transaction, the LSN of the last change, regardless of
157+
* what it was.
156158
* ----
157159
*/
158160
XLogRecPtr final_lsn;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy