PostgreSQL Source Code  git master
lmgr.h File Reference
#include "lib/stringinfo.h"
#include "storage/itemptr.h"
#include "storage/lock.h"
#include "utils/rel.h"
Include dependency graph for lmgr.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef enum XLTW_Oper XLTW_Oper
 

Enumerations

enum  XLTW_Oper {
  XLTW_None, XLTW_Update, XLTW_Delete, XLTW_Lock,
  XLTW_LockUpdated, XLTW_InsertIndex, XLTW_InsertIndexUnique, XLTW_FetchUpdated,
  XLTW_RecheckExclusionConstr
}
 

Functions

void RelationInitLockInfo (Relation relation)
 
void LockRelationOid (Oid relid, LOCKMODE lockmode)
 
bool ConditionalLockRelationOid (Oid relid, LOCKMODE lockmode)
 
void UnlockRelationId (LockRelId *relid, LOCKMODE lockmode)
 
void UnlockRelationOid (Oid relid, LOCKMODE lockmode)
 
void LockRelation (Relation relation, LOCKMODE lockmode)
 
bool ConditionalLockRelation (Relation relation, LOCKMODE lockmode)
 
void UnlockRelation (Relation relation, LOCKMODE lockmode)
 
bool CheckRelationLockedByMe (Relation relation, LOCKMODE lockmode, bool orstronger)
 
bool LockHasWaitersRelation (Relation relation, LOCKMODE lockmode)
 
void LockRelationIdForSession (LockRelId *relid, LOCKMODE lockmode)
 
void UnlockRelationIdForSession (LockRelId *relid, LOCKMODE lockmode)
 
void LockRelationForExtension (Relation relation, LOCKMODE lockmode)
 
void UnlockRelationForExtension (Relation relation, LOCKMODE lockmode)
 
bool ConditionalLockRelationForExtension (Relation relation, LOCKMODE lockmode)
 
int RelationExtensionLockWaiterCount (Relation relation)
 
void LockDatabaseFrozenIds (LOCKMODE lockmode)
 
void LockPage (Relation relation, BlockNumber blkno, LOCKMODE lockmode)
 
bool ConditionalLockPage (Relation relation, BlockNumber blkno, LOCKMODE lockmode)
 
void UnlockPage (Relation relation, BlockNumber blkno, LOCKMODE lockmode)
 
void LockTuple (Relation relation, ItemPointer tid, LOCKMODE lockmode)
 
bool ConditionalLockTuple (Relation relation, ItemPointer tid, LOCKMODE lockmode)
 
void UnlockTuple (Relation relation, ItemPointer tid, LOCKMODE lockmode)
 
void XactLockTableInsert (TransactionId xid)
 
void XactLockTableDelete (TransactionId xid)
 
void XactLockTableWait (TransactionId xid, Relation rel, ItemPointer ctid, XLTW_Oper oper)
 
bool ConditionalXactLockTableWait (TransactionId xid)
 
void WaitForLockers (LOCKTAG heaplocktag, LOCKMODE lockmode, bool progress)
 
void WaitForLockersMultiple (List *locktags, LOCKMODE lockmode, bool progress)
 
uint32 SpeculativeInsertionLockAcquire (TransactionId xid)
 
void SpeculativeInsertionLockRelease (TransactionId xid)
 
void SpeculativeInsertionWait (TransactionId xid, uint32 token)
 
