Prevent multiple cleanup process for pending list in GIN.

Enterprise / PostgreSQL - Teodor Sigaev [sigaev.ru] - 28 April 2016 08:21 UTC

Previously, ginInsertCleanup could exit early if it detects that someone else is cleaning up the pending list, without waiting for that someone else to finish the job. But in this case vacuum could miss tuples to be deleted.

Cleanup process now locks metapage with a help of heavyweight LockPage(ExclusiveLock), and it guarantees that there is no another cleanup process at the same time. Lock is taken differently depending on caller of cleanup process: any vacuums and gin_clean_pending_list() will be blocked until lock becomes available, ordinary insert uses conditional lock to prevent indefinite waiting on lock.

Insert into pending list doesn't use this lock, so insertion isn't blocked.

Also, patch adds stopping of cleanup process when at-start-cleanup-tail is reached in order to prevent infinite cleanup in case of massive insertion. But it will stop only for automatic maintenance tasks like autovacuum.

Patch introduces choice of limit of memory to use: autovacuum_work_mem, maintenance_work_mem or work_mem depending on call path.

Patch for previous releases should be reworked due to changes between 9.6 and previous ones in this area.

Discover and diagnostics by Jeff Janes and Tomas Vondra

Patch by me with some ideas of Jeff Janes

e2c79e1 Prevent multiple cleanup process for pending list in GIN.
src/backend/access/gin/ginfast.c | 126 ++++++++++++++++++++----------------
src/backend/access/gin/ginvacuum.c | 11 ++--
src/include/access/gin_private.h | 2 +-
3 files changed, 77 insertions(+), 62 deletions(-)

Upstream: git.postgresql.org


  • Share