PostgreSQL Source Code  git master
lockfuncs.c File Reference
#include "postgres.h"
#include "access/htup_details.h"
#include "access/xact.h"
#include "catalog/pg_type.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "storage/predicate_internals.h"
#include "utils/array.h"
#include "utils/builtins.h"
Include dependency graph for lockfuncs.c:

Go to the source code of this file.

Data Structures

struct  PG_Lock_Status
 

Macros

#define NUM_LOCK_STATUS_COLUMNS   16
 
#define SET_LOCKTAG_INT64(tag, key64)
 
#define SET_LOCKTAG_INT32(tag, key1, key2)    SET_LOCKTAG_ADVISORY(tag, MyDatabaseId, key1, key2, 2)
 

Functions

 StaticAssertDecl (lengthof(LockTagTypeNames)==(LOCKTAG_LAST_TYPE+1), "array length mismatch")
 
 StaticAssertDecl (lengthof(PredicateLockTagTypeNames)==(PREDLOCKTAG_TUPLE+1), "array length mismatch")
 
static Datum VXIDGetDatum (BackendId bid, LocalTransactionId lxid)
 
Datum pg_lock_status (PG_FUNCTION_ARGS)
 
Datum pg_blocking_pids (PG_FUNCTION_ARGS)
 
Datum pg_safe_snapshot_blocking_pids (PG_FUNCTION_ARGS)
 
Datum pg_isolation_test_session_is_blocked (PG_FUNCTION_ARGS)
 
Datum pg_advisory_lock_int8 (PG_FUNCTION_ARGS)
 
Datum pg_advisory_xact_lock_int8 (PG_FUNCTION_ARGS)
 
Datum pg_advisory_lock_shared_int8 (PG_FUNCTION_ARGS)
 
Datum pg_advisory_xact_lock_shared_int8 (PG_FUNCTION_ARGS)
 
Datum pg_try_advisory_lock_int8 (PG_FUNCTION_ARGS)
 
Datum pg_try_advisory_xact_lock_int8 (PG_FUNCTION_ARGS)
 
Datum pg_try_advisory_lock_shared_int8 (PG_FUNCTION_ARGS)
 
Datum pg_try_advisory_xact_lock_shared_int8 (PG_FUNCTION_ARGS)
 
Datum pg_advisory_unlock_int8 (PG_FUNCTION_ARGS)
 
Datum pg_advisory_unlock_shared_int8 (PG_FUNCTION_ARGS)
 
Datum pg_advisory_lock_int4 (PG_FUNCTION_ARGS)
 
Datum pg_advisory_xact_lock_int4 (PG_FUNCTION_ARGS)
 
Datum pg_advisory_lock_shared_int4 (PG_FUNCTION_ARGS)
 
Datum pg_advisory_xact_lock_shared_int4 (PG_FUNCTION_ARGS)
 
Datum pg_try_advisory_lock_int4 (PG_FUNCTION_ARGS)
 
Datum pg_try_advisory_xact_lock_int4 (PG_FUNCTION_ARGS)
 
Datum pg_try_advisory_lock_shared_int4 (PG_FUNCTION_ARGS)
 
Datum pg_try_advisory_xact_lock_shared_int4 (PG_FUNCTION_ARGS)
 
Datum pg_advisory_unlock_int4 (PG_FUNCTION_ARGS)
 
Datum pg_advisory_unlock_shared_int4 (PG_FUNCTION_ARGS)
 
Datum pg_advisory_unlock_all (PG_FUNCTION_ARGS)
 

Variables

const char *const LockTagTypeNames []
 
static const char *const PredicateLockTagTypeNames []
 

Macro Definition Documentation

◆ NUM_LOCK_STATUS_COLUMNS

#define NUM_LOCK_STATUS_COLUMNS   16

Definition at line 67 of file lockfuncs.c.

◆ SET_LOCKTAG_INT32

#define SET_LOCKTAG_INT32 (   tag,
  key1,
  key2 
)     SET_LOCKTAG_ADVISORY(tag, MyDatabaseId, key1, key2, 2)

Definition at line 697 of file lockfuncs.c.

◆ SET_LOCKTAG_INT64

#define SET_LOCKTAG_INT64 (   tag,
  key64 
)
Value:
(uint32) ((key64) >> 32), \
(uint32) (key64), \
1)
unsigned int uint32
Definition: c.h:490
Oid MyDatabaseId
Definition: globals.c:89
#define SET_LOCKTAG_ADVISORY(locktag, id1, id2, id3, id4)
Definition: lock.h:270

Definition at line 691 of file lockfuncs.c.

Function Documentation

◆ pg_advisory_lock_int4()

Datum pg_advisory_lock_int4 ( PG_FUNCTION_ARGS  )

Definition at line 886 of file lockfuncs.c.

887 {
888  int32 key1 = PG_GETARG_INT32(0);
889  int32 key2 = PG_GETARG_INT32(1);
890  LOCKTAG tag;
891 
892  SET_LOCKTAG_INT32(tag, key1, key2);
893 
894  (void) LockAcquire(&tag, ExclusiveLock, true, false);
895 
896  PG_RETURN_VOID();
897 }
signed int int32
Definition: c.h:478
#define PG_RETURN_VOID()
Definition: fmgr.h:349
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:747
#define ExclusiveLock
Definition: lockdefs.h:42
#define SET_LOCKTAG_INT32(tag, key1, key2)
Definition: lockfuncs.c:697
Definition: lock.h:165

References ExclusiveLock, LockAcquire(), PG_GETARG_INT32, PG_RETURN_VOID, and SET_LOCKTAG_INT32.

◆ pg_advisory_lock_int8()

Datum pg_advisory_lock_int8 ( PG_FUNCTION_ARGS  )

Definition at line 704 of file lockfuncs.c.

705 {
706  int64 key = PG_GETARG_INT64(0);
707  LOCKTAG tag;
708 
709  SET_LOCKTAG_INT64(tag, key);
710 
711  (void) LockAcquire(&tag, ExclusiveLock, true, false);
712 
713  PG_RETURN_VOID();
714 }
#define PG_GETARG_INT64(n)
Definition: fmgr.h:283
#define SET_LOCKTAG_INT64(tag, key64)
Definition: lockfuncs.c:691

References ExclusiveLock, sort-test::key, LockAcquire(), PG_GETARG_INT64, PG_RETURN_VOID, and SET_LOCKTAG_INT64.

Referenced by delay_execution_planner().

◆ pg_advisory_lock_shared_int4()

Datum pg_advisory_lock_shared_int4 ( PG_FUNCTION_ARGS  )

