Always prune dead members in MultiXactIdExpand, to fix assertion

MultiXactIdExpand() has an early return that returns the original
multixid, when the transaction is already a member.  The early return
happened before pruning members that are no longer of interest, e.g.
aborted transactions.

The comment in MultiXactIdExpand() says that removing the dead members
is not merely an optimization but needed for freezing, so it was
surprising that they were not always removed.  I don't see a live bug
with freezing though.

However, it tripped this assertion in heap_update().  When
heap_update() needs to temporarily lock the tuple before updating it,
it calls compute_new_xmax_infomask(), which calls MultiXactIdExpand(),
and then asserts that:

    Assert(HEAP_XMAX_IS_LOCKED_ONLY(infomask_lock_old_tuple));

The assumption makes sense at first glance: we've checked that the
tuple is not being updated, and we computed the infomask for locking
it, so surely the infomask should not indicate any updaters.  However,
if the xmax was previously a multixid which contained an updating
transaction that is now aborted, and our transaction was already a
member, MultiXactIdExpand() returned the original multixid with the
aborted updating member included.

To fix, make MultiXactIdExpand() remove dead members, even if the
original multixid already contains the transaction being added.  That
makes the assertion valid again.

Reported-by: Jasper Smit <[email protected]>
Reported-by: Lionel Hamayon <[email protected]>
Reported-by: RekGRpth <[email protected]>
Analyzed-by: Luc Vlaming Hummel <[email protected]>
Discussion: 
https://www.postgresql.org/message-id/CAOG+RQ6ECiiFH7bb7e1M0bkd0whprp=T0u=rvarsapogry-...@mail.gmail.com
Discussion: 
https://www.postgresql.org/message-id/CAPgh2mJhTo2yq_vLrT6OZPn54hDxJpDVu=9l7ay_m5qognf...@mail.gmail.com
Backpatch-through: 15

Branch
------
REL_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/4f4dbb593ebadd3e0cb7d292cdb28d55a8679f03

Modified Files
--------------
src/backend/access/transam/multixact.c | 65 +++++++++++++++++++++-------------
src/test/regress/expected/combocid.out | 49 +++++++++++++++++++++++++
src/test/regress/sql/combocid.sql      | 44 +++++++++++++++++++++++
3 files changed, 133 insertions(+), 25 deletions(-)

Reply via email to