mirror of
https://github.com/postgres/postgres.git
synced 2025-07-31 22:04:40 +03:00
Correct logical decoding restore behaviour for subtransactions.
Before initializing iteration over a subtransaction's changes, the last few changes were not spilled to disk. That's correct if the transaction didn't spill to disk, but otherwise... This bug can lead to missed or misorderd subtransaction contents when they were spilled to disk. Move spilling of the remaining in-memory changes to ReorderBufferIterTXNInit(), where it can easily be applied to the top transaction and, if present, subtransactions. Since this code had too many bugs already, noticeably increase test coverage. Fixes: #14319 Reported-By: Huan Ruan Discussion: <20160909012610.20024.58169@wrigleys.postgresql.org> Backport: 9,4-, where logical decoding was added
This commit is contained in:
@ -935,8 +935,12 @@ ReorderBufferIterTXNInit(ReorderBuffer *rb, ReorderBufferTXN *txn)
|
||||
ReorderBufferChange *cur_change;
|
||||
|
||||
if (txn->nentries != txn->nentries_mem)
|
||||
{
|
||||
/* serialize remaining changes */
|
||||
ReorderBufferSerializeTXN(rb, txn);
|
||||
ReorderBufferRestoreChanges(rb, txn, &state->entries[off].fd,
|
||||
&state->entries[off].segno);
|
||||
}
|
||||
|
||||
cur_change = dlist_head_element(ReorderBufferChange, node,
|
||||
&txn->changes);
|
||||
@ -960,10 +964,13 @@ ReorderBufferIterTXNInit(ReorderBuffer *rb, ReorderBufferTXN *txn)
|
||||
ReorderBufferChange *cur_change;
|
||||
|
||||
if (cur_txn->nentries != cur_txn->nentries_mem)
|
||||
{
|
||||
/* serialize remaining changes */
|
||||
ReorderBufferSerializeTXN(rb, cur_txn);
|
||||
ReorderBufferRestoreChanges(rb, cur_txn,
|
||||
&state->entries[off].fd,
|
||||
&state->entries[off].segno);
|
||||
|
||||
}
|
||||
cur_change = dlist_head_element(ReorderBufferChange, node,
|
||||
&cur_txn->changes);
|
||||
|
||||
@ -1367,10 +1374,6 @@ ReorderBufferCommit(ReorderBuffer *rb, TransactionId xid,
|
||||
txn->origin_id = origin_id;
|
||||
txn->origin_lsn = origin_lsn;
|
||||
|
||||
/* serialize the last bunch of changes if we need start earlier anyway */
|
||||
if (txn->nentries_mem != txn->nentries)
|
||||
ReorderBufferSerializeTXN(rb, txn);
|
||||
|
||||
/*
|
||||
* If this transaction didn't have any real changes in our database, it's
|
||||
* OK not to have a snapshot. Note that ReorderBufferCommitChild will have
|
||||
|
Reference in New Issue
Block a user