Definition at line 921 of file lockfuncs.c.

922 {
923  int32 key1 = PG_GETARG_INT32(0);
924  int32 key2 = PG_GETARG_INT32(1);
925  LOCKTAG tag;
926 
927  SET_LOCKTAG_INT32(tag, key1, key2);
928 
929  (void) LockAcquire(&tag, ShareLock, true, false);
930 
931  PG_RETURN_VOID();
932 }
#define ShareLock
Definition: lockdefs.h:40

References LockAcquire(), PG_GETARG_INT32, PG_RETURN_VOID, SET_LOCKTAG_INT32, and ShareLock.

◆ pg_advisory_lock_shared_int8()

Datum pg_advisory_lock_shared_int8 ( PG_FUNCTION_ARGS  )

Definition at line 737 of file lockfuncs.c.

738 {
739  int64 key = PG_GETARG_INT64(0);
740  LOCKTAG tag;
741 
742  SET_LOCKTAG_INT64(tag, key);
743 
744  (void) LockAcquire(&tag, ShareLock, true, false);
745 
746  PG_RETURN_VOID();
747 }

References sort-test::key, LockAcquire(), PG_GETARG_INT64, PG_RETURN_VOID, SET_LOCKTAG_INT64, and ShareLock.

◆ pg_advisory_unlock_all()

Datum pg_advisory_unlock_all ( PG_FUNCTION_ARGS  )

Definition at line 1078 of file lockfuncs.c.

1079 {
1081 
1082  PG_RETURN_VOID();
1083 }
void LockReleaseSession(LOCKMETHODID lockmethodid)
Definition: lock.c:2419
#define USER_LOCKMETHOD
Definition: lock.h:126

References LockReleaseSession(), PG_RETURN_VOID, and USER_LOCKMETHOD.

◆ pg_advisory_unlock_int4()

Datum pg_advisory_unlock_int4 ( PG_FUNCTION_ARGS  )

Definition at line 1040 of file lockfuncs.c.

1041 {
1042  int32 key1 = PG_GETARG_INT32(0);
1043  int32 key2 = PG_GETARG_INT32(1);
1044  LOCKTAG tag;
1045  bool res;
1046 
1047  SET_LOCKTAG_INT32(tag, key1, key2);
1048 
1049  res = LockRelease(&tag, ExclusiveLock, true);
1050 
1052 }
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
bool LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
Definition: lock.c:1949

References ExclusiveLock, LockRelease(), PG_GETARG_INT32, PG_RETURN_BOOL, res, and SET_LOCKTAG_INT32.

◆ pg_advisory_unlock_int8()

Datum pg_advisory_unlock_int8 ( PG_FUNCTION_ARGS  )

Definition at line 850 of file lockfuncs.c.

851 {
852  int64 key = PG_GETARG_INT64(0);
853  LOCKTAG tag;
854  bool res;
855 
856  SET_LOCKTAG_INT64(tag, key);
857 
858  res = LockRelease(&tag, ExclusiveLock, true);
859 
861 }

References ExclusiveLock, sort-test::key, LockRelease(), PG_GETARG_INT64, PG_RETURN_BOOL, res, and SET_LOCKTAG_INT64.

Referenced by delay_execution_planner().

◆ pg_advisory_unlock_shared_int4()

Datum pg_advisory_unlock_shared_int4 ( PG_FUNCTION_ARGS  )

Definition at line 1060 of file lockfuncs.c.

1061 {
1062  int32 key1 = PG_GETARG_INT32(0);
1063  int32 key2 = PG_GETARG_INT32(1);
1064  LOCKTAG tag;
1065  bool res;
1066 
1067  SET_LOCKTAG_INT32(tag, key1, key2);
1068 
1069  res = LockRelease(&tag, ShareLock, true);
1070 
1072 }

References LockRelease(), PG_GETARG_INT32, PG_RETURN_BOOL, res, SET_LOCKTAG_INT32, and ShareLock.

◆ pg_advisory_unlock_shared_int8()

Datum pg_advisory_unlock_shared_int8 ( PG_FUNCTION_ARGS  )

Definition at line 869 of file lockfuncs.c.

870 {
871  int64 key = PG_GETARG_INT64(0);
872  LOCKTAG tag;
873  bool res;
874 
875  SET_LOCKTAG_INT64(tag, key);
876 
877  res = LockRelease(&tag, ShareLock, true);
878 
880 }

References sort-test::key, LockRelease(), PG_GETARG_INT64, PG_RETURN_BOOL, res, SET_LOCKTAG_INT64, and ShareLock.

◆ pg_advisory_xact_lock_int4()

Datum pg_advisory_xact_lock_int4 ( PG_FUNCTION_ARGS  )

Definition at line 904 of file lockfuncs.c.

905 {
906  int32 key1 = PG_GETARG_INT32(0);
907  int32 key2 = PG_GETARG_INT32(1);
908  LOCKTAG tag;
909 
910  SET_LOCKTAG_INT32(tag, key1, key2);
911 
912  (void) LockAcquire(&tag, ExclusiveLock, false, false);
913 
914  PG_RETURN_VOID();
915 }

References ExclusiveLock, LockAcquire(), PG_GETARG_INT32, PG_RETURN_VOID, and SET_LOCKTAG_INT32.

◆ pg_advisory_xact_lock_int8()

Datum pg_advisory_xact_lock_int8 ( PG_FUNCTION_ARGS  )

Definition at line 721 of file lockfuncs.c.

722 {
723  int64 key = PG_GETARG_INT64(0);
724  LOCKTAG tag;
725 
726  SET_LOCKTAG_INT64(tag, key);
727 
728  (void) LockAcquire(&tag, ExclusiveLock, false, false);
729 
730  PG_RETURN_VOID();
731 }

References ExclusiveLock, sort-test::key, LockAcquire(), PG_GETARG_INT64, PG_RETURN_VOID, and SET_LOCKTAG_INT64.

◆ pg_advisory_xact_lock_shared_int4()

Datum pg_advisory_xact_lock_shared_int4 ( PG_FUNCTION_ARGS  )

Definition at line 939 of file lockfuncs.c.

940 {
941  int32 key1 = PG_GETARG_INT32(0);
942  int32 key2 = PG_GETARG_INT32(1);
943  LOCKTAG tag;
944 
945  SET_LOCKTAG_INT32(tag, key1, key2);
946 
947  (void) LockAcquire(&tag, ShareLock, false, false);
948 
949  PG_RETURN_VOID();
950 }

References LockAcquire(), PG_GETARG_INT32, PG_RETURN_VOID, SET_LOCKTAG_INT32, and ShareLock.