void LockDatabaseObject (Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
 
void UnlockDatabaseObject (Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
 
void LockSharedObject (Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
 
void UnlockSharedObject (Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
 
void LockSharedObjectForSession (Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
 
void UnlockSharedObjectForSession (Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
 
void DescribeLockTag (StringInfo buf, const LOCKTAG *tag)
 
const char * GetLockNameFromTagType (uint16 locktag_type)
 

Typedef Documentation

◆ XLTW_Oper

typedef enum XLTW_Oper XLTW_Oper

Enumeration Type Documentation

◆ XLTW_Oper

enum XLTW_Oper
Enumerator
XLTW_None 
XLTW_Update 
XLTW_Delete 
XLTW_Lock 
XLTW_LockUpdated 
XLTW_InsertIndex 
XLTW_InsertIndexUnique 
XLTW_FetchUpdated 
XLTW_RecheckExclusionConstr 

Definition at line 24 of file lmgr.h.

Function Documentation

◆ CheckRelationLockedByMe()

bool CheckRelationLockedByMe ( Relation  relation,
LOCKMODE  lockmode,
bool  orstronger 
)

Definition at line 303 of file lmgr.c.

References LockRelId::dbId, elog, GetLockmodeName(), LockHeldByMe(), LockInfoData::lockRelId, LOCKTAG::locktag_lockmethodid, MaxLockMode, RelationData::rd_lockInfo, RelationGetRelationName, LockRelId::relId, SET_LOCKTAG_RELATION, and WARNING.

Referenced by addRangeTableEntryForRelation(), ExecGetRangeTableRelation(), relation_open(), and try_relation_open().

304 {
305  LOCKTAG tag;
306 
308  relation->rd_lockInfo.lockRelId.dbId,
309  relation->rd_lockInfo.lockRelId.relId);
310 
311  if (LockHeldByMe(&tag, lockmode))
312  return true;
313 
314  if (orstronger)
315  {
316  LOCKMODE slockmode;
317 
318  for (slockmode = lockmode + 1;
319  slockmode <= MaxLockMode;
320  slockmode++)
321  {
322  if (LockHeldByMe(&tag, slockmode))
323  {
324 #ifdef NOT_USED
325  /* Sometimes this might be useful for debugging purposes */
326  elog(WARNING, "lock mode %s substituted for %s on relation %s",
327  GetLockmodeName(tag.locktag_lockmethodid, slockmode),
328  GetLockmodeName(tag.locktag_lockmethodid, lockmode),
329  RelationGetRelationName(relation));
330 #endif
331  return true;
332  }
333  }
334  }
335 
336  return false;
337 }
#define MaxLockMode
Definition: lockdefs.h:48
LockRelId lockRelId
Definition: rel.h:45
const char * GetLockmodeName(LOCKMETHODID lockmethodid, LOCKMODE mode)
Definition: lock.c:4096
bool LockHeldByMe(const LOCKTAG *locktag, LOCKMODE lockmode)
Definition: lock.c:598
int LOCKMODE
Definition: lockdefs.h:26
Oid dbId
Definition: rel.h:40
Definition: lock.h:166
#define SET_LOCKTAG_RELATION(locktag, dboid, reloid)
Definition: lock.h:183
LockInfoData rd_lockInfo
Definition: rel.h:112
#define RelationGetRelationName(relation)
Definition: rel.h:511
#define WARNING
Definition: elog.h:40
uint8 locktag_lockmethodid
Definition: lock.h:173
#define elog(elevel,...)
Definition: elog.h:232
Oid relId
Definition: rel.h:39

◆ ConditionalLockPage()

bool ConditionalLockPage ( Relation  relation,
BlockNumber  blkno,
LOCKMODE  lockmode 
)

Definition at line 505 of file lmgr.c.

References LockRelId::dbId, LockAcquire(), LOCKACQUIRE_NOT_AVAIL, LockInfoData::lockRelId, RelationData::rd_lockInfo, LockRelId::relId, and SET_LOCKTAG_PAGE.

Referenced by ginInsertCleanup().

506 {
507  LOCKTAG tag;
508 
509  SET_LOCKTAG_PAGE(tag,
510  relation->rd_lockInfo.lockRelId.dbId,
511  relation->rd_lockInfo.lockRelId.relId,
512  blkno);
513 
514  return (LockAcquire(&tag, lockmode, false, true) != LOCKACQUIRE_NOT_AVAIL);
515 }
LockRelId lockRelId
Definition: rel.h:45
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:747
Oid dbId
Definition: rel.h:40
Definition: lock.h:166
LockInfoData rd_lockInfo
Definition: rel.h:112
#define SET_LOCKTAG_PAGE(locktag, dboid, reloid, blocknum)
Definition: lock.h:210
Oid relId
Definition: rel.h:39

◆ ConditionalLockRelation()

bool ConditionalLockRelation ( Relation  relation,
LOCKMODE  lockmode 
)

Definition at line 248 of file lmgr.c.

References AcceptInvalidationMessages(), LockRelId::dbId, LOCKACQUIRE_ALREADY_CLEAR, LOCKACQUIRE_NOT_AVAIL, LockAcquireExtended(), LockInfoData::lockRelId, MarkLockClear(), RelationData::rd_lockInfo, LockRelId::relId, and SET_LOCKTAG_RELATION.

Referenced by lazy_truncate_heap().

249 {
250  LOCKTAG tag;
251  LOCALLOCK *locallock;
252  LockAcquireResult res;
253 
255  relation->rd_lockInfo.lockRelId.dbId,
256  relation->rd_lockInfo.lockRelId.relId);
257 
258  res = LockAcquireExtended(&tag, lockmode, false, true, true, &locallock);
259 
260  if (res == LOCKACQUIRE_NOT_AVAIL)
261  return false;
262 
263  /*
264  * Now that we have the lock, check for invalidation messages; see notes
265  * in LockRelationOid.
266  */
267  if (res != LOCKACQUIRE_ALREADY_CLEAR)
268  {
270  MarkLockClear(locallock);
271  }
272 
273  return true;
274 }
LockRelId lockRelId
Definition: rel.h:45
void AcceptInvalidationMessages(void)
Definition: inval.c:688
Oid dbId
Definition: rel.h:40
Definition: lock.h:166
#define SET_LOCKTAG_RELATION(locktag, dboid, reloid)
Definition: lock.h:183
LockInfoData rd_lockInfo
Definition: rel.h:112
void MarkLockClear(LOCALLOCK *locallock)
Definition: lock.c:1799
LockAcquireResult
Definition: lock.h:491
LockAcquireResult LockAcquireExtended(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait, bool reportMemoryError, LOCALLOCK **locallockp)
Definition: lock.c:771
Oid relId
Definition: rel.h:39

◆ ConditionalLockRelationForExtension()

bool ConditionalLockRelationForExtension ( Relation  relation,
LOCKMODE  lockmode 
)

Definition at line 421 of file lmgr.c.

References LockRelId::dbId, LockAcquire(), LOCKACQUIRE_NOT_AVAIL, LockInfoData::lockRelId, RelationData::rd_lockInfo, LockRelId::relId, and SET_LOCKTAG_RELATION_EXTEND.

Referenced by RelationGetBufferForTuple().

422 {
423  LOCKTAG tag;
424 
426  relation->rd_lockInfo.lockRelId.dbId,
427  relation->rd_lockInfo.lockRelId.relId);
428 
429  return (LockAcquire(&tag, lockmode, false, true) != LOCKACQUIRE_NOT_AVAIL);
430 }
LockRelId lockRelId
Definition: rel.h:45
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:747
Oid dbId
Definition: rel.h:40
Definition: lock.h:166
LockInfoData rd_lockInfo
Definition: rel.h:112
#define SET_LOCKTAG_RELATION_EXTEND(locktag, dboid, reloid)
Definition: lock.h:192
Oid relId
Definition: rel.h:39

◆ ConditionalLockRelationOid()

bool ConditionalLockRelationOid ( Oid  relid,
LOCKMODE  lockmode 
)

Definition at line 152 of file lmgr.c.

References AcceptInvalidationMessages(), LOCKACQUIRE_ALREADY_CLEAR, LOCKACQUIRE_NOT_AVAIL, LockAcquireExtended(), MarkLockClear(), and SetLocktagRelationOid().

Referenced by AlterTableMoveAll(), do_autovacuum(), LockTableRecurse(), LockViewRecurse_walker(), RangeVarGetRelidExtended(), and vacuum_open_relation().

153 {
154  LOCKTAG tag;
155  LOCALLOCK *locallock;
156  LockAcquireResult res;
157 
158  SetLocktagRelationOid(&tag, relid);
159 
160  res = LockAcquireExtended(&tag, lockmode, false, true, true, &locallock);
161 
162  if (res == LOCKACQUIRE_NOT_AVAIL)
163  return false;
164 
165  /*
166  * Now that we have the lock, check for invalidation messages; see notes
167  * in LockRelationOid.
168  */
169  if (res != LOCKACQUIRE_ALREADY_CLEAR)
170  {
172  MarkLockClear(locallock);
173  }
174 
175  return true;
176 }
void AcceptInvalidationMessages(void)
Definition: inval.c:688
static void SetLocktagRelationOid(LOCKTAG *tag, Oid relid)
Definition: lmgr.c:90
Definition: lock.h:166
void MarkLockClear(LOCALLOCK *locallock)
Definition: lock.c:1799
LockAcquireResult
Definition: lock.h:491
LockAcquireResult LockAcquireExtended(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait, bool reportMemoryError, LOCALLOCK **locallockp)
Definition: lock.c:771

◆ ConditionalLockTuple()

bool ConditionalLockTuple ( Relation  relation,
ItemPointer  tid,
LOCKMODE  lockmode 
)

Definition at line 561 of file lmgr.c.

References LockRelId::dbId, ItemPointerGetBlockNumber, ItemPointerGetOffsetNumber, LockAcquire(), LOCKACQUIRE_NOT_AVAIL, LockInfoData::lockRelId, RelationData::rd_lockInfo, LockRelId::relId, and SET_LOCKTAG_TUPLE.

562 {
563  LOCKTAG tag;
564 
565  SET_LOCKTAG_TUPLE(tag,
566  relation->rd_lockInfo.lockRelId.dbId,
567  relation->rd_lockInfo.lockRelId.relId,
570 
571  return (LockAcquire(&tag, lockmode, false, true) != LOCKACQUIRE_NOT_AVAIL);
572 }
#define SET_LOCKTAG_TUPLE(locktag, dboid, reloid, blocknum, offnum)
Definition: lock.h:219
LockRelId lockRelId
Definition: rel.h:45
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:747
Oid dbId
Definition: rel.h:40
Definition: lock.h:166
LockInfoData rd_lockInfo
Definition: rel.h:112
#define ItemPointerGetOffsetNumber(pointer)
Definition: itemptr.h:117
#define ItemPointerGetBlockNumber(pointer)
Definition: itemptr.h:98
Oid relId
Definition: rel.h:39

◆ ConditionalXactLockTableWait()

bool ConditionalXactLockTableWait ( TransactionId  xid)

Definition at line 713 of file lmgr.c.

References Assert, GetTopTransactionIdIfAny(), LockAcquire(), LOCKACQUIRE_NOT_AVAIL, LockRelease(), pg_usleep(), SET_LOCKTAG_TRANSACTION, ShareLock, SubTransGetTopmostTransaction(), TransactionIdEquals, TransactionIdIsInProgress(), and TransactionIdIsValid.

Referenced by Do_MultiXactIdWait(), heap_lock_tuple(), and heapam_tuple_lock().

714 {
715  LOCKTAG tag;
716  bool first = true;
717 
718  for (;;)
719  {
722 
723  SET_LOCKTAG_TRANSACTION(tag, xid);
724 
725  if (LockAcquire(&tag, ShareLock, false, true) == LOCKACQUIRE_NOT_AVAIL)
726  return false;
727 
728  LockRelease(&tag, ShareLock, false);
729 
730  if (!TransactionIdIsInProgress(xid))
731  break;
732 
733  /* See XactLockTableWait about this case */
734  if (!first)
735  pg_usleep(1000L);
736  first = false;
738  }
739 
740  return true;
741 }
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:747
#define TransactionIdEquals(id1, id2)
Definition: transam.h:43
TransactionId SubTransGetTopmostTransaction(TransactionId xid)
Definition: subtrans.c:150
bool TransactionIdIsInProgress(TransactionId xid)
Definition: procarray.c:1359
Definition: lock.h:166
void pg_usleep(long microsec)
Definition: signal.c:53
TransactionId GetTopTransactionIdIfAny(void)
Definition: xact.c:425
#define Assert(condition)
Definition: c.h:804
#define SET_LOCKTAG_TRANSACTION(locktag, xid)
Definition: lock.h:228
#define ShareLock
Definition: lockdefs.h:41
bool LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
Definition: lock.c:1975
#define TransactionIdIsValid(xid)
Definition: transam.h:41

◆ DescribeLockTag()

void DescribeLockTag ( StringInfo  buf,
const LOCKTAG tag 
)

Definition at line 1100 of file lmgr.c.

References _, appendStringInfo(), LOCKTAG_ADVISORY, LOCKTAG_DATABASE_FROZEN_IDS, LOCKTAG::locktag_field1, LOCKTAG::locktag_field2, LOCKTAG::locktag_field3, LOCKTAG::locktag_field4, LOCKTAG_OBJECT, LOCKTAG_PAGE, LOCKTAG_RELATION, LOCKTAG_RELATION_EXTEND, LOCKTAG_SPECULATIVE_TOKEN, LOCKTAG_TRANSACTION, LOCKTAG_TUPLE, LOCKTAG::locktag_type, LOCKTAG_USERLOCK, and LOCKTAG_VIRTUALTRANSACTION.

Referenced by DeadLockReport(), and ProcSleep().

1101 {
1102  switch ((LockTagType) tag->locktag_type)
1103  {
1104  case LOCKTAG_RELATION:
1105  appendStringInfo(buf,
1106  _("relation %u of database %u"),
1107  tag->locktag_field2,
1108  tag->locktag_field1);
1109  break;
1111  appendStringInfo(buf,
1112  _("extension of relation %u of database %u"),
1113  tag->locktag_field2,
1114  tag->locktag_field1);
1115  break;
1117  appendStringInfo(buf,
1118  _("pg_database.datfrozenxid of database %u"),
1119  tag->locktag_field1);
1120  break;
1121  case LOCKTAG_PAGE:
1122  appendStringInfo(buf,
1123  _("page %u of relation %u of database %u"),
1124  tag->locktag_field3,
1125  tag->locktag_field2,
1126  tag->locktag_field1);
1127  break;
1128  case LOCKTAG_TUPLE:
1129  appendStringInfo(buf,
1130  _("tuple (%u,%u) of relation %u of database %u"),
1131  tag->locktag_field3,
1132  tag->locktag_field4,
1133  tag->locktag_field2,
1134  tag->locktag_field1);
1135  break;
1136  case LOCKTAG_TRANSACTION:
1137  appendStringInfo(buf,
1138  _("transaction %u"),
1139  tag->locktag_field1);
1140  break;
1142  appendStringInfo(buf,
1143  _("virtual transaction %d/%u"),
1144  tag->locktag_field1,
1145  tag->locktag_field2);
1146  break;
1148  appendStringInfo(buf,
1149  _("speculative token %u of transaction %u"),
1150  tag->locktag_field2,
1151  tag->locktag_field1);
1152  break;
1153  case LOCKTAG_OBJECT:
1154  appendStringInfo(buf,
1155  _("object %u of class %u of database %u"),
1156  tag->locktag_field3,
1157  tag->locktag_field2,
1158  tag->locktag_field1);
1159  break;
1160  case LOCKTAG_USERLOCK:
1161  /* reserved for old contrib code, now on pgfoundry */
1162  appendStringInfo(buf,
1163  _("user lock [%u,%u,%u]"),
1164  tag->locktag_field1,
1165  tag->locktag_field2,
1166  tag->locktag_field3);
1167  break;
1168  case LOCKTAG_ADVISORY:
1169  appendStringInfo(buf,
1170  _("advisory lock [%u,%u,%u,%u]"),
1171  tag->locktag_field1,
1172  tag->locktag_field2,
1173  tag->locktag_field3,
1174  tag->locktag_field4);
1175  break;
1176  default:
1177  appendStringInfo(buf,
1178  _("unrecognized locktag type %d"),
1179  (int) tag->locktag_type);
1180  break;
1181  }
1182 }
uint16 locktag_field4
Definition: lock.h:171
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
uint32 locktag_field2
Definition: lock.h:169
uint8 locktag_type
Definition: lock.h:172
LockTagType
Definition: lock.h:139
uint32 locktag_field1
Definition: lock.h:168
#define _(x)
Definition: elog.c:89
uint32 locktag_field3
Definition: lock.h:170

◆ GetLockNameFromTagType()

const char* GetLockNameFromTagType ( uint16  locktag_type)

Definition at line 1190 of file lmgr.c.

References LOCKTAG_LAST_TYPE, and LockTagTypeNames.

Referenced by pgstat_get_wait_event().

1191 {
1192  if (locktag_type > LOCKTAG_LAST_TYPE)
1193  return "???";
1194  return LockTagTypeNames[locktag_type];
1195 }
#define LOCKTAG_LAST_TYPE
Definition: lock.h:154
const char *const LockTagTypeNames[]
Definition: lockfuncs.c:29

◆ LockDatabaseFrozenIds()

void LockDatabaseFrozenIds ( LOCKMODE  lockmode)

Definition at line 470 of file lmgr.c.

References LockAcquire(), MyDatabaseId, and SET_LOCKTAG_DATABASE_FROZEN_IDS.

Referenced by vac_update_datfrozenxid().

471 {
472  LOCKTAG tag;
473 
475 
476  (void) LockAcquire(&tag, lockmode, false, false);
477 }
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:747
Definition: lock.h:166
Oid MyDatabaseId
Definition: globals.c:88
#define SET_LOCKTAG_DATABASE_FROZEN_IDS(locktag, dboid)
Definition: lock.h:201

◆ LockDatabaseObject()

void LockDatabaseObject ( Oid  classid,
Oid  objid,
uint16  objsubid,
LOCKMODE  lockmode 
)

Definition at line 976 of file lmgr.c.

References AcceptInvalidationMessages(), LockAcquire(), MyDatabaseId, and SET_LOCKTAG_OBJECT.

Referenced by AcquireDeletionLock(), AddEnumLabel(), get_object_address(), RangeVarGetAndCheckCreationNamespace(), and RenameEnumLabel().

978 {
979  LOCKTAG tag;
980 
981  SET_LOCKTAG_OBJECT(tag,
982  MyDatabaseId,
983  classid,
984  objid,
985  objsubid);
986 
987  (void) LockAcquire(&tag, lockmode, false, false);
988 
989  /* Make sure syscaches are up-to-date with any changes we waited for */
991 }
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:747
void AcceptInvalidationMessages(void)
Definition: inval.c:688
Definition: lock.h:166
Oid MyDatabaseId
Definition: globals.c:88
#define SET_LOCKTAG_OBJECT(locktag, dboid, classoid, objoid, objsubid)
Definition: lock.h:264

◆ LockHasWaitersRelation()

bool LockHasWaitersRelation ( Relation  relation,
LOCKMODE  lockmode 
)

Definition at line 346 of file lmgr.c.

References LockRelId::dbId, LockHasWaiters(), LockInfoData::lockRelId, RelationData::rd_lockInfo, LockRelId::relId, and SET_LOCKTAG_RELATION.

Referenced by count_nondeletable_pages().

347 {
348  LOCKTAG tag;
349 
351  relation->rd_lockInfo.lockRelId.dbId,
352  relation->rd_lockInfo.lockRelId.relId);
353 
354  return LockHasWaiters(&tag, lockmode, false);
355 }
LockRelId lockRelId
Definition: rel.h:45
Oid dbId
Definition: rel.h:40
Definition: lock.h:166
#define SET_LOCKTAG_RELATION(locktag, dboid, reloid)
Definition: lock.h:183
LockInfoData rd_lockInfo
Definition: rel.h:112
bool LockHasWaiters(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
Definition: lock.c:634
Oid relId
Definition: rel.h:39

◆ LockPage()

void LockPage ( Relation  relation,
BlockNumber  blkno,
LOCKMODE  lockmode 
)

Definition at line 486 of file lmgr.c.

References LockRelId::dbId, LockAcquire(), LockInfoData::lockRelId, RelationData::rd_lockInfo, LockRelId::relId, and SET_LOCKTAG_PAGE.

Referenced by ginInsertCleanup().

487 {
488  LOCKTAG tag;
489 
490  SET_LOCKTAG_PAGE(tag,
491  relation->rd_lockInfo.lockRelId.dbId,
492  relation->rd_lockInfo.lockRelId.relId,
493  blkno);
494 
495  (void) LockAcquire(&tag, lockmode, false, false);
496 }
LockRelId lockRelId
Definition: rel.h:45
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:747
Oid dbId
Definition: rel.h:40
Definition: lock.h:166
LockInfoData rd_lockInfo
Definition: rel.h:112
#define SET_LOCKTAG_PAGE(locktag, dboid, reloid, blocknum)
Definition: lock.h:210
Oid relId
Definition: rel.h:39

◆ LockRelation()

void LockRelation ( Relation  relation,
LOCKMODE  lockmode 
)

Definition at line 217 of file lmgr.c.

References AcceptInvalidationMessages(), LockRelId::dbId, LOCKACQUIRE_ALREADY_CLEAR, LockAcquireExtended(), LockInfoData::lockRelId, MarkLockClear(), RelationData::rd_lockInfo, LockRelId::relId, and SET_LOCKTAG_RELATION.

Referenced by index_create().

218 {
219  LOCKTAG tag;
220  LOCALLOCK *locallock;
221  LockAcquireResult res;
222 
224  relation->rd_lockInfo.lockRelId.dbId,
225  relation->rd_lockInfo.lockRelId.relId);
226 
227  res = LockAcquireExtended(&tag, lockmode, false, false, true, &locallock);
228 
229  /*
230  * Now that we have the lock, check for invalidation messages; see notes
231  * in LockRelationOid.
232  */
233  if (res != LOCKACQUIRE_ALREADY_CLEAR)
234  {
236  MarkLockClear(locallock);
237  }
238 }
LockRelId lockRelId
Definition: rel.h:45
void AcceptInvalidationMessages(void)
Definition: inval.c:688
Oid dbId
Definition: rel.h:40
Definition: lock.h:166
#define SET_LOCKTAG_RELATION(locktag, dboid, reloid)
Definition: lock.h:183
LockInfoData rd_lockInfo
Definition: rel.h:112
void MarkLockClear(LOCALLOCK *locallock)
Definition: lock.c:1799
LockAcquireResult
Definition: lock.h:491
LockAcquireResult LockAcquireExtended(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait, bool reportMemoryError, LOCALLOCK **locallockp)
Definition: lock.c:771
Oid relId
Definition: rel.h:39

◆ LockRelationForExtension()

void LockRelationForExtension ( Relation  relation,
LOCKMODE  lockmode 
)

Definition at line 403 of file lmgr.c.

References LockRelId::dbId, LockAcquire(), LockInfoData::lockRelId, RelationData::rd_lockInfo, LockRelId::relId, and SET_LOCKTAG_RELATION_EXTEND.

Referenced by _bt_getbuf(), BloomNewBuffer(), brin_getinsertbuffer(), brin_page_cleanup(), btvacuumscan(), fsm_extend(), GinNewBuffer(), ginvacuumcleanup(), gistNewBuffer(), gistvacuumscan(), pgstat_index(), RelationGetBufferForTuple(), revmap_physical_extend(), SpGistNewBuffer(), spgvacuumscan(), and vm_extend().

404 {
405  LOCKTAG tag;
406 
408  relation->rd_lockInfo.lockRelId.dbId,
409  relation->rd_lockInfo.lockRelId.relId);
410 
411  (void) LockAcquire(&tag, lockmode, false, false);
412 }
LockRelId lockRelId
Definition: rel.h:45
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:747
Oid dbId
Definition: rel.h:40
Definition: lock.h:166
LockInfoData rd_lockInfo
Definition: rel.h:112
#define SET_LOCKTAG_RELATION_EXTEND(locktag, dboid, reloid)
Definition: lock.h:192
Oid relId
Definition: rel.h:39

◆ LockRelationIdForSession()

void LockRelationIdForSession ( LockRelId relid,
LOCKMODE  lockmode 
)

Definition at line 370 of file lmgr.c.

References LockRelId::dbId, LockAcquire(), LockRelId::relId, and SET_LOCKTAG_RELATION.

Referenced by DefineIndex(), index_drop(), ReindexRelationConcurrently(), and vacuum_rel().

371 {
372  LOCKTAG tag;
373 
374  SET_LOCKTAG_RELATION(tag, relid->dbId, relid->relId);
375 
376  (void) LockAcquire(&tag, lockmode, true, false);
377 }
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:747
Oid dbId
Definition: rel.h:40
Definition: lock.h:166
#define SET_LOCKTAG_RELATION(locktag, dboid, reloid)
Definition: lock.h:183
Oid relId
Definition: rel.h:39

◆ LockRelationOid()

void LockRelationOid ( Oid  relid,
LOCKMODE  lockmode 
)

Definition at line 109 of file lmgr.c.

References AcceptInvalidationMessages(), LOCKACQUIRE_ALREADY_CLEAR, LockAcquireExtended(), MarkLockClear(), and SetLocktagRelationOid().

Referenced by AcquireDeletionLock(), AcquireExecutorLocks(), AlterTableMoveAll(), ATExecAttachPartition(), ATExecDetachPartition(), ATPostAlterTypeCleanup(), copy_table_data(), CreateTriggerFiringOn(), ExecRefreshMatView(), find_inheritance_children_extended(), heap_drop_with_catalog(), InitCatCachePhase2(), load_critical_index(), lock_and_open_sequence(), LockTableRecurse(), LockViewRecurse_walker(), LogicalRepSyncTableStart(), pg_replication_origin_advance(), RangeVarCallbackForAttachIndex(), RangeVarCallbackForDropRelation(), RangeVarCallbackForReindexIndex(), RangeVarGetAndCheckCreationNamespace(), RangeVarGetRelidExtended(), relation_open(), ScanQueryForLocks(), and try_relation_open().

110 {
111  LOCKTAG tag;
112  LOCALLOCK *locallock;
113  LockAcquireResult res;
114 
115  SetLocktagRelationOid(&tag, relid);
116 
117  res = LockAcquireExtended(&tag, lockmode, false, false, true, &locallock);
118 
119  /*
120  * Now that we have the lock, check for invalidation messages, so that we
121  * will update or flush any stale relcache entry before we try to use it.
122  * RangeVarGetRelid() specifically relies on us for this. We can skip
123  * this in the not-uncommon case that we already had the same type of lock
124  * being requested, since then no one else could have modified the
125  * relcache entry in an undesirable way. (In the case where our own xact
126  * modifies the rel, the relcache update happens via
127  * CommandCounterIncrement, not here.)
128  *
129  * However, in corner cases where code acts on tables (usually catalogs)
130  * recursively, we might get here while still processing invalidation
131  * messages in some outer execution of this function or a sibling. The
132  * "cleared" status of the lock tells us whether we really are done
133  * absorbing relevant inval messages.
134  */
135  if (res != LOCKACQUIRE_ALREADY_CLEAR)
136  {
138  MarkLockClear(locallock);
139  }
140 }
void AcceptInvalidationMessages(void)
Definition: inval.c:688
static void SetLocktagRelationOid(LOCKTAG *tag, Oid relid)
Definition: lmgr.c:90
Definition: lock.h:166
void MarkLockClear(LOCALLOCK *locallock)
Definition: lock.c:1799
LockAcquireResult
Definition: lock.h:491
LockAcquireResult LockAcquireExtended(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait, bool reportMemoryError, LOCALLOCK **locallockp)
Definition: lock.c:771

◆ LockSharedObject()

void LockSharedObject ( Oid  classid,
Oid  objid,
uint16  objsubid,
LOCKMODE  lockmode 
)

Definition at line 1017 of file lmgr.c.

References AcceptInvalidationMessages(), InvalidOid, LockAcquire(), and SET_LOCKTAG_OBJECT.

Referenced by AddSubscriptionRelState(), AlterSubscription(), DropRole(), DropSubscription(), get_db_info(), get_object_address(), InitPostgres(), PreCommit_Notify(), shdepLockAndCheckObject(), and UpdateSubscriptionRelState().

1019 {
1020  LOCKTAG tag;
1021 
1022  SET_LOCKTAG_OBJECT(tag,
1023  InvalidOid,
1024  classid,
1025  objid,
1026  objsubid);
1027 
1028  (void) LockAcquire(&tag, lockmode, false, false);
1029 
1030  /* Make sure syscaches are up-to-date with any changes we waited for */
1032 }
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:747
void AcceptInvalidationMessages(void)
Definition: inval.c:688
Definition: lock.h:166
#define InvalidOid
Definition: postgres_ext.h:36
#define SET_LOCKTAG_OBJECT(locktag, dboid, classoid, objoid, objsubid)
Definition: lock.h:264

◆ LockSharedObjectForSession()

void LockSharedObjectForSession ( Oid  classid,
Oid  objid,
uint16  objsubid,
LOCKMODE  lockmode 
)

Definition at line 1059 of file lmgr.c.

References InvalidOid, LockAcquire(), and SET_LOCKTAG_OBJECT.

Referenced by dbase_redo(), and movedb().

1061 {
1062  LOCKTAG tag;
1063 
1064  SET_LOCKTAG_OBJECT(tag,
1065  InvalidOid,
1066  classid,
1067  objid,
1068  objsubid);
1069 
1070  (void) LockAcquire(&tag, lockmode, true, false);
1071 }
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:747
Definition: lock.h:166
#define InvalidOid
Definition: postgres_ext.h:36
#define SET_LOCKTAG_OBJECT(locktag, dboid, classoid, objoid, objsubid)
Definition: lock.h:264

◆ LockTuple()

void LockTuple ( Relation  relation,
ItemPointer  tid,
LOCKMODE  lockmode 
)

Definition at line 541 of file lmgr.c.

References LockRelId::dbId, ItemPointerGetBlockNumber, ItemPointerGetOffsetNumber, LockAcquire(), LockInfoData::lockRelId, RelationData::rd_lockInfo, LockRelId::relId, and SET_LOCKTAG_TUPLE.

542 {
543  LOCKTAG tag;
544 
545  SET_LOCKTAG_TUPLE(tag,
546  relation->rd_lockInfo.lockRelId.dbId,
547  relation->rd_lockInfo.lockRelId.relId,
550 
551  (void) LockAcquire(&tag, lockmode, false, false);
552 }
#define SET_LOCKTAG_TUPLE(locktag, dboid, reloid, blocknum, offnum)
Definition: lock.h:219
LockRelId lockRelId
Definition: rel.h:45
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:747
Oid dbId
Definition: rel.h:40
Definition: lock.h:166
LockInfoData rd_lockInfo
Definition: rel.h:112
#define ItemPointerGetOffsetNumber(pointer)
Definition: itemptr.h:117
#define ItemPointerGetBlockNumber(pointer)
Definition: itemptr.h:98
Oid relId
Definition: rel.h:39

◆ RelationExtensionLockWaiterCount()

int RelationExtensionLockWaiterCount ( Relation  relation)

Definition at line 438 of file lmgr.c.

References LockRelId::dbId, LockInfoData::lockRelId, LockWaiterCount(), RelationData::rd_lockInfo, LockRelId::relId, and SET_LOCKTAG_RELATION_EXTEND.

Referenced by RelationAddExtraBlocks().

439 {
440  LOCKTAG tag;
441 
443  relation->rd_lockInfo.lockRelId.dbId,
444  relation->rd_lockInfo.lockRelId.relId);
445 
446  return LockWaiterCount(&tag);
447 }
LockRelId lockRelId
Definition: rel.h:45
Oid dbId
Definition: rel.h:40
Definition: lock.h:166
LockInfoData rd_lockInfo
Definition: rel.h:112
int LockWaiterCount(const LOCKTAG *locktag)
Definition: lock.c:4653
#define SET_LOCKTAG_RELATION_EXTEND(locktag, dboid, reloid)
Definition: lock.h:192
Oid relId
Definition: rel.h:39

◆ RelationInitLockInfo()

void RelationInitLockInfo ( Relation  relation)

Definition at line 72 of file lmgr.c.

References Assert, LockRelId::dbId, InvalidOid, LockInfoData::lockRelId, MyDatabaseId, OidIsValid, RelationData::rd_lockInfo, RelationData::rd_rel, RelationGetRelid, RelationIsValid, and LockRelId::relId.

Referenced by formrdesc(), load_relcache_init_file(), RelationBuildDesc(), and RelationBuildLocalRelation().

73 {
74  Assert(RelationIsValid(relation));
76 
77  relation->rd_lockInfo.lockRelId.relId = RelationGetRelid(relation);
78 
79  if (relation->rd_rel->relisshared)
81  else
83 }
LockRelId lockRelId
Definition: rel.h:45
Oid dbId
Definition: rel.h:40
Form_pg_class rd_rel
Definition: rel.h:109
#define OidIsValid(objectId)
Definition: c.h:710
#define RelationIsValid(relation)
Definition: rel.h:450
LockInfoData rd_lockInfo
Definition: rel.h:112
Oid MyDatabaseId
Definition: globals.c:88
#define InvalidOid
Definition: postgres_ext.h:36
#define Assert(condition)
Definition: c.h:804
#define RelationGetRelid(relation)
Definition: rel.h:477
Oid relId
Definition: rel.h:39

◆ SpeculativeInsertionLockAcquire()

uint32 SpeculativeInsertionLockAcquire ( TransactionId  xid)

Definition at line 755 of file lmgr.c.

References ExclusiveLock, LockAcquire(), SET_LOCKTAG_SPECULATIVE_INSERTION, and speculativeInsertionToken.

Referenced by ExecInsert().

756 {
757  LOCKTAG tag;
758 
760 
761  /*
762  * Check for wrap-around. Zero means no token is held, so don't use that.
763  */
764  if (speculativeInsertionToken == 0)
766 
768 
769  (void) LockAcquire(&tag, ExclusiveLock, false, false);
770 
772 }
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:747
#define ExclusiveLock
Definition: lockdefs.h:44
Definition: lock.h:166
#define SET_LOCKTAG_SPECULATIVE_INSERTION(locktag, xid, token)
Definition: lock.h:249
static uint32 speculativeInsertionToken
Definition: lmgr.c:47

◆ SpeculativeInsertionLockRelease()

void SpeculativeInsertionLockRelease ( TransactionId  xid)

Definition at line 781 of file lmgr.c.

References ExclusiveLock, LockRelease(), SET_LOCKTAG_SPECULATIVE_INSERTION, and speculativeInsertionToken.

Referenced by ExecInsert().

782 {
783  LOCKTAG tag;
784 
786 
787  LockRelease(&tag, ExclusiveLock, false);
788 }
#define ExclusiveLock
Definition: lockdefs.h:44
Definition: lock.h:166
#define SET_LOCKTAG_SPECULATIVE_INSERTION(locktag, xid, token)
Definition: lock.h:249
static uint32 speculativeInsertionToken
Definition: lmgr.c:47
bool LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
Definition: lock.c:1975

◆ SpeculativeInsertionWait()

void SpeculativeInsertionWait ( TransactionId  xid,
uint32  token 
)

Definition at line 797 of file lmgr.c.

References Assert, LockAcquire(), LockRelease(), SET_LOCKTAG_SPECULATIVE_INSERTION, ShareLock, and TransactionIdIsValid.

Referenced by _bt_doinsert(), and check_exclusion_or_unique_constraint().

798 {
799  LOCKTAG tag;
800 
801  SET_LOCKTAG_SPECULATIVE_INSERTION(tag, xid, token);
802 
804  Assert(token != 0);
805 
806  (void) LockAcquire(&tag, ShareLock, false, false);
807  LockRelease(&tag, ShareLock, false);
808 }
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:747
Definition: lock.h:166
#define SET_LOCKTAG_SPECULATIVE_INSERTION(locktag, xid, token)
Definition: lock.h:249
#define Assert(condition)
Definition: c.h:804
#define ShareLock
Definition: lockdefs.h:41
bool LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
Definition: lock.c:1975
#define TransactionIdIsValid(xid)
Definition: transam.h:41

◆ UnlockDatabaseObject()

void UnlockDatabaseObject ( Oid  classid,
Oid  objid,
uint16  objsubid,
LOCKMODE  lockmode 
)

Definition at line 997 of file lmgr.c.

References LockRelease(), MyDatabaseId, and SET_LOCKTAG_OBJECT.

Referenced by get_object_address(), RangeVarGetAndCheckCreationNamespace(), and ReleaseDeletionLock().

999 {
1000  LOCKTAG tag;
1001 
1002  SET_LOCKTAG_OBJECT(tag,
1003  MyDatabaseId,
1004  classid,
1005  objid,
1006  objsubid);
1007 
1008  LockRelease(&tag, lockmode, false);
1009 }
Definition: lock.h:166
Oid MyDatabaseId
Definition: globals.c:88
#define SET_LOCKTAG_OBJECT(locktag, dboid, classoid, objoid, objsubid)
Definition: lock.h:264
bool LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
Definition: lock.c:1975

◆ UnlockPage()

void UnlockPage ( Relation  relation,
BlockNumber  blkno,
LOCKMODE  lockmode 
)

Definition at line 521 of file lmgr.c.

References LockRelId::dbId, LockRelease(), LockInfoData::lockRelId, RelationData::rd_lockInfo, LockRelId::relId, and SET_LOCKTAG_PAGE.

Referenced by ginInsertCleanup().

522 {
523  LOCKTAG tag;
524 
525  SET_LOCKTAG_PAGE(tag,
526  relation->rd_lockInfo.lockRelId.dbId,
527  relation->rd_lockInfo.lockRelId.relId,
528  blkno);
529 
530  LockRelease(&tag, lockmode, false);
531 }
LockRelId lockRelId
Definition: rel.h:45
Oid dbId
Definition: rel.h:40
Definition: lock.h:166
LockInfoData rd_lockInfo
Definition: rel.h:112
#define SET_LOCKTAG_PAGE(locktag, dboid, reloid, blocknum)
Definition: lock.h:210
bool LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
Definition: lock.c:1975
Oid relId
Definition: rel.h:39

◆ UnlockRelation()

void UnlockRelation ( Relation  relation,
LOCKMODE  lockmode 
)

Definition at line 283 of file lmgr.c.

References LockRelId::dbId, LockRelease(), LockInfoData::lockRelId, RelationData::rd_lockInfo, LockRelId::relId, and SET_LOCKTAG_RELATION.

Referenced by lazy_truncate_heap().

284 {
285  LOCKTAG tag;
286 
288  relation->rd_lockInfo.lockRelId.dbId,
289  relation->rd_lockInfo.lockRelId.relId);
290 
291  LockRelease(&tag, lockmode, false);
292 }
LockRelId lockRelId
Definition: rel.h:45
Oid dbId
Definition: rel.h:40
Definition: lock.h:166
#define SET_LOCKTAG_RELATION(locktag, dboid, reloid)
Definition: lock.h:183
LockInfoData rd_lockInfo
Definition: rel.h:112
bool LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
Definition: lock.c:1975
Oid relId
Definition: rel.h:39

◆ UnlockRelationForExtension()

void UnlockRelationForExtension ( Relation  relation,
LOCKMODE  lockmode 
)

Definition at line 453 of file lmgr.c.

References LockRelId::dbId, LockRelease(), LockInfoData::lockRelId, RelationData::rd_lockInfo, LockRelId::relId, and SET_LOCKTAG_RELATION_EXTEND.

Referenced by _bt_getbuf(), BloomNewBuffer(), brin_getinsertbuffer(), brin_page_cleanup(), btvacuumscan(), fsm_extend(), GinNewBuffer(), ginvacuumcleanup(), gistNewBuffer(), gistvacuumscan(), pgstat_index(), RelationGetBufferForTuple(), revmap_physical_extend(), SpGistNewBuffer(), spgvacuumscan(), and vm_extend().

454 {
455  LOCKTAG tag;
456 
458  relation->rd_lockInfo.lockRelId.dbId,
459  relation->rd_lockInfo.lockRelId.relId);
460 
461  LockRelease(&tag, lockmode, false);
462 }
LockRelId lockRelId
Definition: rel.h:45
Oid dbId
Definition: rel.h:40
Definition: lock.h:166
LockInfoData rd_lockInfo
Definition: rel.h:112
bool LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
Definition: lock.c:1975
#define SET_LOCKTAG_RELATION_EXTEND(locktag, dboid, reloid)
Definition: lock.h:192
Oid relId
Definition: rel.h:39

