Re: Allow aggressive VACUUM to freeze without a cleanup lock

Поиск
Список
Период
Сортировка
Искать

Re: Allow aggressive VACUUM to freeze without a cleanup lock

От:
Yuhang Qiu <iamqyh@gmail.com>
Дата:
Вложения:
Hi Melanie, Peter, Jingtang,

> So it's reasonable to surmise that freezing could be done with only an
> exclusive lock on top of the current VACUUM code (though not a shared
> lock, which seems really dangerous). And that page defragmentation is
> the only thing that necessitates a cleanup lock/makes this idea difficult.

Agreed. Freezing itself only needs an exclusive lock, a cleanup lock is needed
for page defragmentation. I also agree with Melanie that the patch should
explain this if it is not already documented elsewhere.

I reviewed the patch and found a few issues.

First, the buffer lock is released and reacquired between
`lazy_scan_noprune()` and `lazy_scan_freeze()`. The page may be changed or
already frozen during this window, so this assertion is not always valid:
```C
Assert(state.pagefrz.freeze_required);
```

Second, the code may call heap_prepare_freeze_tuple() and then discard the
freeze plans after finding an old DEAD tuple. This function may create a new
MultiXactId, write WAL, and advance the MultiXact state. These side effects
remain even if the plans are discarded.

There is also a small naming issue. lazy_scan_noprune and lazy_scan_freeze are
quite confusing now. I think lazy_scan_noprune is not correct at this moment.

The patch adds FreezeState, HeapPageFreezeParams, and
HeapPageFreezeResult, but they overlap with PruneState,
PruneFreezeParams, and PruneFreezeResult. These abstractions add complexity
without much reuse.

Pages containing old XIDs or MultiXactIds in DEAD tuples still need a cleanup
lock. I think this is a reasonable limitation for this patch.

Best Regards,
Yuhang Qiu



Re: Allow aggressive VACUUM to freeze without a cleanup lock

От:
Jingtang Zhang <mrdrivingduck@gmail.com>
Дата:
Hi, Melanie.

Thanks for looking.

> Do you know if in your use case this would have been able to do the
> freeze (i.e. you didn't have too-old dead tuples on the page) with
> needing pruning?

In this case, I believe the page would have been able to make freeze
progress without pruning.  Whenever an anti-wraparound VACUUM became
stuck, we had to terminate every SELECT FOR UPDATE session accessing that
page before it could acquire the cleanup lock and proceed past the page
using the normal prune-and-freeze path.  That pass would have removed any
removable DEAD tuples on the page.  Across many subsequent
anti-wraparound VACUUM runs, the same page and the same row repeatedly
became the blocking point again.  The recurring workload continuously
ran SELECT FOR UPDATE on that row, and later anti-wraparound VACUUM runs
again waited on BufferPin at the same page and row.

SELECT FOR UPDATE does not create a new tuple version.  It only locks
the existing tuple, so repeated locking of the same logical row continues
to access the same physical tuple and the same heap page.  There is no
mechanism that moves this hotspot to another page.

UPDATE behaves differently.  Without pruning, old tuple versions cannot
have their space recycled on the current page.  As the page fills, a
later update can no longer be HOT and must place the new current version
on another page.  The original page is then no longer the hotspot for
that row, so the sustained pins can move away and it can get a chance to
be pruned.  SELECT FOR UPDATE has no comparable escape path.

---
Regards,
Jingtang


FAQ