diff options
author | Simon Riggs <simon@2ndQuadrant.com> | 2016-03-10 19:26:24 +0000 |
---|---|---|
committer | Simon Riggs <simon@2ndQuadrant.com> | 2016-03-10 19:26:24 +0000 |
commit | 37c54863cf71a4a1126d21db8eb68974bef34374 (patch) | |
tree | ad1213376b9b14f5479d14efaeec857b732f8b2f /src/backend/storage/lmgr/proc.c | |
parent | 53be0b1add7064ca5db3cd884302dfc3268d884e (diff) |
Rework wait for AccessExclusiveLocks on Hot Standby
Earlier version committed in 9.0 caused spurious waits in some cases.
New infrastructure for lock waits in 9.3 used to correct and improve this.
Jeff Janes based upon a proposal by Simon Riggs, who also reviewed
Additional review comments from Amit Kapila
Diffstat (limited to 'src/backend/storage/lmgr/proc.c')
-rw-r--r-- | src/backend/storage/lmgr/proc.c | 74 |
1 files changed, 46 insertions, 28 deletions
diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 46838d852e5..74ef4197986 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -42,6 +42,7 @@ #include "postmaster/autovacuum.h" #include "replication/slot.h" #include "replication/syncrep.h" +#include "storage/standby.h" #include "storage/ipc.h" #include "storage/lmgr.h" #include "storage/pmsignal.h" @@ -1169,21 +1170,27 @@ ProcSleep(LOCALLOCK *locallock, LockMethod lockMethodTable) * * If LockTimeout is set, also enable the timeout for that. We can save a * few cycles by enabling both timeout sources in one call. + * + * If InHotStandby we set lock waits slightly later for clarity with other + * code. */ - if (LockTimeout > 0) + if (!InHotStandby) { - EnableTimeoutParams timeouts[2]; - - timeouts[0].id = DEADLOCK_TIMEOUT; - timeouts[0].type = TMPARAM_AFTER; - timeouts[0].delay_ms = DeadlockTimeout; - timeouts[1].id = LOCK_TIMEOUT; - timeouts[1].type = TMPARAM_AFTER; - timeouts[1].delay_ms = LockTimeout; - enable_timeouts(timeouts, 2); + if (LockTimeout > 0) + { + EnableTimeoutParams timeouts[2]; + + timeouts[0].id = DEADLOCK_TIMEOUT; + timeouts[0].type = TMPARAM_AFTER; + timeouts[0].delay_ms = DeadlockTimeout; + timeouts[1].id = LOCK_TIMEOUT; + timeouts[1].type = TMPARAM_AFTER; + timeouts[1].delay_ms = LockTimeout; + enable_timeouts(timeouts, 2); + } + else + enable_timeout_after(DEADLOCK_TIMEOUT, DeadlockTimeout); } - else - enable_timeout_after(DEADLOCK_TIMEOUT, DeadlockTimeout); /* * If somebody wakes us between LWLockRelease and WaitLatch, the latch @@ -1201,15 +1208,23 @@ ProcSleep(LOCALLOCK *locallock, LockMethod lockMethodTable) */ do { - WaitLatch(MyLatch, WL_LATCH_SET, 0); - ResetLatch(MyLatch); - /* check for deadlocks first, as that's probably log-worthy */ - if (got_deadlock_timeout) + if (InHotStandby) + { + /* Set a timer and wait for that or for the Lock to be granted */ + ResolveRecoveryConflictWithLock(locallock->tag.lock); + } + else { - CheckDeadLock(); - got_deadlock_timeout = false; + WaitLatch(MyLatch, WL_LATCH_SET, 0); + ResetLatch(MyLatch); + /* check for deadlocks first, as that's probably log-worthy */ + if (got_deadlock_timeout) + { + CheckDeadLock(); + got_deadlock_timeout = false; + } + CHECK_FOR_INTERRUPTS(); } - CHECK_FOR_INTERRUPTS(); /* * waitStatus could change from STATUS_WAITING to something else @@ -1447,18 +1462,21 @@ ProcSleep(LOCALLOCK *locallock, LockMethod lockMethodTable) * already caused QueryCancelPending to become set, we want the cancel to * be reported as a lock timeout, not a user cancel. */ - if (LockTimeout > 0) + if (!InHotStandby) { - DisableTimeoutParams timeouts[2]; + if (LockTimeout > 0) + { + DisableTimeoutParams timeouts[2]; - timeouts[0].id = DEADLOCK_TIMEOUT; - timeouts[0].keep_indicator = false; - timeouts[1].id = LOCK_TIMEOUT; - timeouts[1].keep_indicator = true; - disable_timeouts(timeouts, 2); + timeouts[0].id = DEADLOCK_TIMEOUT; + timeouts[0].keep_indicator = false; + timeouts[1].id = LOCK_TIMEOUT; + timeouts[1].keep_indicator = true; + disable_timeouts(timeouts, 2); + } + else + disable_timeout(DEADLOCK_TIMEOUT, false); } - else - disable_timeout(DEADLOCK_TIMEOUT, false); /* * Re-acquire the lock table's partition lock. We have to do this to hold |