◆ UnlockRelationId()

void UnlockRelationId ( LockRelId relid,
LOCKMODE  lockmode 
)

Definition at line 185 of file lmgr.c.

References LockRelId::dbId, LockRelease(), LockRelId::relId, and SET_LOCKTAG_RELATION.

Referenced by index_close(), and relation_close().

186 {
187  LOCKTAG tag;
188 
189  SET_LOCKTAG_RELATION(tag, relid->dbId, relid->relId);
190 
191  LockRelease(&tag, lockmode, false);
192 }
Oid dbId
Definition: rel.h:40
Definition: lock.h:166
#define SET_LOCKTAG_RELATION(locktag, dboid, reloid)
Definition: lock.h:183
bool LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
Definition: lock.c:1975
Oid relId
Definition: rel.h:39

◆ UnlockRelationIdForSession()

void UnlockRelationIdForSession ( LockRelId relid,
LOCKMODE  lockmode 
)

Definition at line 383 of file lmgr.c.

References LockRelId::dbId, LockRelease(), LockRelId::relId, and SET_LOCKTAG_RELATION.

Referenced by DefineIndex(), index_drop(), ReindexRelationConcurrently(), and vacuum_rel().

384 {
385  LOCKTAG tag;
386 
387  SET_LOCKTAG_RELATION(tag, relid->dbId, relid->relId);
388 
389  LockRelease(&tag, lockmode, true);
390 }
Oid dbId
Definition: rel.h:40
Definition: lock.h:166
#define SET_LOCKTAG_RELATION(locktag, dboid, reloid)
Definition: lock.h:183
bool LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
Definition: lock.c:1975
Oid relId
Definition: rel.h:39

