55 mul_size(max_locks_per_xact, add_size(MaxBackends, max_prepared_xacts))
112 "ShareUpdateExclusiveLock",
114 "ShareRowExclusiveLock",
116 "AccessExclusiveLock"
212#define FAST_PATH_REL_GROUP(rel) \
213 (((uint64) (rel) * 49157) % FastPathLockGroupsPerBackend)
219#define FAST_PATH_SLOT(group, index) \
220 (AssertMacro((uint32) (group) < FastPathLockGroupsPerBackend), \
221 AssertMacro((uint32) (index) < FP_LOCK_SLOTS_PER_GROUP), \
222 ((group) * FP_LOCK_SLOTS_PER_GROUP + (index)))
228#define FAST_PATH_GROUP(index) \
229 (AssertMacro((uint32) (index) < FP_LOCK_SLOTS_PER_BACKEND), \
230 ((index) / FP_LOCK_SLOTS_PER_GROUP))
231#define FAST_PATH_INDEX(index) \
232 (AssertMacro((uint32) (index) < FP_LOCK_SLOTS_PER_BACKEND), \
233 ((index) % FP_LOCK_SLOTS_PER_GROUP))
236#define FAST_PATH_BITS_PER_SLOT 3
237#define FAST_PATH_LOCKNUMBER_OFFSET 1
238#define FAST_PATH_MASK ((1 << FAST_PATH_BITS_PER_SLOT) - 1)
239#define FAST_PATH_BITS(proc, n) (proc)->fpLockBits[FAST_PATH_GROUP(n)]
240#define FAST_PATH_GET_BITS(proc, n) \
241 ((FAST_PATH_BITS(proc, n) >> (FAST_PATH_BITS_PER_SLOT * FAST_PATH_INDEX(n))) & FAST_PATH_MASK)
242#define FAST_PATH_BIT_POSITION(n, l) \
243 (AssertMacro((l) >= FAST_PATH_LOCKNUMBER_OFFSET), \
244 AssertMacro((l) < FAST_PATH_BITS_PER_SLOT+FAST_PATH_LOCKNUMBER_OFFSET), \
245 AssertMacro((n) < FP_LOCK_SLOTS_PER_BACKEND), \
246 ((l) - FAST_PATH_LOCKNUMBER_OFFSET + FAST_PATH_BITS_PER_SLOT * (FAST_PATH_INDEX(n))))
247#define FAST_PATH_SET_LOCKMODE(proc, n, l) \
248 FAST_PATH_BITS(proc, n) |= UINT64CONST(1) << FAST_PATH_BIT_POSITION(n, l)
249#define FAST_PATH_CLEAR_LOCKMODE(proc, n, l) \
250 FAST_PATH_BITS(proc, n) &= ~(UINT64CONST(1) << FAST_PATH_BIT_POSITION(n, l))
251#define FAST_PATH_CHECK_LOCKMODE(proc, n, l) \
252 (FAST_PATH_BITS(proc, n) & (UINT64CONST(1) << FAST_PATH_BIT_POSITION(n, l)))
262#define EligibleForRelationFastPath(locktag, mode) \
263 ((locktag)->locktag_lockmethodid == DEFAULT_LOCKMETHOD && \
264 (locktag)->locktag_type == LOCKTAG_RELATION && \
265 (locktag)->locktag_field1 == MyDatabaseId && \
266 MyDatabaseId != InvalidOid && \
267 (mode) < ShareUpdateExclusiveLock)
268#define ConflictsWithRelationFastPath(locktag, mode) \
269 ((locktag)->locktag_lockmethodid == DEFAULT_LOCKMETHOD && \
270 (locktag)->locktag_type == LOCKTAG_RELATION && \
271 (locktag)->locktag_field1 != InvalidOid && \
272 (mode) > ShareUpdateExclusiveLock)
295#define FAST_PATH_STRONG_LOCK_HASH_BITS 10
296#define FAST_PATH_STRONG_LOCK_HASH_PARTITIONS \
297 (1 << FAST_PATH_STRONG_LOCK_HASH_BITS)
298#define FastPathStrongLockHashPartition(hashcode) \
299 ((hashcode) % FAST_PATH_STRONG_LOCK_HASH_PARTITIONS)
347bool Trace_locks =
false;
348bool Trace_userlocks =
false;
349int Trace_lock_table = 0;
350bool Debug_deadlocks =
false;
354LOCK_DEBUG_ENABLED(
const LOCKTAG *tag)
359 || (Trace_lock_table &&
367 if (LOCK_DEBUG_ENABLED(&lock->
tag))
369 "%s: lock(%p) id(%u,%u,%u,%u,%u,%u) grantMask(%x) "
370 "req(%d,%d,%d,%d,%d,%d,%d)=%d "
371 "grant(%d,%d,%d,%d,%d,%d,%d)=%d wait(%d) type(%s)",
393 "%s: proclock(%p) lock(%p) method(%u) proc(%p) hold(%x)",
400#define LOCK_PRINT(where, lock, type) ((void) 0)
401#define PROCLOCK_PRINT(where, proclockP) ((void) 0)
422 bool decrement_strong_lock_count);
441 long init_table_size,
450 init_table_size = max_table_size / 2;
468 init_table_size *= 2;
601 uint32 lockhash = hashcode;
646 MemSet(&localtag, 0,
sizeof(localtag));
647 localtag.
lock = *locktag;
648 localtag.
mode = lockmode;
654 if (locallock && locallock->
nLocks > 0)
661 for (slockmode = lockmode + 1;
673#ifdef USE_ASSERT_CHECKING
679GetLockMethodLocalHash(
void)
699 bool hasWaiters =
false;
702 elog(
ERROR,
"unrecognized lock method: %d", lockmethodid);
704 if (lockmode <= 0 || lockmode > lockMethodTable->
numLockModes)
705 elog(
ERROR,
"unrecognized lock mode: %d", lockmode);
708 if (LOCK_DEBUG_ENABLED(locktag))
709 elog(
LOG,
"LockHasWaiters: lock [%u,%u] %s",
717 MemSet(&localtag, 0,
sizeof(localtag));
718 localtag.
lock = *locktag;
719 localtag.
mode = lockmode;
728 if (!locallock || locallock->
nLocks <= 0)
747 lock = locallock->
lock;
748 LOCK_PRINT(
"LockHasWaiters: found", lock, lockmode);
831 bool reportMemoryError,
846 bool log_lock =
false;
849 elog(
ERROR,
"unrecognized lock method: %d", lockmethodid);
851 if (lockmode <= 0 || lockmode > lockMethodTable->
numLockModes)
852 elog(
ERROR,
"unrecognized lock mode: %d", lockmode);
859 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
860 errmsg(
"cannot acquire lock mode %s on database objects while recovery is in progress",
862 errhint(
"Only RowExclusiveLock or less can be acquired on database objects during recovery.")));
865 if (LOCK_DEBUG_ENABLED(locktag))
866 elog(
LOG,
"LockAcquire: lock [%u,%u] %s",
880 MemSet(&localtag, 0,
sizeof(localtag));
881 localtag.
lock = *locktag;
882 localtag.
mode = lockmode;
893 locallock->
lock = NULL;
922 *locallockp = locallock;
930 if (locallock->
nLocks > 0)
944 Assert(!IsRelationExtensionLockHeld);
1003 locallock->
lock = NULL;
1025 if (locallock->
nLocks == 0)
1029 if (reportMemoryError)
1031 (
errcode(ERRCODE_OUT_OF_MEMORY),
1032 errmsg(
"out of shared memory"),
1033 errhint(
"You might need to increase \"%s\".",
"max_locks_per_transaction")));
1058 hashcode, lockmode);
1063 if (locallock->
nLocks == 0)
1067 if (reportMemoryError)
1069 (
errcode(ERRCODE_OUT_OF_MEMORY),
1070 errmsg(
"out of shared memory"),
1071 errhint(
"You might need to increase \"%s\".",
"max_locks_per_transaction")));
1077 locallock->
lock = lock;
1085 found_conflict =
true;
1090 if (!found_conflict)
1103 waitResult =
JoinWaitQueue(locallock, lockMethodTable, dontWait);
1120 uint32 proclock_hashcode;
1131 elog(
PANIC,
"proclock table corrupted");
1134 PROCLOCK_PRINT(
"LockAcquire: did not join wait queue", proclock);
1137 LOCK_PRINT(
"LockAcquire: did not join wait queue",
1143 if (locallock->
nLocks == 0)
1167 LOCK_PRINT(
"LockAcquire: sleeping on lock", lock, lockmode);
1238 uint32 proclock_hashcode;
1265 LOCK_PRINT(
"LockAcquire: new", lock, lockmode);
1269 LOCK_PRINT(
"LockAcquire: found", lock, lockmode);
1278 proclocktag.
myLock = lock;
1279 proclocktag.
myProc = proc;
1344#ifdef CHECK_DEADLOCK_RISK
1367 if (
i >= (
int) lockmode)
1369 elog(
LOG,
"deadlock risk: raising lock level"
1370 " from %s to %s on object %u/%u/%u",
1396 elog(
ERROR,
"lock %s on object %u/%u/%u is already held",
1415#ifdef USE_ASSERT_CHECKING
1417 IsRelationExtensionLockHeld = acquired;
1485 int conflictMask = lockMethodTable->
conflictTab[lockmode];
1487 int totalConflictsRemaining = 0;
1512 for (
i = 1;
i <= numLockModes;
i++)
1516 conflictsRemaining[
i] = 0;
1519 conflictsRemaining[
i] = lock->
granted[
i];
1521 --conflictsRemaining[
i];
1522 totalConflictsRemaining += conflictsRemaining[
i];
1526 if (totalConflictsRemaining == 0)
1528 PROCLOCK_PRINT(
"LockCheckConflicts: resolved (simple)", proclock);
1564 if (proclock != otherproclock &&
1566 (otherproclock->
holdMask & conflictMask) != 0)
1568 int intersectMask = otherproclock->
holdMask & conflictMask;
1570 for (
i = 1;
i <= numLockModes;
i++)
1574 if (conflictsRemaining[
i] <= 0)
1575 elog(
PANIC,
"proclocks held do not match lock");
1576 conflictsRemaining[
i]--;
1577 totalConflictsRemaining--;
1581 if (totalConflictsRemaining == 0)
1591 PROCLOCK_PRINT(
"LockCheckConflicts: conflicting (group)", proclock);
1633 bool wakeupNeeded =
false;
1647 if (lock->
granted[lockmode] == 0)
1653 LOCK_PRINT(
"UnGrantLock: updated", lock, lockmode);
1665 wakeupNeeded =
true;
1673 return wakeupNeeded;
1697 uint32 proclock_hashcode;
1708 elog(
PANIC,
"proclock table corrupted");
1717 LOCK_PRINT(
"CleanUpLock: deleting", lock, 0);
1726 else if (wakeupNeeded)
1752 if (lockOwners[
i].owner == owner)
1758 lockOwners[
i].
owner = owner;
1814 if (locallock == NULL)
2023 elog(
ERROR,
"unrecognized lock method: %d", lockmethodid);
2025 if (lockmode <= 0 || lockmode > lockMethodTable->
numLockModes)
2026 elog(
ERROR,
"unrecognized lock mode: %d", lockmode);
2029 if (LOCK_DEBUG_ENABLED(locktag))
2030 elog(
LOG,
"LockRelease: lock [%u,%u] %s",
2038 MemSet(&localtag, 0,
sizeof(localtag));
2039 localtag.
lock = *locktag;
2040 localtag.
mode = lockmode;
2049 if (!locallock || locallock->
nLocks <= 0)
2072 if (lockOwners[
i].owner == owner)
2074 Assert(lockOwners[
i].nLocks > 0);
2075 if (--lockOwners[
i].nLocks == 0)
2081 if (i < locallock->numLockOwners)
2102 if (locallock->
nLocks > 0)
2150 lock = locallock->
lock;
2162 elog(
ERROR,
"failed to re-find shared lock object");
2163 locallock->
lock = lock;
2165 proclocktag.
myLock = lock;
2172 elog(
ERROR,
"failed to re-find shared proclock object");
2174 LOCK_PRINT(
"LockRelease: found", lock, lockmode);
2195 wakeupNeeded =
UnGrantLock(lock, lockmode, proclock, lockMethodTable);
2198 lockMethodTable, locallock->
hashcode,
2225 bool have_fast_path_lwlock =
false;
2228 elog(
ERROR,
"unrecognized lock method: %d", lockmethodid);
2233 elog(
LOG,
"LockReleaseAll: lockmethod=%d", lockmethodid);
2263 if (locallock->
nLocks == 0)
2285 if (lockOwners[
i].owner == NULL)
2286 lockOwners[0] = lockOwners[
i];
2292 lockOwners[0].
owner == NULL &&
2293 lockOwners[0].
nLocks > 0)
2305#ifdef USE_ASSERT_CHECKING
2319 if (locallock->
proclock == NULL || locallock->
lock == NULL)
2326 elog(
PANIC,
"locallock table corrupted");
2336 if (!have_fast_path_lwlock)
2339 have_fast_path_lwlock =
true;
2356 have_fast_path_lwlock =
false;
2366 &locallock->
tag.
lock, lockmode,
false);
2372 if (locallock->
nLocks > 0)
2380 if (have_fast_path_lwlock)
2421 bool wakeupNeeded =
false;
2457 for (
i = 1;
i <= numLockModes;
i++)
2465 LOCK_PRINT(
"LockReleaseAll: updated", lock, 0);
2481 elog(
LOG,
"LockReleaseAll done");
2496 elog(
ERROR,
"unrecognized lock method: %d", lockmethodid);
2522 if (locallocks == NULL)
2536 for (
i = nlocks - 1;
i >= 0;
i--)
2571 if (lockOwners[
i].owner == owner)
2573 Assert(lockOwners[
i].nLocks > 0);
2574 if (lockOwners[
i].nLocks < locallock->nLocks)
2585 if (i < locallock->numLockOwners)
2621 if (locallocks == NULL)
2635 for (
i = nlocks - 1;
i >= 0;
i--)
2661 else if (lockOwners[
i].owner == parent)
2671 lockOwners[ic].
owner = parent;
2680 if (ic < locallock->numLockOwners)
2737 bool result =
false;
2837 hashcode, lockmode);
2892 lockmode = locallock->
tag.
mode;
2906 (
errcode(ERRCODE_OUT_OF_MEMORY),
2907 errmsg(
"out of shared memory"),
2908 errhint(
"You might need to increase \"%s\".",
"max_locks_per_transaction")));
2922 if (proclock == NULL)
2926 uint32 proclock_hashcode;
2936 elog(
ERROR,
"failed to re-find shared lock object");
2938 proclocktag.
myLock = lock;
2949 elog(
ERROR,
"failed to re-find shared proclock object");
2991 elog(
ERROR,
"unrecognized lock method: %d", lockmethodid);
2993 if (lockmode <= 0 || lockmode > lockMethodTable->
numLockModes)
2994 elog(
ERROR,
"unrecognized lock mode: %d", lockmode);
3017 conflictMask = lockMethodTable->
conflictTab[lockmode];
3077 if (relid != proc->
fpRelId[f])
3088 if ((lockmask & conflictMask) == 0)
3095 vxids[count++] = vxid;
3140 if (conflictMask & proclock->
holdMask)
3156 for (
i = 0;
i < fast_count; ++
i)
3159 if (
i >= fast_count)
3160 vxids[count++] = vxid;
3170 elog(
PANIC,
"too many conflicting locks found");
3193 bool decrement_strong_lock_count)
3199 uint32 proclock_hashcode;
3217 elog(
PANIC,
"failed to re-find shared lock object");
3222 proclocktag.
myLock = lock;
3223 proclocktag.
myProc = proc;
3233 elog(
PANIC,
"failed to re-find shared proclock object");
3251 wakeupNeeded =
UnGrantLock(lock, lockmode, proclock, lockMethodTable);
3254 lockMethodTable, hashcode,
3262 if (decrement_strong_lock_count
3311 hash_ctl.
entrysize =
sizeof(PerLockTagEntry);
3314 lockhtab =
hash_create(
"CheckForSessionAndXactLocks table",
3325 PerLockTagEntry *hentry;
3337 if (locallock->
nLocks <= 0)
3341 hentry = (PerLockTagEntry *)
hash_search(lockhtab,
3345 hentry->sessLock = hentry->xactLock =
false;
3350 if (lockOwners[
i].owner == NULL)
3351 hentry->sessLock =
true;
3353 hentry->xactLock =
true;
3360 if (hentry->sessLock && hentry->xactLock)
3362 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3363 errmsg(
"cannot PREPARE while holding both session-level and transaction-level locks on the same object")));
3398 bool haveSessionLock;
3410 if (locallock->
nLocks <= 0)
3414 haveSessionLock = haveXactLock =
false;
3417 if (lockOwners[
i].owner == NULL)
3418 haveSessionLock =
true;
3420 haveXactLock =
true;
3428 if (haveSessionLock)
3430 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3431 errmsg(
"cannot PREPARE while holding both session-level and transaction-level locks on the same object")));
3510 bool haveSessionLock;
3514 if (locallock->
proclock == NULL || locallock->
lock == NULL)
3530 haveSessionLock = haveXactLock =
false;
3533 if (lockOwners[
i].owner == NULL)
3534 haveSessionLock =
true;
3536 haveXactLock =
true;
3544 if (haveSessionLock)
3546 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3547 errmsg(
"cannot PREPARE while holding both session-level and transaction-level locks on the same object")));
3550 if (locallock->
nLocks > 0)
3606 elog(
PANIC,
"we seem to have dropped a bit somewhere");
3626 proclocktag.
myLock = lock;
3627 proclocktag.
myProc = newproc;
3644 elog(
PANIC,
"duplicate entry found while reassigning a prepared transaction's locks");
3666 long max_table_size;
3673 max_table_size *= 2;
3761 instance = &
data->locks[el];
3768 instance->
pid = proc->
pid;
3797 instance = &
data->locks[el];
3803 instance->
pid = proc->
pid;
3832 if (
data->nelements > els)
3834 els =
data->nelements;
3856 instance->
pid = proc->
pid;
3993 if (theLock == NULL)
3997 bproc = &
data->procs[
data->nprocs++];
3998 bproc->
pid = blocked_proc->
pid;
4016 if (
data->nlocks >=
data->maxlocks)
4023 instance = &
data->locks[
data->nlocks];
4032 instance->
pid = proc->
pid;
4042 if (queue_size >
data->maxpids -
data->npids)
4045 data->npids + queue_size);
4047 sizeof(
int) *
data->maxpids);
4055 if (queued_proc == blocked_proc)
4057 data->waiter_pids[
data->npids++] = queued_proc->
pid;
4134 accessExclusiveLocks[
index].
xid = xid;
4155 return accessExclusiveLocks;
4229 elog(
LOG,
"DumpAllLocks: proclock->tag.myLock = NULL");
4277 uint32 proclock_hashcode;
4288 elog(
ERROR,
"unrecognized lock method: %d", lockmethodid);
4309 (
errcode(ERRCODE_OUT_OF_MEMORY),
4310 errmsg(
"out of shared memory"),
4311 errhint(
"You might need to increase \"%s\".",
"max_locks_per_transaction")));
4327 LOCK_PRINT(
"lock_twophase_recover: new", lock, lockmode);
4331 LOCK_PRINT(
"lock_twophase_recover: found", lock, lockmode);
4340 proclocktag.
myLock = lock;
4341 proclocktag.
myProc = proc;
4374 (
errcode(ERRCODE_OUT_OF_MEMORY),
4375 errmsg(
"out of shared memory"),
4376 errhint(
"You might need to increase \"%s\".",
"max_locks_per_transaction")));
4412 elog(
ERROR,
"lock %s on object %u/%u/%u is already held",
4459 elog(
ERROR,
"unrecognized lock method: %d", lockmethodid);
4491 elog(
ERROR,
"unrecognized lock method: %d", lockmethodid);
4724 (
errcode(ERRCODE_OUT_OF_MEMORY),
4725 errmsg(
"out of shared memory"),
4726 errhint(
"You might need to increase \"%s\".",
"max_locks_per_transaction")));
4771 elog(
ERROR,
"unrecognized lock method: %d", lockmethodid);
static uint64 pg_atomic_read_u64(volatile pg_atomic_uint64 *ptr)
#define Assert(condition)
uint32 LocalTransactionId
#define MemSet(start, val, len)
void DeadLockReport(void)
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
void hash_destroy(HTAB *hashp)
void * hash_search_with_hash_value(HTAB *hashp, const void *keyPtr, uint32 hashvalue, HASHACTION action, bool *foundPtr)
void * hash_seq_search(HASH_SEQ_STATUS *status)
long hash_get_num_entries(HTAB *hashp)
Size hash_estimate_size(long num_entries, Size entrysize)
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
bool hash_update_hash_key(HTAB *hashp, void *existingEntry, const void *newKeyPtr)
uint32 get_hash_value(HTAB *hashp, const void *keyPtr)
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
#define dlist_foreach(iter, lhead)
static void dlist_init(dlist_head *head)
static void dlist_delete(dlist_node *node)
static uint32 dclist_count(const dclist_head *head)
static bool dclist_is_empty(const dclist_head *head)
#define dlist_foreach_modify(iter, lhead)
static bool dlist_is_empty(const dlist_head *head)
static void dlist_push_tail(dlist_head *head, dlist_node *node)
static void dclist_delete_from_thoroughly(dclist_head *head, dlist_node *node)
static void dclist_init(dclist_head *head)
#define dlist_container(type, membername, ptr)
#define dclist_foreach(iter, lhead)
static bool XactLockForVirtualXact(VirtualTransactionId vxid, TransactionId xid, bool wait)
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
static LOCALLOCK * awaitedLock
static void RemoveLocalLock(LOCALLOCK *locallock)
LockAcquireResult LockAcquireExtended(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait, bool reportMemoryError, LOCALLOCK **locallockp)
static void LockReassignOwner(LOCALLOCK *locallock, ResourceOwner parent)
bool LockHeldByMe(const LOCKTAG *locktag, LOCKMODE lockmode, bool orstronger)
static const char *const lock_mode_names[]
#define LOCK_PRINT(where, lock, type)
bool DoLockModesConflict(LOCKMODE mode1, LOCKMODE mode2)
static PROCLOCK * SetupLockInTable(LockMethod lockMethodTable, PGPROC *proc, const LOCKTAG *locktag, uint32 hashcode, LOCKMODE lockmode)
static PROCLOCK * FastPathGetRelationLockEntry(LOCALLOCK *locallock)
void VirtualXactLockTableInsert(VirtualTransactionId vxid)
#define FastPathStrongLockHashPartition(hashcode)
static uint32 ProcLockHashCode(const PROCLOCKTAG *proclocktag, uint32 hashcode)
#define FAST_PATH_CHECK_LOCKMODE(proc, n, l)
void GrantAwaitedLock(void)
int LockWaiterCount(const LOCKTAG *locktag)
void AtPrepare_Locks(void)
bool LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
void lock_twophase_postcommit(TransactionId xid, uint16 info, void *recdata, uint32 len)
#define FAST_PATH_LOCKNUMBER_OFFSET
Size LockManagerShmemSize(void)
#define FAST_PATH_REL_GROUP(rel)
void InitLockManagerAccess(void)
void GrantLock(LOCK *lock, PROCLOCK *proclock, LOCKMODE lockmode)
void VirtualXactLockTableCleanup(void)
bool VirtualXactLock(VirtualTransactionId vxid, bool wait)
VirtualTransactionId * GetLockConflicts(const LOCKTAG *locktag, LOCKMODE lockmode, int *countp)
static volatile FastPathStrongRelationLockData * FastPathStrongRelationLocks
void RemoveFromWaitQueue(PGPROC *proc, uint32 hashcode)
void LockReleaseAll(LOCKMETHODID lockmethodid, bool allLocks)
#define FAST_PATH_SLOT(group, index)
static void CheckAndSetLockHeld(LOCALLOCK *locallock, bool acquired)
#define ConflictsWithRelationFastPath(locktag, mode)
static bool FastPathTransferRelationLocks(LockMethod lockMethodTable, const LOCKTAG *locktag, uint32 hashcode)
static HTAB * LockMethodLocalHash
void LockReassignCurrentOwner(LOCALLOCK **locallocks, int nlocks)
static bool UnGrantLock(LOCK *lock, LOCKMODE lockmode, PROCLOCK *proclock, LockMethod lockMethodTable)
#define FAST_PATH_SET_LOCKMODE(proc, n, l)
#define PROCLOCK_PRINT(where, proclockP)
static void CleanUpLock(LOCK *lock, PROCLOCK *proclock, LockMethod lockMethodTable, uint32 hashcode, bool wakeupNeeded)
static uint32 proclock_hash(const void *key, Size keysize)
static bool FastPathUnGrantRelationLock(Oid relid, LOCKMODE lockmode)
void AbortStrongLockAcquire(void)
static bool FastPathGrantRelationLock(Oid relid, LOCKMODE lockmode)
static int FastPathLocalUseCounts[FP_LOCK_GROUPS_PER_BACKEND_MAX]
static HTAB * LockMethodLockHash
static ResourceOwner awaitedOwner
BlockedProcsData * GetBlockerStatusData(int blocked_pid)
void LockManagerShmemInit(void)
void lock_twophase_postabort(TransactionId xid, uint16 info, void *recdata, uint32 len)
static ProcWaitStatus WaitOnLock(LOCALLOCK *locallock, ResourceOwner owner)
bool LockHasWaiters(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
const char * GetLockmodeName(LOCKMETHODID lockmethodid, LOCKMODE mode)
static void GetSingleProcBlockerStatusData(PGPROC *blocked_proc, BlockedProcsData *data)
#define FAST_PATH_CLEAR_LOCKMODE(proc, n, l)
static const LockMethod LockMethods[]
void lock_twophase_standby_recover(TransactionId xid, uint16 info, void *recdata, uint32 len)
void LockReleaseCurrentOwner(LOCALLOCK **locallocks, int nlocks)
LOCALLOCK * GetAwaitedLock(void)
void lock_twophase_recover(TransactionId xid, uint16 info, void *recdata, uint32 len)
void LockReleaseSession(LOCKMETHODID lockmethodid)
void MarkLockClear(LOCALLOCK *locallock)
LockData * GetLockStatusData(void)
static bool IsRelationExtensionLockHeld PG_USED_FOR_ASSERTS_ONLY
static const LockMethodData default_lockmethod
#define FAST_PATH_GET_BITS(proc, n)
static LOCALLOCK * StrongLockInProgress
#define FAST_PATH_BITS_PER_SLOT
static const LockMethodData user_lockmethod
int FastPathLockGroupsPerBackend
#define EligibleForRelationFastPath(locktag, mode)
uint32 LockTagHashCode(const LOCKTAG *locktag)
static void BeginStrongLockAcquire(LOCALLOCK *locallock, uint32 fasthashcode)
bool LockCheckConflicts(LockMethod lockMethodTable, LOCKMODE lockmode, LOCK *lock, PROCLOCK *proclock)
static void GrantLockLocal(LOCALLOCK *locallock, ResourceOwner owner)
static const LOCKMASK LockConflicts[]
static void ReleaseLockIfHeld(LOCALLOCK *locallock, bool sessionLock)
LockMethod GetLocksMethodTable(const LOCK *lock)
static void FinishStrongLockAcquire(void)
#define FAST_PATH_STRONG_LOCK_HASH_PARTITIONS
void PostPrepare_Locks(TransactionId xid)
xl_standby_lock * GetRunningTransactionLocks(int *nlocks)
static void LockRefindAndRelease(LockMethod lockMethodTable, PGPROC *proc, LOCKTAG *locktag, LOCKMODE lockmode, bool decrement_strong_lock_count)
static void CheckForSessionAndXactLocks(void)
static HTAB * LockMethodProcLockHash
struct TwoPhaseLockRecord TwoPhaseLockRecord
LockMethod GetLockTagsMethodTable(const LOCKTAG *locktag)
#define DEFAULT_LOCKMETHOD
struct LOCALLOCK LOCALLOCK
#define LOCK_LOCKTAG(lock)
#define SET_LOCKTAG_VIRTUALTRANSACTION(locktag, vxid)
@ LOCKTAG_RELATION_EXTEND
@ LOCKTAG_VIRTUALTRANSACTION
#define VirtualTransactionIdIsValid(vxid)
#define LockHashPartitionLock(hashcode)
#define GET_VXID_FROM_PGPROC(vxid_dst, proc)
#define LOCK_LOCKMETHOD(lock)
#define LOCKBIT_OFF(lockmode)
#define LOCALLOCK_LOCKMETHOD(llock)
#define InvalidLocalTransactionId
#define SET_LOCKTAG_TRANSACTION(locktag, xid)
#define SET_LOCKTAG_RELATION(locktag, dboid, reloid)
struct PROCLOCKTAG PROCLOCKTAG
#define LOCKBIT_ON(lockmode)
#define LocalTransactionIdIsValid(lxid)
#define LOCALLOCK_LOCKTAG(llock)
#define LockHashPartition(hashcode)
#define VirtualTransactionIdEquals(vxid1, vxid2)
struct LOCALLOCKTAG LOCALLOCKTAG
#define PROCLOCK_LOCKMETHOD(proclock)
#define LockHashPartitionLockByIndex(i)
@ LOCKACQUIRE_ALREADY_CLEAR
@ LOCKACQUIRE_ALREADY_HELD
#define VirtualTransactionIdIsRecoveredPreparedXact(vxid)
#define AccessExclusiveLock
#define ShareRowExclusiveLock
#define ShareUpdateExclusiveLock
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
void LWLockRelease(LWLock *lock)
#define NUM_LOCK_PARTITIONS
#define LOG2_NUM_LOCK_PARTITIONS
void * MemoryContextAlloc(MemoryContext context, Size size)
void * repalloc(void *pointer, Size size)
void pfree(void *pointer)
void * palloc0(Size size)
MemoryContext TopMemoryContext
MemoryContext CurrentMemoryContext
#define START_CRIT_SECTION()
#define END_CRIT_SECTION()
static PgChecksumMode mode
static Datum PointerGetDatum(const void *X)
#define FP_LOCK_GROUPS_PER_BACKEND_MAX
#define FP_LOCK_SLOTS_PER_BACKEND
#define FP_LOCK_SLOTS_PER_GROUP
@ PROC_WAIT_STATUS_WAITING
PGPROC * BackendPidGetProcWithLock(int pid)
PGPROC * ProcNumberGetProc(ProcNumber procNumber)
#define INVALID_PROC_NUMBER
void set_ps_display_remove_suffix(void)
void set_ps_display_suffix(const char *suffix)
void ResourceOwnerRememberLock(ResourceOwner owner, LOCALLOCK *locallock)
ResourceOwner ResourceOwnerGetParent(ResourceOwner owner)
ResourceOwner CurrentResourceOwner
void ResourceOwnerForgetLock(ResourceOwner owner, LOCALLOCK *locallock)
HTAB * ShmemInitHash(const char *name, long init_size, long max_size, HASHCTL *infoP, int hash_flags)
Size add_size(Size s1, Size s2)
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
static pg_noinline void Size size
#define SpinLockInit(lock)
#define SpinLockRelease(lock)
#define SpinLockAcquire(lock)
ProcWaitStatus JoinWaitQueue(LOCALLOCK *locallock, LockMethod lockMethodTable, bool dontWait)
ProcWaitStatus ProcSleep(LOCALLOCK *locallock)
void ProcLockWakeup(LockMethod lockMethodTable, LOCK *lock)
void LogAccessExclusiveLockPrepare(void)
void StandbyAcquireAccessExclusiveLock(TransactionId xid, Oid dbOid, Oid relOid)
void LogAccessExclusiveLock(Oid dbOid, Oid relOid)
uint32 count[FAST_PATH_STRONG_LOCK_HASH_PARTITIONS]
struct ResourceOwnerData * owner
LOCALLOCKOWNER * lockOwners
bool holdsStrongLockCount
uint8 locktag_lockmethodid
int requested[MAX_LOCKMODES]
int granted[MAX_LOCKMODES]
VirtualTransactionId vxid
const LOCKMASK * conflictTab
const char *const * lockModeNames
dlist_head lockGroupMembers
pg_atomic_uint64 waitStart
LocalTransactionId fpLocalTransactionId
dlist_head myProcLocks[NUM_LOCK_PARTITIONS]
ProcWaitStatus waitStatus
LocalTransactionId localTransactionId
#define InvalidTransactionId
#define FirstNormalObjectId
#define TransactionIdIsValid(xid)
void RegisterTwoPhaseRecord(TwoPhaseRmgrId rmid, uint16 info, const void *data, uint32 len)
TransactionId TwoPhaseGetXidByVirtualXID(VirtualTransactionId vxid, bool *have_more)
PGPROC * TwoPhaseGetDummyProc(TransactionId xid, bool lock_held)
#define TWOPHASE_RM_LOCK_ID
bool RecoveryInProgress(void)
#define XLogStandbyInfoActive()
static struct link * links