Skip autovacuum processes for distributed deadlock detection

Autovacuum process cancels itself if any modification starts
on the table in order to avoid blocking your regular Postgres
sessions. That's normal and expected. Thus, any locks held by
autovacuum process cannot involve in a distributed deadlock
since it'll be released if needed.
pull/2077/head
Onder Kalaci 2017-11-15 11:17:37 +02:00 committed by velioglu
parent fbfe5385cb
commit 376fc71fc9
1 changed files with 12 additions and 0 deletions

View File

@ -496,6 +496,10 @@ BuildLocalWaitGraph(void)
* IsProcessWaitingForSafeOperations returns true if the given PROC * IsProcessWaitingForSafeOperations returns true if the given PROC
* waiting on relation extension locks, page locks or speculative locks. * waiting on relation extension locks, page locks or speculative locks.
* *
* The function also returns true if the waiting process is an autovacuum
* process given that autovacuum cannot contribute to any distributed
* deadlocks.
*
* In general for the purpose of distributed deadlock detection, we should * In general for the purpose of distributed deadlock detection, we should
* skip if the process blocked on the locks that may not be part of deadlocks. * skip if the process blocked on the locks that may not be part of deadlocks.
* Those locks are held for a short duration while the relation or the index * Those locks are held for a short duration while the relation or the index
@ -509,12 +513,20 @@ IsProcessWaitingForSafeOperations(PGPROC *proc)
{ {
PROCLOCK *waitProcLock = NULL; PROCLOCK *waitProcLock = NULL;
LOCK *waitLock = NULL; LOCK *waitLock = NULL;
PGXACT *pgxact = NULL;
if (proc->waitStatus != STATUS_WAITING) if (proc->waitStatus != STATUS_WAITING)
{ {
return false; return false;
} }
/* get the transaction that the backend associated with */
pgxact = &ProcGlobal->allPgXact[proc->pgprocno];
if (pgxact->vacuumFlags & PROC_IS_AUTOVACUUM)
{
return true;
}
waitProcLock = proc->waitProcLock; waitProcLock = proc->waitProcLock;
waitLock = waitProcLock->tag.myLock; waitLock = waitProcLock->tag.myLock;