◆ UnlockRelationOid()

void UnlockRelationOid ( Oid  relid,
LOCKMODE  lockmode 
)

◆ UnlockSharedObject()

void UnlockSharedObject ( Oid  classid,
Oid  objid,
uint16  objsubid,
LOCKMODE  lockmode 
)

Definition at line 1038 of file lmgr.c.

References InvalidOid, LockRelease(), and SET_LOCKTAG_OBJECT.

Referenced by AlterDatabaseSet(), createdb_failure_callback(), get_db_info(), and get_object_address().

1040 {
1041  LOCKTAG tag;
1042 
1043  SET_LOCKTAG_OBJECT(tag,
1044  InvalidOid,
1045  classid,
1046  objid,
1047  objsubid);
1048 
1049  LockRelease(&tag, lockmode, false);
1050 }
Definition: lock.h:166
#define InvalidOid
Definition: postgres_ext.h:36
#define SET_LOCKTAG_OBJECT(locktag, dboid, classoid, objoid, objsubid)
Definition: lock.h:264
bool LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
Definition: lock.c:1975

◆ UnlockSharedObjectForSession()

void UnlockSharedObjectForSession ( Oid  classid,
Oid  objid,
uint16  objsubid,
LOCKMODE  lockmode 
)

Definition at line 1077 of file lmgr.c.

