aboutsummaryrefslogtreecommitdiff
path: root/src/backend/replication/logical/reorderbuffer.c
diff options
context:
space:
mode:
authorAndres Freund <andres@anarazel.de>2017-06-18 18:48:22 -0700
committerAndres Freund <andres@anarazel.de>2017-06-18 19:13:15 -0700
commit810344436db69eb29ca5761fbed872c42de9e7d5 (patch)
tree1450ed366a16b08b9099fdaf381fa1227ecd1541 /src/backend/replication/logical/reorderbuffer.c
parenta9a5eb32b38443540def8f2d47f0b118601acbf5 (diff)
downloadpostgresql-810344436db69eb29ca5761fbed872c42de9e7d5.tar.gz
postgresql-810344436db69eb29ca5761fbed872c42de9e7d5.zip
Fix leaking of small spilled subtransactions during logical decoding.
When, during logical decoding, a transaction gets too big, it's contents get spilled to disk. Not just the top-transaction gets spilled, but *also* all of its subtransactions, even if they're not that large themselves. Unfortunately we didn't clean up such small spilled subtransactions from disk. Fix that, by keeping better track of whether a transaction has been spilled to disk. Author: Andres Freund Reported-By: Dmitriy Sarafannikov, Fabrízio de Royes Mello Discussion: https://postgr.es/m/1457621358.355011041@f382.i.mail.ru https://postgr.es/m/CAFcNs+qNMhNYii4nxpO6gqsndiyxNDYV0S=JNq0v_sEE+9PHXg@mail.gmail.com Backpatch: 9.4-, where logical decoding was introduced
Diffstat (limited to 'src/backend/replication/logical/reorderbuffer.c')
-rw-r--r--src/backend/replication/logical/reorderbuffer.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index 72c70585bc5..81bab8cf142 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -934,7 +934,7 @@ ReorderBufferIterTXNInit(ReorderBuffer *rb, ReorderBufferTXN *txn)
{
ReorderBufferChange *cur_change;
- if (txn->nentries != txn->nentries_mem)
+ if (txn->serialized)
{
/* serialize remaining changes */
ReorderBufferSerializeTXN(rb, txn);
@@ -963,7 +963,7 @@ ReorderBufferIterTXNInit(ReorderBuffer *rb, ReorderBufferTXN *txn)
{
ReorderBufferChange *cur_change;
- if (cur_txn->nentries != cur_txn->nentries_mem)
+ if (cur_txn->serialized)
{
/* serialize remaining changes */
ReorderBufferSerializeTXN(rb, cur_txn);
@@ -1185,7 +1185,7 @@ ReorderBufferCleanupTXN(ReorderBuffer *rb, ReorderBufferTXN *txn)
Assert(found);
/* remove entries spilled to disk */
- if (txn->nentries != txn->nentries_mem)
+ if (txn->serialized)
ReorderBufferRestoreCleanup(rb, txn);
/* deallocate */
@@ -2167,6 +2167,7 @@ ReorderBufferSerializeTXN(ReorderBuffer *rb, ReorderBufferTXN *txn)
Assert(spilled == txn->nentries_mem);
Assert(dlist_is_empty(&txn->changes));
txn->nentries_mem = 0;
+ txn->serialized = true;
if (fd != -1)
CloseTransientFile(fd);