◆ pg_advisory_xact_lock_shared_int8()

Datum pg_advisory_xact_lock_shared_int8 ( PG_FUNCTION_ARGS  )

Definition at line 754 of file lockfuncs.c.

755 {
756  int64 key = PG_GETARG_INT64(0);
757  LOCKTAG tag;
758 
759  SET_LOCKTAG_INT64(tag, key);
760 
761  (void) LockAcquire(&tag, ShareLock, false, false);
762 
763  PG_RETURN_VOID();
764 }

References sort-test::key, LockAcquire(), PG_GETARG_INT64, PG_RETURN_VOID, SET_LOCKTAG_INT64, and ShareLock.

◆ pg_blocking_pids()

Datum pg_blocking_pids ( PG_FUNCTION_ARGS  )

Definition at line 466 of file lockfuncs.c.

467 {
468  int blocked_pid = PG_GETARG_INT32(0);
469  Datum *arrayelems;
470  int narrayelems;
471  BlockedProcsData *lockData; /* state data from lmgr */
472  int i,
473  j;
474 
475  /* Collect a snapshot of lock manager state */
476  lockData = GetBlockerStatusData(blocked_pid);
477 
478  /* We can't need more output entries than there are reported PROCLOCKs */
479  arrayelems = (Datum *) palloc(lockData->nlocks * sizeof(Datum));
480  narrayelems = 0;
481 
482  /* For each blocked proc in the lock group ... */
483  for (i = 0; i < lockData->nprocs; i++)
484  {
485  BlockedProcData *bproc = &lockData->procs[i];
486  LockInstanceData *instances = &lockData->locks[bproc->first_lock];
487  int *preceding_waiters = &lockData->waiter_pids[bproc->first_waiter];
488  LockInstanceData *blocked_instance;
489  LockMethod lockMethodTable;
490  int conflictMask;
491 
492  /*
493  * Locate the blocked proc's own entry in the LockInstanceData array.
494  * There should be exactly one matching entry.
495  */
496  blocked_instance = NULL;
497  for (j = 0; j < bproc->num_locks; j++)
498  {
499  LockInstanceData *instance = &(instances[j]);
500 
501  if (instance->pid == bproc->pid)
502  {
503  Assert(blocked_instance == NULL);
504  blocked_instance = instance;
505  }
506  }
507  Assert(blocked_instance != NULL);
508 
509  lockMethodTable = GetLockTagsMethodTable(&(blocked_instance->locktag));
510  conflictMask = lockMethodTable->conflictTab[blocked_instance->waitLockMode];
511 
512  /* Now scan the PROCLOCK data for conflicting procs */
513  for (j = 0; j < bproc->num_locks; j++)
514  {
515  LockInstanceData *instance = &(instances[j]);
516 
517  /* A proc never blocks itself, so ignore that entry */
518  if (instance == blocked_instance)
519  continue;
520  /* Members of same lock group never block each other, either */
521  if (instance->leaderPid == blocked_instance->leaderPid)
522  continue;
523 
524  if (conflictMask & instance->holdMask)
525  {
526  /* hard block: blocked by lock already held by this entry */
527  }
528  else if (instance->waitLockMode != NoLock &&
529  (conflictMask & LOCKBIT_ON(instance->waitLockMode)))
530  {
531  /* conflict in lock requests; who's in front in wait queue? */
532  bool ahead = false;
533  int k;
534 
535  for (k = 0; k < bproc->num_waiters; k++)
536  {
537  if (preceding_waiters[k] == instance->pid)
538  {
539  /* soft block: this entry is ahead of blocked proc */
540  ahead = true;
541  break;
542  }
543  }
544  if (!ahead)
545  continue; /* not blocked by this entry */
546  }
547  else
548  {
549  /* not blocked by this entry */
550  continue;
551  }
552 
553  /* blocked by this entry, so emit a record */
554  arrayelems[narrayelems++] = Int32GetDatum(instance->leaderPid);
555  }
556  }
557 
558  /* Assert we didn't overrun arrayelems[] */
559  Assert(narrayelems <= lockData->nlocks);
560 
561  PG_RETURN_ARRAYTYPE_P(construct_array_builtin(arrayelems, narrayelems, INT4OID));
562 }
#define PG_RETURN_ARRAYTYPE_P(x)
Definition: array.h:258
ArrayType * construct_array_builtin(Datum *elems, int nelems, Oid elmtype)
Definition: arrayfuncs.c:3363
int j
Definition: isn.c:74
int i
Definition: isn.c:73
Assert(fmt[strlen(fmt) - 1] !='\n')
BlockedProcsData * GetBlockerStatusData(int blocked_pid)
Definition: lock.c:3788
LockMethod GetLockTagsMethodTable(const LOCKTAG *locktag)
Definition: lock.c:499
#define LOCKBIT_ON(lockmode)
Definition: lock.h:84
#define NoLock
Definition: lockdefs.h:34
void * palloc(Size size)
Definition: mcxt.c:1210
uintptr_t Datum
Definition: postgres.h:64
static Datum Int32GetDatum(int32 X)
Definition: postgres.h:212
int first_lock
Definition: lock.h:477
int first_waiter
Definition: lock.h:481
int num_waiters
Definition: lock.h:482
int num_locks
Definition: lock.h:478
LockInstanceData * locks
Definition: lock.h:488
int * waiter_pids
Definition: lock.h:489
BlockedProcData * procs
Definition: lock.h:487
LOCKMASK holdMask
Definition: lock.h:455
LOCKMODE waitLockMode
Definition: lock.h:456
LOCKTAG locktag
Definition: lock.h:454
int leaderPid
Definition: lock.h:462
const LOCKMASK * conflictTab
Definition: lock.h:111

References Assert(), LockMethodData::conflictTab, construct_array_builtin(), BlockedProcData::first_lock, BlockedProcData::first_waiter, GetBlockerStatusData(), GetLockTagsMethodTable(), LockInstanceData::holdMask, i, Int32GetDatum(), j, LockInstanceData::leaderPid, LOCKBIT_ON, BlockedProcsData::locks, LockInstanceData::locktag, BlockedProcsData::nlocks, NoLock, BlockedProcsData::nprocs, BlockedProcData::num_locks, BlockedProcData::num_waiters, palloc(), PG_GETARG_INT32, PG_RETURN_ARRAYTYPE_P, LockInstanceData::pid, BlockedProcData::pid, BlockedProcsData::procs, BlockedProcsData::waiter_pids, and LockInstanceData::waitLockMode.

Referenced by pg_isolation_test_session_is_blocked().

◆ pg_isolation_test_session_is_blocked()

Datum pg_isolation_test_session_is_blocked ( PG_FUNCTION_ARGS  )

Definition at line 615 of file lockfuncs.c.

616 {
617  int blocked_pid = PG_GETARG_INT32(0);
618  ArrayType *interesting_pids_a = PG_GETARG_ARRAYTYPE_P(1);
619  ArrayType *blocking_pids_a;
620  int32 *interesting_pids;
621  int32 *blocking_pids;
622  int num_interesting_pids;
623  int num_blocking_pids;
624  int dummy;
625  int i,
626  j;
627 
628  /* Validate the passed-in array */
629  Assert(ARR_ELEMTYPE(interesting_pids_a) == INT4OID);
630  if (array_contains_nulls(interesting_pids_a))
631  elog(ERROR, "array must not contain nulls");
632  interesting_pids = (int32 *) ARR_DATA_PTR(interesting_pids_a);
633  num_interesting_pids = ArrayGetNItems(ARR_NDIM(interesting_pids_a),
634  ARR_DIMS(interesting_pids_a));
635 
636  /*
637  * Get the PIDs of all sessions blocking the given session's attempt to
638  * acquire heavyweight locks.
639  */
640  blocking_pids_a =
642 
643  Assert(ARR_ELEMTYPE(blocking_pids_a) == INT4OID);
644  Assert(!array_contains_nulls(blocking_pids_a));
645  blocking_pids = (int32 *) ARR_DATA_PTR(blocking_pids_a);
646  num_blocking_pids = ArrayGetNItems(ARR_NDIM(blocking_pids_a),
647  ARR_DIMS(blocking_pids_a));
648 
649  /*
650  * Check if any of these are in the list of interesting PIDs, that being
651  * the sessions that the isolation tester is running. We don't use
652  * "arrayoverlaps" here, because it would lead to cache lookups and one of
653  * our goals is to run quickly with debug_discard_caches > 0. We expect
654  * blocking_pids to be usually empty and otherwise a very small number in
655  * isolation tester cases, so make that the outer loop of a naive search
656  * for a match.
657  */
658  for (i = 0; i < num_blocking_pids; i++)
659  for (j = 0; j < num_interesting_pids; j++)
660  {
661  if (blocking_pids[i] == interesting_pids[j])
662  PG_RETURN_BOOL(true);
663  }
664 
665  /*
666  * Check if blocked_pid is waiting for a safe snapshot. We could in
667  * theory check the resulting array of blocker PIDs against the
668  * interesting PIDs list, but since there is no danger of autovacuum
669  * blocking GetSafeSnapshot there seems to be no point in expending cycles
670  * on allocating a buffer and searching for overlap; so it's presently
671  * sufficient for the isolation tester's purposes to use a single element
672  * buffer and check if the number of safe snapshot blockers is non-zero.
673  */
674  if (GetSafeSnapshotBlockingPids(blocked_pid, &dummy, 1) > 0)
675  PG_RETURN_BOOL(true);
676 
677  PG_RETURN_BOOL(false);
678 }
#define ARR_NDIM(a)
Definition: array.h:283
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:256
#define ARR_DATA_PTR(a)
Definition: array.h:315
#define DatumGetArrayTypeP(X)
Definition: array.h:254
#define ARR_ELEMTYPE(a)
Definition: array.h:285
#define ARR_DIMS(a)
Definition: array.h:287
bool array_contains_nulls(ArrayType *array)
Definition: arrayfuncs.c:3738
int ArrayGetNItems(int ndim, const int *dims)
Definition: arrayutils.c:76
#define ERROR
Definition: elog.h:39
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:642
Datum pg_blocking_pids(PG_FUNCTION_ARGS)
Definition: lockfuncs.c:466
int GetSafeSnapshotBlockingPids(int blocked_pid, int *output, int output_size)
Definition: predicate.c:1562

References ARR_DATA_PTR, ARR_DIMS, ARR_ELEMTYPE, ARR_NDIM, array_contains_nulls(), ArrayGetNItems(), Assert(), DatumGetArrayTypeP, DirectFunctionCall1, elog(), ERROR, GetSafeSnapshotBlockingPids(), i, j, pg_blocking_pids(), PG_GETARG_ARRAYTYPE_P, PG_GETARG_INT32, and PG_RETURN_BOOL.

◆ pg_lock_status()

Datum pg_lock_status ( PG_FUNCTION_ARGS  )

Definition at line 93 of file lockfuncs.c.

94 {
95  FuncCallContext *funcctx;
96  PG_Lock_Status *mystatus;
97  LockData *lockData;
98  PredicateLockData *predLockData;
99 
100  if (SRF_IS_FIRSTCALL())
101  {
102  TupleDesc tupdesc;
103  MemoryContext oldcontext;
104 
105  /* create a function context for cross-call persistence */
106  funcctx = SRF_FIRSTCALL_INIT();
107 
108  /*
109  * switch to memory context appropriate for multiple function calls
110  */
111  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
112 
113  /* build tupdesc for result tuples */
114  /* this had better match function's declaration in pg_proc.h */
116  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "locktype",
117  TEXTOID, -1, 0);
118  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "database",
119  OIDOID, -1, 0);
120  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "relation",
121  OIDOID, -1, 0);
122  TupleDescInitEntry(tupdesc, (AttrNumber) 4, "page",
123  INT4OID, -1, 0);
124  TupleDescInitEntry(tupdesc, (AttrNumber) 5, "tuple",
125  INT2OID, -1, 0);
126  TupleDescInitEntry(tupdesc, (AttrNumber) 6, "virtualxid",
127  TEXTOID, -1, 0);
128  TupleDescInitEntry(tupdesc, (AttrNumber) 7, "transactionid",
129  XIDOID, -1, 0);
130  TupleDescInitEntry(tupdesc, (AttrNumber) 8, "classid",
131  OIDOID, -1, 0);
132  TupleDescInitEntry(tupdesc, (AttrNumber) 9, "objid",
133  OIDOID, -1, 0);
134  TupleDescInitEntry(tupdesc, (AttrNumber) 10, "objsubid",
135  INT2OID, -1, 0);
136  TupleDescInitEntry(tupdesc, (AttrNumber) 11, "virtualtransaction",
137  TEXTOID, -1, 0);
138  TupleDescInitEntry(tupdesc, (AttrNumber) 12, "pid",
139  INT4OID, -1, 0);
140  TupleDescInitEntry(tupdesc, (AttrNumber) 13, "mode",
141  TEXTOID, -1, 0);
142  TupleDescInitEntry(tupdesc, (AttrNumber) 14, "granted",
143  BOOLOID, -1, 0);
144  TupleDescInitEntry(tupdesc, (AttrNumber) 15, "fastpath",
145  BOOLOID, -1, 0);
146  TupleDescInitEntry(tupdesc, (AttrNumber) 16, "waitstart",
147  TIMESTAMPTZOID, -1, 0);
148 
149  funcctx->tuple_desc = BlessTupleDesc(tupdesc);
150 
151  /*
152  * Collect all the locking information that we will format and send
153  * out as a result set.
154  */
155  mystatus = (PG_Lock_Status *) palloc(sizeof(PG_Lock_Status));
156  funcctx->user_fctx = (void *) mystatus;
157 
158  mystatus->lockData = GetLockStatusData();
159  mystatus->currIdx = 0;
161  mystatus->predLockIdx = 0;
162 
163  MemoryContextSwitchTo(oldcontext);
164  }
165 
166  funcctx = SRF_PERCALL_SETUP();
167  mystatus = (PG_Lock_Status *) funcctx->user_fctx;
168  lockData = mystatus->lockData;
169 
170  while (mystatus->currIdx < lockData->nelements)
171  {
172  bool granted;
173  LOCKMODE mode = 0;
174  const char *locktypename;
175  char tnbuf[32];
177  bool nulls[NUM_LOCK_STATUS_COLUMNS] = {0};
178  HeapTuple tuple;
179  Datum result;
180  LockInstanceData *instance;
181 
182  instance = &(lockData->locks[mystatus->currIdx]);
183 
184  /*
185  * Look to see if there are any held lock modes in this PROCLOCK. If
186  * so, report, and destructively modify lockData so we don't report
187  * again.
188  */
189  granted = false;
190  if (instance->holdMask)
191  {
192  for (mode = 0; mode < MAX_LOCKMODES; mode++)
193  {
194  if (instance->holdMask & LOCKBIT_ON(mode))
195  {
196  granted = true;
197  instance->holdMask &= LOCKBIT_OFF(mode);
198  break;
199  }
200  }
201  }
202 
203  /*
204  * If no (more) held modes to report, see if PROC is waiting for a
205  * lock on this lock.
206  */
207  if (!granted)
208  {
209  if (instance->waitLockMode != NoLock)
210  {
211  /* Yes, so report it with proper mode */
212  mode = instance->waitLockMode;
213 
214  /*
215  * We are now done with this PROCLOCK, so advance pointer to
216  * continue with next one on next call.
217  */
218  mystatus->currIdx++;
219  }
220  else
221  {
222  /*
223  * Okay, we've displayed all the locks associated with this
224  * PROCLOCK, proceed to the next one.
225  */
226  mystatus->currIdx++;
227  continue;
228  }
229  }
230 
231  /*
232  * Form tuple with appropriate data.
233  */
234 
235  if (instance->locktag.locktag_type <= LOCKTAG_LAST_TYPE)
236  locktypename = LockTagTypeNames[instance->locktag.locktag_type];
237  else
238  {
239  snprintf(tnbuf, sizeof(tnbuf), "unknown %d",
240  (int) instance->locktag.locktag_type);
241  locktypename = tnbuf;
242  }
243  values[0] = CStringGetTextDatum(locktypename);
244 
245  switch ((LockTagType) instance->locktag.locktag_type)
246  {
247  case LOCKTAG_RELATION:
251  nulls[3] = true;
252  nulls[4] = true;
253  nulls[5] = true;
254  nulls[6] = true;
255  nulls[7] = true;
256  nulls[8] = true;
257  nulls[9] = true;
258  break;
261  nulls[2] = true;
262  nulls[3] = true;
263  nulls[4] = true;
264  nulls[5] = true;
265  nulls[6] = true;
266  nulls[7] = true;
267  nulls[8] = true;
268  nulls[9] = true;
269  break;
270  case LOCKTAG_PAGE:
274  nulls[4] = true;
275  nulls[5] = true;
276  nulls[6] = true;
277  nulls[7] = true;
278  nulls[8] = true;
279  nulls[9] = true;
280  break;
281  case LOCKTAG_TUPLE:
286  nulls[5] = true;
287  nulls[6] = true;
288  nulls[7] = true;
289  nulls[8] = true;
290  nulls[9] = true;
291  break;
292  case LOCKTAG_TRANSACTION:
293  values[6] =
295  nulls[1] = true;
296  nulls[2] = true;
297  nulls[3] = true;
298  nulls[4] = true;
299  nulls[5] = true;
300  nulls[7] = true;
301  nulls[8] = true;
302  nulls[9] = true;
303  break;
305  values[5] = VXIDGetDatum(instance->locktag.locktag_field1,
306  instance->locktag.locktag_field2);
307  nulls[1] = true;
308  nulls[2] = true;
309  nulls[3] = true;
310  nulls[4] = true;
311  nulls[6] = true;
312  nulls[7] = true;
313  nulls[8] = true;
314  nulls[9] = true;
315  break;
317  values[6] =
320  nulls[1] = true;
321  nulls[2] = true;
322  nulls[3] = true;
323  nulls[4] = true;
324  nulls[5] = true;
325  nulls[7] = true;
326  nulls[9] = true;
327  break;
332  values[9] = Int16GetDatum(instance->locktag.locktag_field4);
333  nulls[2] = true;
334  nulls[3] = true;
335  nulls[4] = true;
336  nulls[5] = true;
337  nulls[7] = true;
338  break;
339  case LOCKTAG_OBJECT:
340  case LOCKTAG_USERLOCK:
341  case LOCKTAG_ADVISORY:
342  default: /* treat unknown locktags like OBJECT */
346  values[9] = Int16GetDatum(instance->locktag.locktag_field4);
347  nulls[2] = true;
348  nulls[3] = true;
349  nulls[4] = true;
350  nulls[5] = true;
351  nulls[6] = true;
352  break;
353  }
354 
355  values[10] = VXIDGetDatum(instance->backend, instance->lxid);
356  if (instance->pid != 0)
357  values[11] = Int32GetDatum(instance->pid);
358  else
359  nulls[11] = true;
361  values[13] = BoolGetDatum(granted);
362  values[14] = BoolGetDatum(instance->fastpath);
363  if (!granted && instance->waitStart != 0)
364  values[15] = TimestampTzGetDatum(instance->waitStart);
365  else
366  nulls[15] = true;
367 
368  tuple = heap_form_tuple(funcctx->tuple_desc, values, nulls);
369  result = HeapTupleGetDatum(tuple);
370  SRF_RETURN_NEXT(funcctx, result);
371  }
372 
373  /*
374  * Have returned all regular locks. Now start on the SIREAD predicate
375  * locks.
376  */
377  predLockData = mystatus->predLockData;
378  if (mystatus->predLockIdx < predLockData->nelements)
379  {
380  PredicateLockTargetType lockType;
381 
382  PREDICATELOCKTARGETTAG *predTag = &(predLockData->locktags[mystatus->predLockIdx]);
383  SERIALIZABLEXACT *xact = &(predLockData->xacts[mystatus->predLockIdx]);
385  bool nulls[NUM_LOCK_STATUS_COLUMNS] = {0};
386  HeapTuple tuple;
387  Datum result;
388 
389  mystatus->predLockIdx++;
390 
391  /*
392  * Form tuple with appropriate data.
393  */
394 
395  /* lock type */
396  lockType = GET_PREDICATELOCKTARGETTAG_TYPE(*predTag);
397 
399 
400  /* lock target */
401  values[1] = GET_PREDICATELOCKTARGETTAG_DB(*predTag);
403  if (lockType == PREDLOCKTAG_TUPLE)
405  else
406  nulls[4] = true;
407  if ((lockType == PREDLOCKTAG_TUPLE) ||
408  (lockType == PREDLOCKTAG_PAGE))
410  else
411  nulls[3] = true;
412 
413  /* these fields are targets for other types of locks */
414  nulls[5] = true; /* virtualxid */
415  nulls[6] = true; /* transactionid */
416  nulls[7] = true; /* classid */
417  nulls[8] = true; /* objid */
418  nulls[9] = true; /* objsubid */
419 
420  /* lock holder */
421  values[10] = VXIDGetDatum(xact->vxid.backendId,
422  xact->vxid.localTransactionId);
423  if (xact->pid != 0)
424  values[11] = Int32GetDatum(xact->pid);
425  else
426  nulls[11] = true;
427 
428  /*
429  * Lock mode. Currently all predicate locks are SIReadLocks, which are
430  * always held (never waiting) and have no fast path
431  */
432  values[12] = CStringGetTextDatum("SIReadLock");
433  values[13] = BoolGetDatum(true);
434  values[14] = BoolGetDatum(false);
435  nulls[15] = true;
436 
437  tuple = heap_form_tuple(funcctx->tuple_desc, values, nulls);
438  result = HeapTupleGetDatum(tuple);
439  SRF_RETURN_NEXT(funcctx, result);
440  }
441 
442  SRF_RETURN_DONE(funcctx);
443 }
int16 AttrNumber
Definition: attnum.h:21
static Datum values[MAXATTR]
Definition: bootstrap.c:156
#define CStringGetTextDatum(s)
Definition: builtins.h:94
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:2071
#define SRF_IS_FIRSTCALL()
Definition: funcapi.h:303
#define SRF_PERCALL_SETUP()
Definition: funcapi.h:307
#define SRF_RETURN_NEXT(_funcctx, _result)
Definition: funcapi.h:309
#define SRF_FIRSTCALL_INIT()
Definition: funcapi.h:305
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
Definition: funcapi.h:230
#define SRF_RETURN_DONE(_funcctx)
Definition: funcapi.h:327
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020
LockData * GetLockStatusData(void)
Definition: lock.c:3596
const char * GetLockmodeName(LOCKMETHODID lockmethodid, LOCKMODE mode)
Definition: lock.c:4044
LockTagType
Definition: lock.h:136
@ LOCKTAG_OBJECT
Definition: lock.h:145
@ LOCKTAG_RELATION_EXTEND
Definition: lock.h:138
@ LOCKTAG_RELATION
Definition: lock.h:137
@ LOCKTAG_TUPLE
Definition: lock.h:141
@ LOCKTAG_SPECULATIVE_TOKEN
Definition: lock.h:144
@ LOCKTAG_APPLY_TRANSACTION
Definition: lock.h:148
@ LOCKTAG_USERLOCK
Definition: lock.h:146
@ LOCKTAG_DATABASE_FROZEN_IDS
Definition: lock.h:139
@ LOCKTAG_VIRTUALTRANSACTION
Definition: lock.h:143
@ LOCKTAG_TRANSACTION
Definition: lock.h:142
@ LOCKTAG_PAGE
Definition: lock.h:140
@ LOCKTAG_ADVISORY
Definition: lock.h:147
#define LOCKBIT_OFF(lockmode)
Definition: lock.h:85
#define LOCKTAG_LAST_TYPE
Definition: lock.h:152
#define MAX_LOCKMODES
Definition: lock.h:82
int LOCKMODE
Definition: lockdefs.h:26
#define NUM_LOCK_STATUS_COLUMNS
Definition: lockfuncs.c:67
static const char *const PredicateLockTagTypeNames[]
Definition: lockfuncs.c:48
static Datum VXIDGetDatum(BackendId bid, LocalTransactionId lxid)
Definition: lockfuncs.c:75
const char *const LockTagTypeNames[]
Definition: lockfuncs.c:29
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:138
static PgChecksumMode mode
Definition: pg_checksums.c:65
while(p+4<=pend)
#define snprintf
Definition: port.h:238
static Datum TransactionIdGetDatum(TransactionId X)
Definition: postgres.h:272
static Datum Int16GetDatum(int16 X)
Definition: postgres.h:172
static Datum UInt16GetDatum(uint16 X)
Definition: postgres.h:192
static Datum BoolGetDatum(bool X)
Definition: postgres.h:102
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:252
static Datum UInt32GetDatum(uint32 X)
Definition: postgres.h:232
PredicateLockData * GetPredicateLockStatusData(void)
Definition: predicate.c:1379
PredicateLockTargetType
@ PREDLOCKTAG_PAGE
@ PREDLOCKTAG_TUPLE
#define GET_PREDICATELOCKTARGETTAG_DB(locktag)
#define GET_PREDICATELOCKTARGETTAG_RELATION(locktag)
#define GET_PREDICATELOCKTARGETTAG_TYPE(locktag)
#define GET_PREDICATELOCKTARGETTAG_PAGE(locktag)
#define GET_PREDICATELOCKTARGETTAG_OFFSET(locktag)
void * user_fctx
Definition: funcapi.h:82
MemoryContext multi_call_memory_ctx
Definition: funcapi.h:101
TupleDesc tuple_desc
Definition: funcapi.h:112
uint8 locktag_type
Definition: lock.h:170
uint32 locktag_field3
Definition: lock.h:168
uint32 locktag_field1
Definition: lock.h:166
uint8 locktag_lockmethodid
Definition: lock.h:171
uint16 locktag_field4
Definition: lock.h:169
uint32 locktag_field2
Definition: lock.h:167
Definition: lock.h:467
LockInstanceData * locks
Definition: lock.h:469
int nelements
Definition: lock.h:468
bool fastpath
Definition: lock.h:463
TimestampTz waitStart
Definition: lock.h:459
BackendId backend
Definition: lock.h:457
LocalTransactionId lxid
Definition: lock.h:458
PredicateLockData * predLockData
Definition: lockfuncs.c:62
LockData * lockData
Definition: lockfuncs.c:60
PREDICATELOCKTARGETTAG * locktags
SERIALIZABLEXACT * xacts
VirtualTransactionId vxid
LocalTransactionId localTransactionId
Definition: lock.h:62
BackendId backendId
Definition: lock.h:61
TupleDesc CreateTemplateTupleDesc(int natts)
Definition: tupdesc.c:45
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:583
static Datum TimestampTzGetDatum(TimestampTz X)
Definition: timestamp.h:52

References LockInstanceData::backend, VirtualTransactionId::backendId, BlessTupleDesc(), BoolGetDatum(), CreateTemplateTupleDesc(), CStringGetTextDatum, PG_Lock_Status::currIdx, LockInstanceData::fastpath, GET_PREDICATELOCKTARGETTAG_DB, GET_PREDICATELOCKTARGETTAG_OFFSET, GET_PREDICATELOCKTARGETTAG_PAGE, GET_PREDICATELOCKTARGETTAG_RELATION, GET_PREDICATELOCKTARGETTAG_TYPE, GetLockmodeName(), GetLockStatusData(), GetPredicateLockStatusData(), heap_form_tuple(), HeapTupleGetDatum(), LockInstanceData::holdMask, Int16GetDatum(), Int32GetDatum(), VirtualTransactionId::localTransactionId, LOCKBIT_OFF, LOCKBIT_ON, PG_Lock_Status::lockData, LockData::locks, LockInstanceData::locktag, LOCKTAG_ADVISORY, LOCKTAG_APPLY_TRANSACTION, LOCKTAG_DATABASE_FROZEN_IDS, LOCKTAG::locktag_field1, LOCKTAG::locktag_field2, LOCKTAG::locktag_field3, LOCKTAG::locktag_field4, LOCKTAG_LAST_TYPE, LOCKTAG::locktag_lockmethodid, LOCKTAG_OBJECT, LOCKTAG_PAGE, LOCKTAG_RELATION, LOCKTAG_RELATION_EXTEND, LOCKTAG_SPECULATIVE_TOKEN, LOCKTAG_TRANSACTION, LOCKTAG_TUPLE, LOCKTAG::locktag_type, LOCKTAG_USERLOCK, LOCKTAG_VIRTUALTRANSACTION, PredicateLockData::locktags, LockTagTypeNames, LockInstanceData::lxid, MAX_LOCKMODES, MemoryContextSwitchTo(), mode, FuncCallContext::multi_call_memory_ctx, LockData::nelements, PredicateLockData::nelements, NoLock, NUM_LOCK_STATUS_COLUMNS, ObjectIdGetDatum(), palloc(), LockInstanceData::pid, SERIALIZABLEXACT::pid, PredicateLockTagTypeNames, PG_Lock_Status::predLockData, PG_Lock_Status::predLockIdx, PREDLOCKTAG_PAGE, PREDLOCKTAG_TUPLE, snprintf, SRF_FIRSTCALL_INIT, SRF_IS_FIRSTCALL, SRF_PERCALL_SETUP, SRF_RETURN_DONE, SRF_RETURN_NEXT, TimestampTzGetDatum(), TransactionIdGetDatum(), FuncCallContext::tuple_desc, TupleDescInitEntry(), UInt16GetDatum(), UInt32GetDatum(), FuncCallContext::user_fctx, values, SERIALIZABLEXACT::vxid, VXIDGetDatum(), LockInstanceData::waitLockMode, LockInstanceData::waitStart, while(), and PredicateLockData::xacts.

