Fix logical decoding bug leading to inefficient reopening of files.
authorAndres Freund
Tue, 7 Jul 2015 11:12:59 +0000 (13:12 +0200)
committerAndres Freund
Tue, 7 Jul 2015 11:12:59 +0000 (13:12 +0200)
When spilling transaction data to disk a simple typo caused the output
file to be closed and reopened for every serialized change. That happens
to not have a huge impact on linux, which is why it probably wasn't
noticed so far, but on windows that appears to trigger actual disk
writes after every change. Not fun.

The bug fortunately does not have any impact besides speed. A change
could end up being in the wrong segment (last instead of next), but
since we read all files to the end, that's just ugly, not really
problematic. It's not a problem to upgrade, since transaction spill
files do not persist across restarts.

Bug: #13484
Reported-By: Olivier Gosseaume
Discussion: 20150703090217[email protected]

Backpatch to 9.4, where logical decoding was added.

src/backend/replication/logical/reorderbuffer.c

index 59bc3c3cc0ca5ce7c68a5b9486897f331e8c9f11..68cacff08b02c3aa5bcd1f3aa0e5b7c3d1fba4ae 100644 (file)
@@ -1937,7 +1937,7 @@ ReorderBufferSerializeTXN(ReorderBuffer *rb, ReorderBufferTXN *txn)
         * store in segment in which it belongs by start lsn, don't split over
         * multiple segments tho
         */
-       if (fd == -1 || XLByteInSeg(change->lsn, curOpenSegNo))
+       if (fd == -1 || !XLByteInSeg(change->lsn, curOpenSegNo))
        {
            XLogRecPtr  recptr;