summaryrefslogtreecommitdiff
path: root/src/backend/replication/logical/reorderbuffer.c
diff options
context:
space:
mode:
authorAndres Freund <andres@anarazel.de>2016-10-03 22:11:36 -0700
committerAndres Freund <andres@anarazel.de>2016-10-03 22:14:12 -0700
commit07172b20f1a0c4e3a24b0b8f6781de4d2c4866cb (patch)
tree59205d90aaf4b31fdee61989aba2da8ce5535e0c /src/backend/replication/logical/reorderbuffer.c
parent475866f08725a01aac91417fc67b725b2511f435 (diff)
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
Diffstat (limited to 'src/backend/replication/logical/reorderbuffer.c')
-rw-r--r--src/backend/replication/logical/reorderbuffer.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index 3b63e21dbd0..11d1907b57d 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -872,8 +872,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);
@@ -897,10 +901,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);
@@ -1304,10 +1311,6 @@ ReorderBufferCommit(ReorderBuffer *rb, TransactionId xid,
txn->end_lsn = end_lsn;
txn->commit_time = commit_time;
- /* 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