diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2018-09-19 12:43:51 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2018-09-19 12:43:51 -0400 |
commit | 8f0de712c389df37d4db1fd439ede40189d75f60 (patch) | |
tree | b0d899c61339366aca12f0df2c43c1bf303db03c /src | |
parent | 2a6368343ff43743ddd90d0f4c2d0ac03e18aa85 (diff) | |
download | postgresql-8f0de712c389df37d4db1fd439ede40189d75f60.tar.gz postgresql-8f0de712c389df37d4db1fd439ede40189d75f60.zip |
Don't ignore locktable-full failures in StandbyAcquireAccessExclusiveLock.
Commit 37c54863c removed the code in StandbyAcquireAccessExclusiveLock
that checked the return value of LockAcquireExtended. That created a
bug, because it's still passing reportMemoryError = false to
LockAcquireExtended, meaning that LOCKACQUIRE_NOT_AVAIL will be returned
if we're out of shared memory for the lock table.
In such a situation, the startup process would believe it had acquired an
exclusive lock even though it hadn't, with potentially dire consequences.
To fix, just drop the use of reportMemoryError = false, which allows us
to simplify the call into a plain LockAcquire(). It's unclear that the
locktable-full situation arises often enough that it's worth having a
better recovery method than crash-and-restart. (I strongly suspect that
the only reason the code path existed at all was that it was relatively
simple to do in the pre-37c54863c implementation. But now it's not.)
LockAcquireExtended's reportMemoryError parameter is now dead code and
could be removed. I refrained from doing so, however, because there
was some interest in resurrecting the behavior if we do get reports of
locktable-full failures in the field. Also, it seems unwise to remove
the parameter concurrently with shipping commit f868a8143, which added a
parameter; if there are any third-party callers of LockAcquireExtended,
we want them to get a wrong-number-of-parameters compile error rather
than a possibly-silent misinterpretation of its last parameter.
Back-patch to 9.6 where the bug was introduced.
Discussion: https://postgr.es/m/6202.1536359835@sss.pgh.pa.us
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/storage/ipc/standby.c | 3 | ||||
-rw-r--r-- | src/backend/storage/lmgr/lock.c | 12 |
2 files changed, 8 insertions, 7 deletions
diff --git a/src/backend/storage/ipc/standby.c b/src/backend/storage/ipc/standby.c index f9c12e603b1..c9bb3e987d0 100644 --- a/src/backend/storage/ipc/standby.c +++ b/src/backend/storage/ipc/standby.c @@ -661,8 +661,7 @@ StandbyAcquireAccessExclusiveLock(TransactionId xid, Oid dbOid, Oid relOid) SET_LOCKTAG_RELATION(locktag, newlock->dbOid, newlock->relOid); - (void) LockAcquireExtended(&locktag, AccessExclusiveLock, true, false, - false, NULL); + (void) LockAcquire(&locktag, AccessExclusiveLock, true, false); } static void diff --git a/src/backend/storage/lmgr/lock.c b/src/backend/storage/lmgr/lock.c index 58d1f32cf36..831ae625258 100644 --- a/src/backend/storage/lmgr/lock.c +++ b/src/backend/storage/lmgr/lock.c @@ -693,11 +693,13 @@ LockAcquire(const LOCKTAG *locktag, /* * LockAcquireExtended - allows us to specify additional options * - * reportMemoryError specifies whether a lock request that fills the - * lock table should generate an ERROR or not. This allows a priority - * caller to note that the lock table is full and then begin taking - * extreme action to reduce the number of other lock holders before - * retrying the action. + * reportMemoryError specifies whether a lock request that fills the lock + * table should generate an ERROR or not. Passing "false" allows the caller + * to attempt to recover from lock-table-full situations, perhaps by forcibly + * cancelling other lock holders and then retrying. Note, however, that the + * return code for that is LOCKACQUIRE_NOT_AVAIL, so that it's unsafe to use + * in combination with dontWait = true, as the cause of failure couldn't be + * distinguished. * * If locallockp isn't NULL, *locallockp receives a pointer to the LOCALLOCK * table entry if a lock is successfully acquired, or NULL if not. |