References InvalidOid, LockRelease(), and SET_LOCKTAG_OBJECT.

Referenced by dbase_redo(), and movedb().

1079 {
1080  LOCKTAG tag;
1081 
1082  SET_LOCKTAG_OBJECT(tag,
1083  InvalidOid,
1084  classid,
1085  objid,
1086  objsubid);
1087 
1088  LockRelease(&tag, lockmode, true);
1089 }
Definition: lock.h:166
#define InvalidOid
Definition: postgres_ext.h:36
#define SET_LOCKTAG_OBJECT(locktag, dboid, classoid, objoid, objsubid)
Definition: lock.h:264
bool LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
Definition: lock.c:1975

◆ UnlockTuple()

void UnlockTuple ( Relation  relation,
ItemPointer  tid,
LOCKMODE  lockmode 
)

Definition at line 578 of file lmgr.c.

References LockRelId::dbId, ItemPointerGetBlockNumber, ItemPointerGetOffsetNumber, LockRelease(), LockInfoData::lockRelId, RelationData::rd_lockInfo, LockRelId::relId, and SET_LOCKTAG_TUPLE.

579 {
580  LOCKTAG tag;
581 
582  SET_LOCKTAG_TUPLE(tag,
583  relation->rd_lockInfo.lockRelId.dbId,
584  relation->rd_lockInfo.lockRelId.relId,
587 
588  LockRelease(&tag, lockmode, false);
589 }
#define SET_LOCKTAG_TUPLE(locktag, dboid, reloid, blocknum, offnum)
Definition: lock.h:219
LockRelId lockRelId
Definition: rel.h:45
Oid dbId
Definition: rel.h:40
Definition: lock.h:166
LockInfoData rd_lockInfo
Definition: rel.h:112
#define ItemPointerGetOffsetNumber(pointer)
Definition: itemptr.h:117
bool LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
Definition: lock.c:1975
#define ItemPointerGetBlockNumber(pointer)
Definition: itemptr.h:98
Oid relId
Definition: rel.h:39

◆ WaitForLockers()

void WaitForLockers ( LOCKTAG  heaplocktag,
LOCKMODE  lockmode,
bool  progress 
)

Definition at line 957 of file lmgr.c.

References list_free(), list_make1, and WaitForLockersMultiple().

Referenced by DefineIndex(), and index_drop().

958 {
959  List *l;
960 
961  l = list_make1(&heaplocktag);
962  WaitForLockersMultiple(l, lockmode, progress);
963  list_free(l);
964 }
void WaitForLockersMultiple(List *locktags, LOCKMODE lockmode, bool progress)
Definition: lmgr.c:879
#define list_make1(x1)
Definition: pg_list.h:206
int progress
Definition: pgbench.c:272
void list_free(List *list)
Definition: list.c:1391
Definition: pg_list.h:50

◆ WaitForLockersMultiple()

void WaitForLockersMultiple ( List locktags,
LOCKMODE  lockmode,
bool  progress 
)

Definition at line 879 of file lmgr.c.

References VirtualTransactionId::backendId, BackendIdGetProc(), GetLockConflicts(), lappend(), lfirst, list_free_deep(), list_length(), NIL, pgstat_progress_update_multi_param(), pgstat_progress_update_param(), PGPROC::pid, PROGRESS_WAITFOR_CURRENT_PID, PROGRESS_WAITFOR_DONE, PROGRESS_WAITFOR_TOTAL, values, VirtualTransactionIdIsValid, and VirtualXactLock().

Referenced by ATExecDetachPartition(), ReindexRelationConcurrently(), and WaitForLockers().

880 {
881  List *holders = NIL;
882  ListCell *lc;
883  int total = 0;
884  int done = 0;
885 
886  /* Done if no locks to wait for */
887  if (list_length(locktags) == 0)
888  return;
889 
890  /* Collect the transactions we need to wait on */
891  foreach(lc, locktags)
892  {
893  LOCKTAG *locktag = lfirst(lc);
894  int count;
895 
896  holders = lappend(holders,
897  GetLockConflicts(locktag, lockmode,
898  progress ? &count : NULL));
899  if (progress)
900  total += count;
901  }
902 
903  if (progress)
905 
906  /*
907  * Note: GetLockConflicts() never reports our own xid, hence we need not
908  * check for that. Also, prepared xacts are reported and awaited.
909  */
910 
911  /* Finally wait for each such transaction to complete */
912  foreach(lc, holders)
913  {
914  VirtualTransactionId *lockholders = lfirst(lc);
915 
916  while (VirtualTransactionIdIsValid(*lockholders))
917  {
918  /* If requested, publish who we're going to wait for. */
919  if (progress)
920  {
921  PGPROC *holder = BackendIdGetProc(lockholders->backendId);
922 
923  if (holder)
925  holder->pid);
926  }
927  VirtualXactLock(*lockholders, true);
928  lockholders++;
929 
930  if (progress)
932  }
933  }
934  if (progress)
935  {
936  const int index[] = {
940  };
941  const int64 values[] = {
942  0, 0, 0
943  };
944 
945  pgstat_progress_update_multi_param(3, index, values);
946  }
947 
948  list_free_deep(holders);
949 }
#define NIL
Definition: pg_list.h:65
Definition: lock.h:166
void list_free_deep(List *list)
Definition: list.c:1405
void pgstat_progress_update_multi_param(int nparam, const int *index, const int64 *val)
Definition: type.h:89
bool VirtualXactLock(VirtualTransactionId vxid, bool wait)
Definition: lock.c:4542
#define PROGRESS_WAITFOR_CURRENT_PID
Definition: progress.h:116
List * lappend(List *list, void *datum)
Definition: list.c:336
#define VirtualTransactionIdIsValid(vxid)
Definition: lock.h:71
int progress
Definition: pgbench.c:272
VirtualTransactionId * GetLockConflicts(const LOCKTAG *locktag, LOCKMODE lockmode, int *countp)
Definition: lock.c:2910
#define lfirst(lc)
Definition: pg_list.h:169
void pgstat_progress_update_param(int index, int64 val)
BackendId backendId
Definition: lock.h:65
#define PROGRESS_WAITFOR_DONE
Definition: progress.h:115
static int list_length(const List *l)
Definition: pg_list.h:149
static Datum values[MAXATTR]
Definition: bootstrap.c:166
#define PROGRESS_WAITFOR_TOTAL
Definition: progress.h:114
Definition: proc.h:121
Definition: pg_list.h:50
int pid
Definition: proc.h:146
PGPROC * BackendIdGetProc(int backendID)
Definition: sinvaladt.c:376

