Fix memory counter update in ReorderBuffer.
authorMasahiko Sawada
Mon, 26 Aug 2024 18:00:04 +0000 (11:00 -0700)
committerMasahiko Sawada
Mon, 26 Aug 2024 18:00:04 +0000 (11:00 -0700)
commitdbed2e36625de9d4074243f60f48e04b5ed67810
treea735130d50c7eb86d06a546ae0dcdb34170ddd2f
parent6749d4aabe74ca37ce351f2e318fe1b3bcf2b71c
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
contrib/test_decoding/expected/stream.out
contrib/test_decoding/sql/stream.sql
src/backend/replication/logical/reorderbuffer.c