Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit72e78d8

Browse files
author
Amit Kapila
committed
Add assert to ensure that page locks don't participate in deadlock cycle.
Assert that we don't acquire any other heavyweight lock while holding thepage lock except for relation extension. However, these locks are nevertaken in reverse order which implies that page locks will neverparticipate in the deadlock cycle.Similar to relation extension, page locks are also held for a shortduration, so imposing such a restriction won't hurt.Author: Dilip Kumar, with few changes by Amit KapilaReviewed-by: Amit Kapila, Kuntal Ghosh and Sawada MasahikoDiscussion:https://postgr.es/m/CAD21AoCmT3cFQUN4aVvzy5chw7DuzXrJCbrjTU05B+Ss=Gn1LA@mail.gmail.com
1 parent6312c08 commit72e78d8

File tree

1 file changed

+24
-2
lines changed
  • src/backend/storage/lmgr

1 file changed

+24
-2
lines changed

‎src/backend/storage/lmgr/lock.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,18 @@ static intFastPathLocalUseCount = 0;
185185
*/
186186
staticboolIsRelationExtensionLockHeldPG_USED_FOR_ASSERTS_ONLY= false;
187187

188+
/*
189+
* Flag to indicate if the page lock is held by this backend. We don't
190+
* acquire any other heavyweight lock while holding the page lock except for
191+
* relation extension. However, these locks are never taken in reverse order
192+
* which implies that page locks will also never participate in the deadlock
193+
* cycle.
194+
*
195+
* Similar to relation extension, page locks are also held for a short
196+
* duration, so imposing such a restriction won't hurt.
197+
*/
198+
staticboolIsPageLockHeldPG_USED_FOR_ASSERTS_ONLY= false;
199+
188200
/* Macros for manipulating proc->fpLockBits */
189201
#defineFAST_PATH_BITS_PER_SLOT3
190202
#defineFAST_PATH_LOCKNUMBER_OFFSET1
@@ -862,6 +874,13 @@ LockAcquireExtended(const LOCKTAG *locktag,
862874
*/
863875
Assert(!IsRelationExtensionLockHeld);
864876

877+
/*
878+
* We don't acquire any other heavyweight lock while holding the page lock
879+
* except for relation extension.
880+
*/
881+
Assert(!IsPageLockHeld||
882+
(locktag->locktag_type==LOCKTAG_RELATION_EXTEND));
883+
865884
/*
866885
* Prepare to emit a WAL record if acquisition of this lock needs to be
867886
* replayed in a standby server.
@@ -1310,10 +1329,10 @@ SetupLockInTable(LockMethod lockMethodTable, PGPROC *proc,
13101329
}
13111330

13121331
/*
1313-
* Check and set/reset the flag that we hold the relation extension lock.
1332+
* Check and set/reset the flag that we hold the relation extension/page lock.
13141333
*
13151334
* It is callers responsibility that this function is called after
1316-
* acquiring/releasing the relation extension lock.
1335+
* acquiring/releasing the relation extension/page lock.
13171336
*
13181337
* Pass acquired as true if lock is acquired, false otherwise.
13191338
*/
@@ -1323,6 +1342,9 @@ CheckAndSetLockHeld(LOCALLOCK *locallock, bool acquired)
13231342
#ifdefUSE_ASSERT_CHECKING
13241343
if (LOCALLOCK_LOCKTAG(*locallock)==LOCKTAG_RELATION_EXTEND)
13251344
IsRelationExtensionLockHeld=acquired;
1345+
elseif (LOCALLOCK_LOCKTAG(*locallock)==LOCKTAG_PAGE)
1346+
IsPageLockHeld=acquired;
1347+
13261348
#endif
13271349
}
13281350

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp