Fix RBM_ZERO_AND_LOCK.
authorThomas Munro
Sun, 9 Jun 2024 23:43:41 +0000 (11:43 +1200)
committerThomas Munro
Mon, 10 Jun 2024 00:32:59 +0000 (12:32 +1200)
commite656657f2b93a96b83fd4038ec5120c5ec9845e5
treec02bc08efdf53af99ea100f8b9aff244626f4227
parent00ac25a3c365004821e819653c3307acd3294818
Fix RBM_ZERO_AND_LOCK.

Commit 210622c6 accidentally zeroed out pages even if they were found in
the buffer pool.  It should always lock the page, but it should only
zero pages that were not already valid.  Otherwise, concurrent readers
that hold only a pin could see corrupted page contents changing under
their feet.

While here, rename ZeroAndLockBuffer() to match the RBM_ flag name.
Also restore a some useful comments lost by 210622c6's refactoring, and
add some new ones to clarify why we need to use the BM_IO_IN_PROGRESS
infrastructure despite not doing I/O.

Reported-by: Noah Misch
Reported-by: Alexander Lakhin
Reviewed-by: Alvaro Herrera (earlier version)
Reviewed-by: Robert Haas (earlier version)
Discussion: https://postgr.es/m/20240512171658[email protected]
Discussion: https://postgr.es/m/7ed10231-ce47-03d5-d3f9-4aea0dc7d5a4%40gmail.com
src/backend/storage/buffer/bufmgr.c