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:56
Message-ID: E1sie1Q-001bBW-II@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
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/52f1d6730bf7132a175b9b612029812859218927

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 19:05:41 Re: pgsql: Restrict accesses to non-system views and foreign tables during
Previous Message Masahiko Sawada 2024-08-26 18:00:51 pgsql: Fix memory counter update in ReorderBuffer.