pgsql: hio: Don't pin the VM while holding buffer lock while extending

Поиск
Список
Период
Сортировка
От Andres Freund
Тема pgsql: hio: Don't pin the VM while holding buffer lock while extending
Дата
Msg-id E1pkULg-001ig5-AI@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
hio: Don't pin the VM while holding buffer lock while extending

Starting with commit 7db0cd2145f, RelationGetBufferForTuple() did a
visibilitymap_pin() while holding an exclusive buffer content lock on a newly
extended page, when using COPY FREEZE. We elsewhere try hard to avoid to doing
IO while holding a content lock. And until 14f98e0af99, that happened while
holding the relation extension lock.

Practically, this isn't a huge issue, because COPY FREEZE is restricted to
relations created or truncated in the current session, so it's unlikely
there's a lot of contention.

We can't avoid doing IO while holding the content lock by pinning the VM
earlier, because we don't know which page it will be on.

While we could just ignore the issue in this case, a future commit will add
bulk relation extension, which needs to enter pages into the FSM while also
trying to hold onto a buffer lock.

To address this issue, use visibilitymap_pin_ok() to see if the relevant
buffer is already pinned. If not, release the buffer, pin the VM buffer, and
acquire the lock again. This opens up a small window for other backends to
insert data onto the page - as the page is not entered into the freespacemap,
other backends won't see it normally, but a concurrent vacuum could enter the
page, if it started just after the relation is extended. In case the page is
used by another backend, retry. This is very similar to how locking
"otherBuffer" is already dealt with.

Reviewed-by: Tomas Vondra <tomas.vondra@enterprisedb.com>
Discussion: http://postgr.es/m/20230325025740.wzvchp2kromw4zqz@awork3.anarazel.de

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/18103b7c5f1aed4ca22f75229346eddb6e20d725

Modified Files
--------------
src/backend/access/heap/hio.c | 126 ++++++++++++++++++++++++++++--------------
1 file changed, 85 insertions(+), 41 deletions(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Andres Freund
Дата:
Сообщение: pgsql: hio: Relax rules for calling GetVisibilityMapPins()
Следующее
От: Tom Lane
Дата:
Сообщение: pgsql: Fix ts_headline() edge cases for empty query and empty search te