◆ XactLockTableDelete()

void XactLockTableDelete ( TransactionId  xid)

Definition at line 616 of file lmgr.c.

References ExclusiveLock, LockRelease(), and SET_LOCKTAG_TRANSACTION.

Referenced by CommitSubTransaction().

617 {
618  LOCKTAG tag;
619 
620  SET_LOCKTAG_TRANSACTION(tag, xid);
621 
622  LockRelease(&tag, ExclusiveLock, false);
623 }
#define ExclusiveLock
Definition: lockdefs.h:44
Definition: lock.h:166
#define SET_LOCKTAG_TRANSACTION(locktag, xid)
Definition: lock.h:228
bool LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
Definition: lock.c:1975

◆ XactLockTableInsert()

void XactLockTableInsert ( TransactionId  xid)

Definition at line 599 of file lmgr.c.

References ExclusiveLock, LockAcquire(), and SET_LOCKTAG_TRANSACTION.

Referenced by AssignTransactionId().

600 {
601  LOCKTAG tag;
602 
603  SET_LOCKTAG_TRANSACTION(tag, xid);
604 
605  (void) LockAcquire(&tag, ExclusiveLock, false, false);
606 }
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:747
#define ExclusiveLock
Definition: lockdefs.h:44
Definition: lock.h:166
#define SET_LOCKTAG_TRANSACTION(locktag, xid)
Definition: lock.h:228

