pgsql: Prevent multiple cleanup process for pending list in GIN. - Mailing list pgsql-committers

From Teodor Sigaev
Subject pgsql: Prevent multiple cleanup process for pending list in GIN.
Date
Msg-id E1avltQ-0005Wd-CU@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Prevent multiple cleanup process for pending list in GIN.

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

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/e2c79e14d998cd31f860854bc9210b37b457bb01

Modified Files
--------------
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(-)


pgsql-committers by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: pgsql: pg_upgrade: preserve database and relation minmxid values
Next
From: Teodor Sigaev
Date:
Subject: pgsql: Prevent to use magic constants