pgsql: Fix memory counter update in ReorderBuffer.

From: Masahiko Sawada <msawada(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix memory counter update in ReorderBuffer.
Date: 2024-08-26 18:00:51
Message-ID: E1sie1L-001bAv-LY@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix memory counter update in ReorderBuffer.

Commit 5bec1d6bc5e changed the memory usage updates of the
ReorderBufferTXN to zero all at once by subtracting txn->size, rather
than updating it for each change. However, if TOAST reconstruction
data remained in the transaction when freeing it, there were cases
where it further subtracted the memory counter from zero, resulting in
an assertion failure.

This change calculates the memory size for each change and updates the
memory usage to precisely the amount that has been freed.

Backpatch to v17, where this was introducd.

Reviewed-by: Amit Kapila, Shlok Kyal
Discussion: https://postgr.es/m/CAD21AoAqkNUvicgKPT_dXzNoOwpPkVTg0QPPxEcWmzT0moCJ1g%40mail.gmail.com
Backpatch-through: 17

Branch
------
REL_17_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/dbed2e36625de9d4074243f60f48e04b5ed67810

Modified Files
--------------
contrib/test_decoding/expected/stream.out | 19 +++++++++++++++
contrib/test_decoding/sql/stream.sql | 15 ++++++++++++
src/backend/replication/logical/reorderbuffer.c | 32 +++++++++++++++++++++----
3 files changed, 62 insertions(+), 4 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Masahiko Sawada 2024-08-26 18:00:56 pgsql: Fix memory counter update in ReorderBuffer.
Previous Message Peter Geoghegan 2024-08-26 15:30:25 pgsql: Fix nbtree lookahead overflow bug.