◆ pg_safe_snapshot_blocking_pids()

Datum pg_safe_snapshot_blocking_pids ( PG_FUNCTION_ARGS  )

Definition at line 573 of file lockfuncs.c.

574 {
575  int blocked_pid = PG_GETARG_INT32(0);
576  int *blockers;
577  int num_blockers;
578  Datum *blocker_datums;
579 
580  /* A buffer big enough for any possible blocker list without truncation */
581  blockers = (int *) palloc(MaxBackends * sizeof(int));
582 
583  /* Collect a snapshot of processes waited for by GetSafeSnapshot */
584  num_blockers =
585  GetSafeSnapshotBlockingPids(blocked_pid, blockers, MaxBackends);
586 
587  /* Convert int array to Datum array */
588  if (num_blockers > 0)
589  {
590  int i;
591 
592  blocker_datums = (Datum *) palloc(num_blockers * sizeof(Datum));
593  for (i = 0; i < num_blockers; ++i)
594  blocker_datums[i] = Int32GetDatum(blockers[i]);
595  }
596  else
597  blocker_datums = NULL;
598 
599  PG_RETURN_ARRAYTYPE_P(construct_array_builtin(blocker_datums, num_blockers, INT4OID));
600 }
int MaxBackends
Definition: globals.c:140

References construct_array_builtin(), GetSafeSnapshotBlockingPids(), i, Int32GetDatum(), MaxBackends, palloc(), PG_GETARG_INT32, and PG_RETURN_ARRAYTYPE_P.

◆ pg_try_advisory_lock_int4()

Datum pg_try_advisory_lock_int4 ( PG_FUNCTION_ARGS  )

Definition at line 958 of file lockfuncs.c.

959 {
960  int32 key1 = PG_GETARG_INT32(0);
961  int32 key2 = PG_GETARG_INT32(1);
962  LOCKTAG tag;
964 
965  SET_LOCKTAG_INT32(tag, key1, key2);
966 
967  res = LockAcquire(&tag, ExclusiveLock, true, true);
968 
970 }
LockAcquireResult
Definition: lock.h:501
@ LOCKACQUIRE_NOT_AVAIL
Definition: lock.h:502

References ExclusiveLock, LockAcquire(), LOCKACQUIRE_NOT_AVAIL, PG_GETARG_INT32, PG_RETURN_BOOL, res, and SET_LOCKTAG_INT32.

◆ pg_try_advisory_lock_int8()

Datum pg_try_advisory_lock_int8 ( PG_FUNCTION_ARGS  )

Definition at line 772 of file lockfuncs.c.

773 {
774  int64 key = PG_GETARG_INT64(0);
775  LOCKTAG tag;
777 
778  SET_LOCKTAG_INT64(tag, key);
779 
780  res = LockAcquire(&tag, ExclusiveLock, true, true);
781 
783 }

References ExclusiveLock, sort-test::key, LockAcquire(), LOCKACQUIRE_NOT_AVAIL, PG_GETARG_INT64, PG_RETURN_BOOL, res, and SET_LOCKTAG_INT64.

◆ pg_try_advisory_lock_shared_int4()

Datum pg_try_advisory_lock_shared_int4 ( PG_FUNCTION_ARGS  )

Definition at line 999 of file lockfuncs.c.

1000 {
1001  int32 key1 = PG_GETARG_INT32(0);
1002  int32 key2 = PG_GETARG_INT32(1);
1003  LOCKTAG tag;
1005 
1006  SET_LOCKTAG_INT32(tag, key1, key2);
1007 
1008  res = LockAcquire(&tag, ShareLock, true, true);
1009 
1011 }

References LockAcquire(), LOCKACQUIRE_NOT_AVAIL, PG_GETARG_INT32, PG_RETURN_BOOL, res, SET_LOCKTAG_INT32, and ShareLock.

◆ pg_try_advisory_lock_shared_int8()

Datum pg_try_advisory_lock_shared_int8 ( PG_FUNCTION_ARGS  )

Definition at line 811 of file lockfuncs.c.

812 {
813  int64 key = PG_GETARG_INT64(0);
814  LOCKTAG tag;
816 
817  SET_LOCKTAG_INT64(tag, key);
818 
819  res = LockAcquire(&tag, ShareLock, true, true);
820 
822 }

References sort-test::key, LockAcquire(), LOCKACQUIRE_NOT_AVAIL, PG_GETARG_INT64, PG_RETURN_BOOL, res, SET_LOCKTAG_INT64, and ShareLock.

◆ pg_try_advisory_xact_lock_int4()

Datum pg_try_advisory_xact_lock_int4 ( PG_FUNCTION_ARGS  )

Definition at line 979 of file lockfuncs.c.

980 {
981  int32 key1 = PG_GETARG_INT32(0);
982  int32 key2 = PG_GETARG_INT32(1);
983  LOCKTAG tag;
985 
986  SET_LOCKTAG_INT32(tag, key1, key2);
987 
988  res = LockAcquire(&tag, ExclusiveLock, false, true);
989 
991 }

References ExclusiveLock, LockAcquire(), LOCKACQUIRE_NOT_AVAIL, PG_GETARG_INT32, PG_RETURN_BOOL, res, and SET_LOCKTAG_INT32.

◆ pg_try_advisory_xact_lock_int8()

Datum pg_try_advisory_xact_lock_int8 ( PG_FUNCTION_ARGS  )

Definition at line 792 of file lockfuncs.c.

793 {
794  int64 key = PG_GETARG_INT64(0);
795  LOCKTAG tag;
797 
798  SET_LOCKTAG_INT64(tag, key);
799 
800  res = LockAcquire(&tag, ExclusiveLock, false, true);
801 
803 }

References ExclusiveLock, sort-test::key, LockAcquire(), LOCKACQUIRE_NOT_AVAIL, PG_GETARG_INT64, PG_RETURN_BOOL, res, and SET_LOCKTAG_INT64.

◆ pg_try_advisory_xact_lock_shared_int4()

Datum pg_try_advisory_xact_lock_shared_int4 ( PG_FUNCTION_ARGS  )

Definition at line 1020 of file lockfuncs.c.

1021 {
1022  int32 key1 = PG_GETARG_INT32(0);
1023  int32 key2 = PG_GETARG_INT32(1);
1024  LOCKTAG tag;
1026 
1027  SET_LOCKTAG_INT32(tag, key1, key2);
1028 
1029  res = LockAcquire(&tag, ShareLock, false, true);
1030 
1032 }

References LockAcquire(), LOCKACQUIRE_NOT_AVAIL, PG_GETARG_INT32, PG_RETURN_BOOL, res, SET_LOCKTAG_INT32, and ShareLock.

◆ pg_try_advisory_xact_lock_shared_int8()

Datum pg_try_advisory_xact_lock_shared_int8 ( PG_FUNCTION_ARGS  )

Definition at line 831 of file lockfuncs.c.

832 {
833  int64 key = PG_GETARG_INT64(0);
834  LOCKTAG tag;
836 
837  SET_LOCKTAG_INT64(tag, key);
838 
839  res = LockAcquire(&tag, ShareLock, false, true);
840 
842 }

References sort-test::key, LockAcquire(), LOCKACQUIRE_NOT_AVAIL, PG_GETARG_INT64, PG_RETURN_BOOL, res, SET_LOCKTAG_INT64, and ShareLock.

◆ StaticAssertDecl() [1/2]

StaticAssertDecl ( lengthof(LockTagTypeNames = =(LOCKTAG_LAST_TYPE+1),
"array length mismatch"   
)

◆ StaticAssertDecl() [2/2]

StaticAssertDecl ( lengthof(PredicateLockTagTypeNames = =(PREDLOCKTAG_TUPLE+1),
"array length mismatch"   
)

◆ VXIDGetDatum()

static Datum VXIDGetDatum ( BackendId  bid,
LocalTransactionId  lxid 
)
static

Definition at line 75 of file lockfuncs.c.

76 {
77  /*
78  * The representation is "<bid>/<lxid>", decimal and unsigned decimal
79  * respectively. Note that elog.c also knows how to format a vxid.
80  */
81  char vxidstr[32];
82 
83  snprintf(vxidstr, sizeof(vxidstr), "%d/%u", bid, lxid);
84 
85  return CStringGetTextDatum(vxidstr);
86 }

References CStringGetTextDatum, and snprintf.

Referenced by pg_lock_status().

Variable Documentation

◆ LockTagTypeNames

const char* const LockTagTypeNames[]
Initial value:
= {
"relation",
"extend",
"frozenid",
"page",
"tuple",
"transactionid",
"virtualxid",
"spectoken",
"object",
"userlock",
"advisory",
"applytransaction"
}

Definition at line 29 of file lockfuncs.c.

Referenced by GetLockNameFromTagType(), and pg_lock_status().

◆ PredicateLockTagTypeNames

const char* const PredicateLockTagTypeNames[]
static
Initial value:
= {
"relation",
"page",
"tuple"
}

Definition at line 48 of file lockfuncs.c.

Referenced by pg_lock_status().