1 /*-------------------------------------------------------------------------
4 * POSTGRES low-level lock mechanism
7 * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * src/include/storage/lock.h
12 *-------------------------------------------------------------------------
18 #error "lock.h may not be included from frontend code"
21 #include "storage/backendid.h"
22 #include "storage/lockdefs.h"
23 #include "storage/lwlock.h"
24 #include "storage/shmem.h"
25 #include "utils/timestamp.h"
27 /* struct PGPROC is declared in proc.h, but must forward-reference it */
28 typedef struct PGPROC PGPROC
;
30 typedef struct PROC_QUEUE
32 SHM_QUEUE links
; /* head of list of PGPROC objects */
33 int size
; /* number of entries in list */
37 extern int max_locks_per_xact
;
40 extern int Trace_lock_oidmin
;
41 extern bool Trace_locks
;
42 extern bool Trace_userlocks
;
43 extern int Trace_lock_table
;
44 extern bool Debug_deadlocks
;
45 #endif /* LOCK_DEBUG */
49 * Top-level transactions are identified by VirtualTransactionIDs comprising
50 * PGPROC fields backendId and lxid. For prepared transactions, the
51 * LocalTransactionId is an ordinary XID. These are guaranteed unique over
52 * the short term, but will be reused after a database restart or XID
53 * wraparound; hence they should never be stored on disk.
55 * Note that struct VirtualTransactionId can not be assumed to be atomically
56 * assignable as a whole. However, type LocalTransactionId is assumed to
57 * be atomically assignable, and the backend ID doesn't change often enough
58 * to be a problem, so we can fetch or assign the two fields separately.
59 * We deliberately refrain from using the struct within PGPROC, to prevent
60 * coding errors from trying to use struct assignment with it; instead use
61 * GET_VXID_FROM_PGPROC().
65 BackendId backendId
; /* backendId from PGPROC */
66 LocalTransactionId localTransactionId
; /* lxid from PGPROC */
67 } VirtualTransactionId
;
69 #define InvalidLocalTransactionId 0
70 #define LocalTransactionIdIsValid(lxid) ((lxid) != InvalidLocalTransactionId)
71 #define VirtualTransactionIdIsValid(vxid) \
72 (LocalTransactionIdIsValid((vxid).localTransactionId))
73 #define VirtualTransactionIdIsPreparedXact(vxid) \
74 ((vxid).backendId == InvalidBackendId)
75 #define VirtualTransactionIdEquals(vxid1, vxid2) \
76 ((vxid1).backendId == (vxid2).backendId && \
77 (vxid1).localTransactionId == (vxid2).localTransactionId)
78 #define SetInvalidVirtualTransactionId(vxid) \
79 ((vxid).backendId = InvalidBackendId, \
80 (vxid).localTransactionId = InvalidLocalTransactionId)
81 #define GET_VXID_FROM_PGPROC(vxid, proc) \
82 ((vxid).backendId = (proc).backendId, \
83 (vxid).localTransactionId = (proc).lxid)
85 /* MAX_LOCKMODES cannot be larger than the # of bits in LOCKMASK */
86 #define MAX_LOCKMODES 10
88 #define LOCKBIT_ON(lockmode) (1 << (lockmode))
89 #define LOCKBIT_OFF(lockmode) (~(1 << (lockmode)))
93 * This data structure defines the locking semantics associated with a
94 * "lock method". The semantics specify the meaning of each lock mode
95 * (by defining which lock modes it conflicts with).
96 * All of this data is constant and is kept in const tables.
98 * numLockModes -- number of lock modes (READ,WRITE,etc) that
99 * are defined in this lock method. Must be less than MAX_LOCKMODES.
101 * conflictTab -- this is an array of bitmasks showing lock
102 * mode conflicts. conflictTab[i] is a mask with the j-th bit
103 * turned on if lock modes i and j conflict. Lock modes are
104 * numbered 1..numLockModes; conflictTab[0] is unused.
106 * lockModeNames -- ID strings for debug printouts.
108 * trace_flag -- pointer to GUC trace flag for this lock method. (The
109 * GUC variable is not constant, but we use "const" here to denote that
110 * it can't be changed through this reference.)
112 typedef struct LockMethodData
115 const LOCKMASK
*conflictTab
;
116 const char *const *lockModeNames
;
117 const bool *trace_flag
;
120 typedef const LockMethodData
*LockMethod
;
123 * Lock methods are identified by LOCKMETHODID. (Despite the declaration as
124 * uint16, we are constrained to 256 lockmethods by the layout of LOCKTAG.)
126 typedef uint16 LOCKMETHODID
;
128 /* These identify the known lock methods */
129 #define DEFAULT_LOCKMETHOD 1
130 #define USER_LOCKMETHOD 2
133 * LOCKTAG is the key information needed to look up a LOCK item in the
134 * lock hashtable. A LOCKTAG value uniquely identifies a lockable object.
136 * The LockTagType enum defines the different kinds of objects we can lock.
137 * We can handle up to 256 different LockTagTypes.
139 typedef enum LockTagType
141 LOCKTAG_RELATION
, /* whole relation */
142 LOCKTAG_RELATION_EXTEND
, /* the right to extend a relation */
143 LOCKTAG_DATABASE_FROZEN_IDS
, /* pg_database.datfrozenxid */
144 LOCKTAG_PAGE
, /* one page of a relation */
145 LOCKTAG_TUPLE
, /* one physical tuple */
146 LOCKTAG_TRANSACTION
, /* transaction (for waiting for xact done) */
147 LOCKTAG_VIRTUALTRANSACTION
, /* virtual transaction (ditto) */
148 LOCKTAG_SPECULATIVE_TOKEN
, /* speculative insertion Xid and token */
149 LOCKTAG_OBJECT
, /* non-relation database object */
150 LOCKTAG_USERLOCK
, /* reserved for old contrib/userlock code */
151 LOCKTAG_ADVISORY
/* advisory user locks */
154 #define LOCKTAG_LAST_TYPE LOCKTAG_ADVISORY
156 extern const char *const LockTagTypeNames
[];
159 * The LOCKTAG struct is defined with malice aforethought to fit into 16
160 * bytes with no padding. Note that this would need adjustment if we were
161 * to widen Oid, BlockNumber, or TransactionId to more than 32 bits.
163 * We include lockmethodid in the locktag so that a single hash table in
164 * shared memory can store locks of different lockmethods.
166 typedef struct LOCKTAG
168 uint32 locktag_field1
; /* a 32-bit ID field */
169 uint32 locktag_field2
; /* a 32-bit ID field */
170 uint32 locktag_field3
; /* a 32-bit ID field */
171 uint16 locktag_field4
; /* a 16-bit ID field */
172 uint8 locktag_type
; /* see enum LockTagType */
173 uint8 locktag_lockmethodid
; /* lockmethod indicator */
177 * These macros define how we map logical IDs of lockable objects into
178 * the physical fields of LOCKTAG. Use these to set up LOCKTAG values,
179 * rather than accessing the fields directly. Note multiple eval of target!
182 /* ID info for a relation is DB OID + REL OID; DB OID = 0 if shared */
183 #define SET_LOCKTAG_RELATION(locktag,dboid,reloid) \
184 ((locktag).locktag_field1 = (dboid), \
185 (locktag).locktag_field2 = (reloid), \
186 (locktag).locktag_field3 = 0, \
187 (locktag).locktag_field4 = 0, \
188 (locktag).locktag_type = LOCKTAG_RELATION, \
189 (locktag).locktag_lockmethodid = DEFAULT_LOCKMETHOD)
191 /* same ID info as RELATION */
192 #define SET_LOCKTAG_RELATION_EXTEND(locktag,dboid,reloid) \
193 ((locktag).locktag_field1 = (dboid), \
194 (locktag).locktag_field2 = (reloid), \
195 (locktag).locktag_field3 = 0, \
196 (locktag).locktag_field4 = 0, \
197 (locktag).locktag_type = LOCKTAG_RELATION_EXTEND, \
198 (locktag).locktag_lockmethodid = DEFAULT_LOCKMETHOD)
200 /* ID info for frozen IDs is DB OID */
201 #define SET_LOCKTAG_DATABASE_FROZEN_IDS(locktag,dboid) \
202 ((locktag).locktag_field1 = (dboid), \
203 (locktag).locktag_field2 = 0, \
204 (locktag).locktag_field3 = 0, \
205 (locktag).locktag_field4 = 0, \
206 (locktag).locktag_type = LOCKTAG_DATABASE_FROZEN_IDS, \
207 (locktag).locktag_lockmethodid = DEFAULT_LOCKMETHOD)
209 /* ID info for a page is RELATION info + BlockNumber */
210 #define SET_LOCKTAG_PAGE(locktag,dboid,reloid,blocknum) \
211 ((locktag).locktag_field1 = (dboid), \
212 (locktag).locktag_field2 = (reloid), \
213 (locktag).locktag_field3 = (blocknum), \
214 (locktag).locktag_field4 = 0, \
215 (locktag).locktag_type = LOCKTAG_PAGE, \
216 (locktag).locktag_lockmethodid = DEFAULT_LOCKMETHOD)
218 /* ID info for a tuple is PAGE info + OffsetNumber */
219 #define SET_LOCKTAG_TUPLE(locktag,dboid,reloid,blocknum,offnum) \
220 ((locktag).locktag_field1 = (dboid), \
221 (locktag).locktag_field2 = (reloid), \
222 (locktag).locktag_field3 = (blocknum), \
223 (locktag).locktag_field4 = (offnum), \
224 (locktag).locktag_type = LOCKTAG_TUPLE, \
225 (locktag).locktag_lockmethodid = DEFAULT_LOCKMETHOD)
227 /* ID info for a transaction is its TransactionId */
228 #define SET_LOCKTAG_TRANSACTION(locktag,xid) \
229 ((locktag).locktag_field1 = (xid), \
230 (locktag).locktag_field2 = 0, \
231 (locktag).locktag_field3 = 0, \
232 (locktag).locktag_field4 = 0, \
233 (locktag).locktag_type = LOCKTAG_TRANSACTION, \
234 (locktag).locktag_lockmethodid = DEFAULT_LOCKMETHOD)
236 /* ID info for a virtual transaction is its VirtualTransactionId */
237 #define SET_LOCKTAG_VIRTUALTRANSACTION(locktag,vxid) \
238 ((locktag).locktag_field1 = (vxid).backendId, \
239 (locktag).locktag_field2 = (vxid).localTransactionId, \
240 (locktag).locktag_field3 = 0, \
241 (locktag).locktag_field4 = 0, \
242 (locktag).locktag_type = LOCKTAG_VIRTUALTRANSACTION, \
243 (locktag).locktag_lockmethodid = DEFAULT_LOCKMETHOD)
246 * ID info for a speculative insert is TRANSACTION info +
247 * its speculative insert counter.
249 #define SET_LOCKTAG_SPECULATIVE_INSERTION(locktag,xid,token) \
250 ((locktag).locktag_field1 = (xid), \
251 (locktag).locktag_field2 = (token), \
252 (locktag).locktag_field3 = 0, \
253 (locktag).locktag_field4 = 0, \
254 (locktag).locktag_type = LOCKTAG_SPECULATIVE_TOKEN, \
255 (locktag).locktag_lockmethodid = DEFAULT_LOCKMETHOD)
258 * ID info for an object is DB OID + CLASS OID + OBJECT OID + SUBID
260 * Note: object ID has same representation as in pg_depend and
261 * pg_description, but notice that we are constraining SUBID to 16 bits.
262 * Also, we use DB OID = 0 for shared objects such as tablespaces.
264 #define SET_LOCKTAG_OBJECT(locktag,dboid,classoid,objoid,objsubid) \
265 ((locktag).locktag_field1 = (dboid), \
266 (locktag).locktag_field2 = (classoid), \
267 (locktag).locktag_field3 = (objoid), \
268 (locktag).locktag_field4 = (objsubid), \
269 (locktag).locktag_type = LOCKTAG_OBJECT, \
270 (locktag).locktag_lockmethodid = DEFAULT_LOCKMETHOD)
272 #define SET_LOCKTAG_ADVISORY(locktag,id1,id2,id3,id4) \
273 ((locktag).locktag_field1 = (id1), \
274 (locktag).locktag_field2 = (id2), \
275 (locktag).locktag_field3 = (id3), \
276 (locktag).locktag_field4 = (id4), \
277 (locktag).locktag_type = LOCKTAG_ADVISORY, \
278 (locktag).locktag_lockmethodid = USER_LOCKMETHOD)
282 * Per-locked-object lock information:
284 * tag -- uniquely identifies the object being locked
285 * grantMask -- bitmask for all lock types currently granted on this object.
286 * waitMask -- bitmask for all lock types currently awaited on this object.
287 * procLocks -- list of PROCLOCK objects for this lock.
288 * waitProcs -- queue of processes waiting for this lock.
289 * requested -- count of each lock type currently requested on the lock
290 * (includes requests already granted!!).
291 * nRequested -- total requested locks of all types.
292 * granted -- count of each lock type currently granted on the lock.
293 * nGranted -- total granted locks of all types.
295 * Note: these counts count 1 for each backend. Internally to a backend,
296 * there may be multiple grabs on a particular lock, but this is not reflected
297 * into shared memory.
302 LOCKTAG tag
; /* unique identifier of lockable object */
305 LOCKMASK grantMask
; /* bitmask for lock types already granted */
306 LOCKMASK waitMask
; /* bitmask for lock types awaited */
307 SHM_QUEUE procLocks
; /* list of PROCLOCK objects assoc. with lock */
308 PROC_QUEUE waitProcs
; /* list of PGPROC objects waiting on lock */
309 int requested
[MAX_LOCKMODES
]; /* counts of requested locks */
310 int nRequested
; /* total of requested[] array */
311 int granted
[MAX_LOCKMODES
]; /* counts of granted locks */
312 int nGranted
; /* total of granted[] array */
315 #define LOCK_LOCKMETHOD(lock) ((LOCKMETHODID) (lock).tag.locktag_lockmethodid)
316 #define LOCK_LOCKTAG(lock) ((LockTagType) (lock).tag.locktag_type)
320 * We may have several different backends holding or awaiting locks
321 * on the same lockable object. We need to store some per-holder/waiter
322 * information for each such holder (or would-be holder). This is kept in
325 * PROCLOCKTAG is the key information needed to look up a PROCLOCK item in the
326 * proclock hashtable. A PROCLOCKTAG value uniquely identifies the combination
327 * of a lockable object and a holder/waiter for that object. (We can use
328 * pointers here because the PROCLOCKTAG need only be unique for the lifespan
329 * of the PROCLOCK, and it will never outlive the lock or the proc.)
331 * Internally to a backend, it is possible for the same lock to be held
332 * for different purposes: the backend tracks transaction locks separately
333 * from session locks. However, this is not reflected in the shared-memory
334 * state: we only track which backend(s) hold the lock. This is OK since a
335 * backend can never block itself.
337 * The holdMask field shows the already-granted locks represented by this
338 * proclock. Note that there will be a proclock object, possibly with
339 * zero holdMask, for any lock that the process is currently waiting on.
340 * Otherwise, proclock objects whose holdMasks are zero are recycled
341 * as soon as convenient.
343 * releaseMask is workspace for LockReleaseAll(): it shows the locks due
344 * to be released during the current call. This must only be examined or
345 * set by the backend owning the PROCLOCK.
347 * Each PROCLOCK object is linked into lists for both the associated LOCK
348 * object and the owning PGPROC object. Note that the PROCLOCK is entered
349 * into these lists as soon as it is created, even if no lock has yet been
350 * granted. A PGPROC that is waiting for a lock to be granted will also be
351 * linked into the lock's waitProcs queue.
353 typedef struct PROCLOCKTAG
355 /* NB: we assume this struct contains no padding! */
356 LOCK
*myLock
; /* link to per-lockable-object information */
357 PGPROC
*myProc
; /* link to PGPROC of owning backend */
360 typedef struct PROCLOCK
363 PROCLOCKTAG tag
; /* unique identifier of proclock object */
366 PGPROC
*groupLeader
; /* proc's lock group leader, or proc itself */
367 LOCKMASK holdMask
; /* bitmask for lock types currently held */
368 LOCKMASK releaseMask
; /* bitmask for lock types to be released */
369 SHM_QUEUE lockLink
; /* list link in LOCK's list of proclocks */
370 SHM_QUEUE procLink
; /* list link in PGPROC's list of proclocks */
373 #define PROCLOCK_LOCKMETHOD(proclock) \
374 LOCK_LOCKMETHOD(*((proclock).tag.myLock))
377 * Each backend also maintains a local hash table with information about each
378 * lock it is currently interested in. In particular the local table counts
379 * the number of times that lock has been acquired. This allows multiple
380 * requests for the same lock to be executed without additional accesses to
381 * shared memory. We also track the number of lock acquisitions per
382 * ResourceOwner, so that we can release just those locks belonging to a
383 * particular ResourceOwner.
385 * When holding a lock taken "normally", the lock and proclock fields always
386 * point to the associated objects in shared memory. However, if we acquired
387 * the lock via the fast-path mechanism, the lock and proclock fields are set
388 * to NULL, since there probably aren't any such objects in shared memory.
389 * (If the lock later gets promoted to normal representation, we may eventually
390 * update our locallock's lock/proclock fields after finding the shared
393 * Caution: a locallock object can be left over from a failed lock acquisition
394 * attempt. In this case its lock/proclock fields are untrustworthy, since
395 * the shared lock object is neither held nor awaited, and hence is available
396 * to be reclaimed. If nLocks > 0 then these pointers must either be valid or
397 * NULL, but when nLocks == 0 they should be considered garbage.
399 typedef struct LOCALLOCKTAG
401 LOCKTAG lock
; /* identifies the lockable object */
402 LOCKMODE mode
; /* lock mode for this table entry */
405 typedef struct LOCALLOCKOWNER
408 * Note: if owner is NULL then the lock is held on behalf of the session;
409 * otherwise it is held on behalf of my current transaction.
411 * Must use a forward struct reference to avoid circularity.
413 struct ResourceOwnerData
*owner
;
414 int64 nLocks
; /* # of times held by this owner */
417 typedef struct LOCALLOCK
420 LOCALLOCKTAG tag
; /* unique identifier of locallock entry */
423 uint32 hashcode
; /* copy of LOCKTAG's hash value */
424 LOCK
*lock
; /* associated LOCK object, if any */
425 PROCLOCK
*proclock
; /* associated PROCLOCK object, if any */
426 int64 nLocks
; /* total number of times lock is held */
427 int numLockOwners
; /* # of relevant ResourceOwners */
428 int maxLockOwners
; /* allocated size of array */
429 LOCALLOCKOWNER
*lockOwners
; /* dynamically resizable array */
430 bool holdsStrongLockCount
; /* bumped FastPathStrongRelationLocks */
431 bool lockCleared
; /* we read all sinval msgs for lock */
434 #define LOCALLOCK_LOCKMETHOD(llock) ((llock).tag.lock.locktag_lockmethodid)
435 #define LOCALLOCK_LOCKTAG(llock) ((LockTagType) (llock).tag.lock.locktag_type)
439 * These structures hold information passed from lmgr internals to the lock
440 * listing user-level functions (in lockfuncs.c).
443 typedef struct LockInstanceData
445 LOCKTAG locktag
; /* tag for locked object */
446 LOCKMASK holdMask
; /* locks held by this PGPROC */
447 LOCKMODE waitLockMode
; /* lock awaited by this PGPROC, if any */
448 BackendId backend
; /* backend ID of this PGPROC */
449 LocalTransactionId lxid
; /* local transaction ID of this PGPROC */
450 TimestampTz waitStart
; /* time at which this PGPROC started waiting
452 int pid
; /* pid of this PGPROC */
453 int leaderPid
; /* pid of group leader; = pid if no group */
454 bool fastpath
; /* taken via fastpath? */
457 typedef struct LockData
459 int nelements
; /* The length of the array */
460 LockInstanceData
*locks
; /* Array of per-PROCLOCK information */
463 typedef struct BlockedProcData
465 int pid
; /* pid of a blocked PGPROC */
466 /* Per-PROCLOCK information about PROCLOCKs of the lock the pid awaits */
467 /* (these fields refer to indexes in BlockedProcsData.locks[]) */
468 int first_lock
; /* index of first relevant LockInstanceData */
469 int num_locks
; /* number of relevant LockInstanceDatas */
470 /* PIDs of PGPROCs that are ahead of "pid" in the lock's wait queue */
471 /* (these fields refer to indexes in BlockedProcsData.waiter_pids[]) */
472 int first_waiter
; /* index of first preceding waiter */
473 int num_waiters
; /* number of preceding waiters */
476 typedef struct BlockedProcsData
478 BlockedProcData
*procs
; /* Array of per-blocked-proc information */
479 LockInstanceData
*locks
; /* Array of per-PROCLOCK information */
480 int *waiter_pids
; /* Array of PIDs of other blocked PGPROCs */
481 int nprocs
; /* # of valid entries in procs[] array */
482 int maxprocs
; /* Allocated length of procs[] array */
483 int nlocks
; /* # of valid entries in locks[] array */
484 int maxlocks
; /* Allocated length of locks[] array */
485 int npids
; /* # of valid entries in waiter_pids[] array */
486 int maxpids
; /* Allocated length of waiter_pids[] array */
490 /* Result codes for LockAcquire() */
493 LOCKACQUIRE_NOT_AVAIL
, /* lock not available, and dontWait=true */
494 LOCKACQUIRE_OK
, /* lock successfully acquired */
495 LOCKACQUIRE_ALREADY_HELD
, /* incremented count for lock already held */
496 LOCKACQUIRE_ALREADY_CLEAR
/* incremented count for lock already clear */
499 /* Deadlock states identified by DeadLockCheck() */
502 DS_NOT_YET_CHECKED
, /* no deadlock check has run yet */
503 DS_NO_DEADLOCK
, /* no deadlock detected */
504 DS_SOFT_DEADLOCK
, /* deadlock avoided by queue rearrangement */
505 DS_HARD_DEADLOCK
, /* deadlock, no way out but ERROR */
506 DS_BLOCKED_BY_AUTOVACUUM
/* no deadlock; queue blocked by autovacuum
511 * The lockmgr's shared hash tables are partitioned to reduce contention.
512 * To determine which partition a given locktag belongs to, compute the tag's
513 * hash code with LockTagHashCode(), then apply one of these macros.
514 * NB: NUM_LOCK_PARTITIONS must be a power of 2!
516 #define LockHashPartition(hashcode) \
517 ((hashcode) % NUM_LOCK_PARTITIONS)
518 #define LockHashPartitionLock(hashcode) \
519 (&MainLWLockArray[LOCK_MANAGER_LWLOCK_OFFSET + \
520 LockHashPartition(hashcode)].lock)
521 #define LockHashPartitionLockByIndex(i) \
522 (&MainLWLockArray[LOCK_MANAGER_LWLOCK_OFFSET + (i)].lock)
525 * The deadlock detector needs to be able to access lockGroupLeader and
526 * related fields in the PGPROC, so we arrange for those fields to be protected
527 * by one of the lock hash partition locks. Since the deadlock detector
528 * acquires all such locks anyway, this makes it safe for it to access these
529 * fields without doing anything extra. To avoid contention as much as
530 * possible, we map different PGPROCs to different partition locks. The lock
531 * used for a given lock group is determined by the group leader's pgprocno.
533 #define LockHashPartitionLockByProc(leader_pgproc) \
534 LockHashPartitionLock((leader_pgproc)->pgprocno)
537 * function prototypes
539 extern void InitLocks(void);
540 extern LockMethod
GetLocksMethodTable(const LOCK
*lock
);
541 extern LockMethod
GetLockTagsMethodTable(const LOCKTAG
*locktag
);
542 extern uint32
LockTagHashCode(const LOCKTAG
*locktag
);
543 extern bool DoLockModesConflict(LOCKMODE mode1
, LOCKMODE mode2
);
544 extern LockAcquireResult
LockAcquire(const LOCKTAG
*locktag
,
548 extern LockAcquireResult
LockAcquireExtended(const LOCKTAG
*locktag
,
552 bool reportMemoryError
,
553 LOCALLOCK
**locallockp
);
554 extern void AbortStrongLockAcquire(void);
555 extern void MarkLockClear(LOCALLOCK
*locallock
);
556 extern bool LockRelease(const LOCKTAG
*locktag
,
557 LOCKMODE lockmode
, bool sessionLock
);
558 extern void LockReleaseAll(LOCKMETHODID lockmethodid
, bool allLocks
);
559 extern void LockReleaseSession(LOCKMETHODID lockmethodid
);
560 extern void LockReleaseCurrentOwner(LOCALLOCK
**locallocks
, int nlocks
);
561 extern void LockReassignCurrentOwner(LOCALLOCK
**locallocks
, int nlocks
);
562 extern bool LockHeldByMe(const LOCKTAG
*locktag
, LOCKMODE lockmode
);
563 #ifdef USE_ASSERT_CHECKING
564 extern HTAB
*GetLockMethodLocalHash(void);
566 extern bool LockHasWaiters(const LOCKTAG
*locktag
,
567 LOCKMODE lockmode
, bool sessionLock
);
568 extern VirtualTransactionId
*GetLockConflicts(const LOCKTAG
*locktag
,
569 LOCKMODE lockmode
, int *countp
);
570 extern void AtPrepare_Locks(void);
571 extern void PostPrepare_Locks(TransactionId xid
);
572 extern bool LockCheckConflicts(LockMethod lockMethodTable
,
574 LOCK
*lock
, PROCLOCK
*proclock
);
575 extern void GrantLock(LOCK
*lock
, PROCLOCK
*proclock
, LOCKMODE lockmode
);
576 extern void GrantAwaitedLock(void);
577 extern void RemoveFromWaitQueue(PGPROC
*proc
, uint32 hashcode
);
578 extern Size
LockShmemSize(void);
579 extern LockData
*GetLockStatusData(void);
580 extern BlockedProcsData
*GetBlockerStatusData(int blocked_pid
);
582 extern xl_standby_lock
*GetRunningTransactionLocks(int *nlocks
);
583 extern const char *GetLockmodeName(LOCKMETHODID lockmethodid
, LOCKMODE mode
);
585 extern void lock_twophase_recover(TransactionId xid
, uint16 info
,
586 void *recdata
, uint32 len
);
587 extern void lock_twophase_postcommit(TransactionId xid
, uint16 info
,
588 void *recdata
, uint32 len
);
589 extern void lock_twophase_postabort(TransactionId xid
, uint16 info
,
590 void *recdata
, uint32 len
);
591 extern void lock_twophase_standby_recover(TransactionId xid
, uint16 info
,
592 void *recdata
, uint32 len
);
594 extern DeadLockState
DeadLockCheck(PGPROC
*proc
);
595 extern PGPROC
*GetBlockingAutoVacuumPgproc(void);
596 extern void DeadLockReport(void) pg_attribute_noreturn();
597 extern void RememberSimpleDeadLock(PGPROC
*proc1
,
601 extern void InitDeadLockChecking(void);
603 extern int LockWaiterCount(const LOCKTAG
*locktag
);
606 extern void DumpLocks(PGPROC
*proc
);
607 extern void DumpAllLocks(void);
610 /* Lock a VXID (used to wait for a transaction to finish) */
611 extern void VirtualXactLockTableInsert(VirtualTransactionId vxid
);
612 extern void VirtualXactLockTableCleanup(void);
613 extern bool VirtualXactLock(VirtualTransactionId vxid
, bool wait
);