diff --git a/src/backend/access/gin/ginfast.c b/src/backend/access/gin/ginfast.c index 7409fdc165..1af9a69abb 100644 --- a/src/backend/access/gin/ginfast.c +++ b/src/backend/access/gin/ginfast.c @@ -791,20 +791,29 @@ ginInsertCleanup(GinState *ginstate, bool full_clean, bool fsm_vac = false; Size workMemory; - /* + /*r * We would like to prevent concurrent cleanup process. For that we will * lock metapage in exclusive mode using LockPage() call. Nobody other * will use that lock for metapage, so we keep possibility of concurrent * insertion into pending list */ + /* + * we use ShareUpdateExclusive lock on this relation to hold-off concurrent + * cleanup + */ + Assert(!CheckRelationLockedByMe(index, ShareUpdateExclusiveLock, false)); + + /* tentative debug-purpose assertion for stronger locks */ + Assert(!CheckRelationLockedByMe(index, ShareLock, true)); + if (forceCleanup) { /* * We are called from [auto]vacuum/analyze or gin_clean_pending_list() * and we would like to wait concurrent cleanup to finish. */ - LockPage(index, GIN_METAPAGE_BLKNO, ExclusiveLock); + LockRelation(index, ShareUpdateExclusiveLock); workMemory = (IsAutoVacuumWorkerProcess() && autovacuum_work_mem != -1) ? autovacuum_work_mem : maintenance_work_mem; @@ -816,7 +825,7 @@ ginInsertCleanup(GinState *ginstate, bool full_clean, * just exit in hope that concurrent process will clean up pending * list. */ - if (!ConditionalLockPage(index, GIN_METAPAGE_BLKNO, ExclusiveLock)) + if (!ConditionalLockRelation(index, ShareUpdateExclusiveLock)) return; workMemory = work_mem; } @@ -830,7 +839,7 @@ ginInsertCleanup(GinState *ginstate, bool full_clean, { /* Nothing to do */ UnlockReleaseBuffer(metabuffer); - UnlockPage(index, GIN_METAPAGE_BLKNO, ExclusiveLock); + UnlockRelation(index, ShareUpdateExclusiveLock); return; } @@ -1002,7 +1011,7 @@ ginInsertCleanup(GinState *ginstate, bool full_clean, page = BufferGetPage(buffer); } - UnlockPage(index, GIN_METAPAGE_BLKNO, ExclusiveLock); + UnlockRelation(index, ShareUpdateExclusiveLock); ReleaseBuffer(metabuffer); /*