◆ XactLockTableWait()

void XactLockTableWait ( TransactionId  xid,
Relation  rel,
ItemPointer  ctid,
XLTW_Oper  oper 
)

Definition at line 640 of file lmgr.c.

References ErrorContextCallback::arg, Assert, callback(), ErrorContextCallback::callback, XactLockTableWaitInfo::ctid, error_context_stack, GetTopTransactionIdIfAny(), ItemPointerIsValid, LockAcquire(), LockRelease(), XactLockTableWaitInfo::oper, pg_usleep(), ErrorContextCallback::previous, XactLockTableWaitInfo::rel, RelationIsValid, SET_LOCKTAG_TRANSACTION, ShareLock, SubTransGetTopmostTransaction(), TransactionIdEquals, TransactionIdIsInProgress(), TransactionIdIsValid, XactLockTableWaitErrorCb(), and XLTW_None.

Referenced by _bt_doinsert(), check_exclusion_or_unique_constraint(), Do_MultiXactIdWait(), heap_delete(), heap_lock_tuple(), heap_lock_updated_tuple_rec(), heap_update(), heapam_index_build_range_scan(), heapam_tuple_lock(), RelationFindReplTupleByIndex(), RelationFindReplTupleSeq(), and SnapBuildWaitSnapshot().

642 {
643  LOCKTAG tag;
646  bool first = true;
647 
648  /*
649  * If an operation is specified, set up our verbose error context
650  * callback.
651  */
652  if (oper != XLTW_None)
653  {
654  Assert(RelationIsValid(rel));
655  Assert(ItemPointerIsValid(ctid));
656 
657  info.rel = rel;
658  info.ctid = ctid;
659  info.oper = oper;
660 
662  callback.arg = &info;
663  callback.previous = error_context_stack;
665  }
666 
667  for (;;)
668  {
671 
672  SET_LOCKTAG_TRANSACTION(tag, xid);
673 
674  (void) LockAcquire(&tag, ShareLock, false, false);
675 
676  LockRelease(&tag, ShareLock, false);
677 
678  if (!TransactionIdIsInProgress(xid))
679  break;
680 
681  /*
682  * If the Xid belonged to a subtransaction, then the lock would have
683  * gone away as soon as it was finished; for correct tuple visibility,
684  * the right action is to wait on its parent transaction to go away.
685  * But instead of going levels up one by one, we can just wait for the
686  * topmost transaction to finish with the same end result, which also
687  * incurs less locktable traffic.
688  *
689  * Some uses of this function don't involve tuple visibility -- such
690  * as when building snapshots for logical decoding. It is possible to
691  * see a transaction in ProcArray before it registers itself in the
692  * locktable. The topmost transaction in that case is the same xid,
693  * so we try again after a short sleep. (Don't sleep the first time
694  * through, to avoid slowing down the normal case.)
695  */
696  if (!first)
697  pg_usleep(1000L);
698  first = false;
700  }
701 
702  if (oper != XLTW_None)
703  error_context_stack = callback.previous;
704 }
#define ItemPointerIsValid(pointer)
Definition: itemptr.h:82
Relation rel
Definition: lmgr.c:59
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:747
#define TransactionIdEquals(id1, id2)
Definition: transam.h:43
TransactionId SubTransGetTopmostTransaction(TransactionId xid)
Definition: subtrans.c:150
bool TransactionIdIsInProgress(TransactionId xid)
Definition: procarray.c:1359
Definition: lock.h:166
void(* callback)(void *arg)
Definition: elog.h:247
struct ErrorContextCallback * previous
Definition: elog.h:246
XLTW_Oper oper
Definition: lmgr.c:58
ErrorContextCallback * error_context_stack
Definition: elog.c:93
void pg_usleep(long microsec)
Definition: signal.c:53
Definition: lmgr.h:26
#define RelationIsValid(relation)
Definition: rel.h:450
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:48
ItemPointer ctid
Definition: lmgr.c:60
TransactionId GetTopTransactionIdIfAny(void)
Definition: xact.c:425
static void XactLockTableWaitErrorCb(void *arg)
Definition: lmgr.c:815
#define Assert(condition)
Definition: c.h:804
#define SET_LOCKTAG_TRANSACTION(locktag, xid)
Definition: lock.h:228
#define ShareLock
Definition: lockdefs.h:41
bool LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
Definition: lock.c:1975
#define TransactionIdIsValid(xid)
Definition: transam.h:41
Operator oper(ParseState *pstate, List *opname, Oid ltypeId, Oid rtypeId, bool noError, int location)
Definition: parse_oper.c:382