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:4100
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:167
#define SET_LOCKTAG_RELATION(locktag, dboid, reloid)
Definition: lock.h:184
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:174
#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:167
LockInfoData rd_lockInfo
Definition: rel.h:112
#define SET_LOCKTAG_PAGE(locktag, dboid, reloid, blocknum)
Definition: lock.h:211
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:745
Oid dbId
Definition: rel.h:40
Definition: lock.h:167
#define SET_LOCKTAG_RELATION(locktag, dboid, reloid)
Definition: lock.h:184
LockInfoData rd_lockInfo
Definition: rel.h:112
void MarkLockClear(LOCALLOCK *locallock)
Definition: lock.c:1799
LockAcquireResult
Definition: lock.h:492
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:167
LockInfoData rd_lockInfo
Definition: rel.h:112
#define SET_LOCKTAG_RELATION_EXTEND(locktag, dboid, reloid)
Definition: lock.h:193
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:745
static void SetLocktagRelationOid(LOCKTAG *tag, Oid relid)
Definition: lmgr.c:90
Definition: lock.h:167
void MarkLockClear(LOCALLOCK *locallock)
Definition: lock.c:1799
LockAcquireResult
Definition: lock.h:492
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:220
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:167
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:167
void pg_usleep(long microsec)
Definition: signal.c:53
TransactionId GetTopTransactionIdIfAny(void)
Definition: xact.c:426
#define Assert(condition)
Definition: c.h:804
#define SET_LOCKTAG_TRANSACTION(locktag, xid)
Definition: lock.h:229
#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 1101 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().

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

◆ GetLockNameFromTagType()

const char* GetLockNameFromTagType ( uint16  locktag_type)

Definition at line 1191 of file lmgr.c.

References LOCKTAG_LAST_TYPE, and LockTagTypeNames.

Referenced by pgstat_get_wait_event().

1192 {
1193  if (locktag_type > LOCKTAG_LAST_TYPE)
1194  return "???";
1195  return LockTagTypeNames[locktag_type];
1196 }
#define LOCKTAG_LAST_TYPE
Definition: lock.h:155
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:167
Oid MyDatabaseId
Definition: globals.c:88
#define SET_LOCKTAG_DATABASE_FROZEN_IDS(locktag, dboid)
Definition: lock.h:202

◆ LockDatabaseObject()

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

Definition at line 977 of file lmgr.c.

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

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

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

◆ 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:167
#define SET_LOCKTAG_RELATION(locktag, dboid, reloid)
Definition: lock.h:184
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:167
LockInfoData rd_lockInfo
Definition: rel.h:112
#define SET_LOCKTAG_PAGE(locktag, dboid, reloid, blocknum)
Definition: lock.h:211
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:745
Oid dbId
Definition: rel.h:40
Definition: lock.h:167
#define SET_LOCKTAG_RELATION(locktag, dboid, reloid)
Definition: lock.h:184
LockInfoData rd_lockInfo
Definition: rel.h:112
void MarkLockClear(LOCALLOCK *locallock)
Definition: lock.c:1799
LockAcquireResult
Definition: lock.h:492
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:167
LockInfoData rd_lockInfo
Definition: rel.h:112
#define SET_LOCKTAG_RELATION_EXTEND(locktag, dboid, reloid)
Definition: lock.h:193
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:167
#define SET_LOCKTAG_RELATION(locktag, dboid, reloid)
Definition: lock.h:184
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:745
static void SetLocktagRelationOid(LOCKTAG *tag, Oid relid)
Definition: lmgr.c:90
Definition: lock.h:167
void MarkLockClear(LOCALLOCK *locallock)
Definition: lock.c:1799
LockAcquireResult
Definition: lock.h:492
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 1018 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().

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

◆ LockSharedObjectForSession()

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

Definition at line 1060 of file lmgr.c.

References InvalidOid, LockAcquire(), and SET_LOCKTAG_OBJECT.

Referenced by dbase_redo(), and movedb().

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

◆ 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:220
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:167
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:167
LockInfoData rd_lockInfo
Definition: rel.h:112
int LockWaiterCount(const LOCKTAG *locktag)
Definition: lock.c:4710
#define SET_LOCKTAG_RELATION_EXTEND(locktag, dboid, reloid)
Definition: lock.h:193
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:167
#define SET_LOCKTAG_SPECULATIVE_INSERTION(locktag, xid, token)
Definition: lock.h:250
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:167
#define SET_LOCKTAG_SPECULATIVE_INSERTION(locktag, xid, token)
Definition: lock.h:250
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:167
#define SET_LOCKTAG_SPECULATIVE_INSERTION(locktag, xid, token)
Definition: lock.h:250
#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 998 of file lmgr.c.

References LockRelease(), MyDatabaseId, and SET_LOCKTAG_OBJECT.

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

1000 {
1001  LOCKTAG tag;
1002 
1003  SET_LOCKTAG_OBJECT(tag,
1004  MyDatabaseId,
1005  classid,
1006  objid,
1007  objsubid);
1008 
1009  LockRelease(&tag, lockmode, false);
1010 }
Definition: lock.h:167
Oid MyDatabaseId
Definition: globals.c:88
#define SET_LOCKTAG_OBJECT(locktag, dboid, classoid, objoid, objsubid)
Definition: lock.h:265
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:167
LockInfoData rd_lockInfo
Definition: rel.h:112
#define SET_LOCKTAG_PAGE(locktag, dboid, reloid, blocknum)
Definition: lock.h:211
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:167
#define SET_LOCKTAG_RELATION(locktag, dboid, reloid)
Definition: lock.h:184
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:167
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:193
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:167
#define SET_LOCKTAG_RELATION(locktag, dboid, reloid)
Definition: lock.h:184
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:167
#define SET_LOCKTAG_RELATION(locktag, dboid, reloid)
Definition: lock.h:184
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 1039 of file lmgr.c.

References InvalidOid, LockRelease(), and SET_LOCKTAG_OBJECT.

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

1041 {
1042  LOCKTAG tag;
1043 
1044  SET_LOCKTAG_OBJECT(tag,
1045  InvalidOid,
1046  classid,
1047  objid,
1048  objsubid);
1049 
1050  LockRelease(&tag, lockmode, false);
1051 }
Definition: lock.h:167
#define InvalidOid
Definition: postgres_ext.h:36
#define SET_LOCKTAG_OBJECT(locktag, dboid, classoid, objoid, objsubid)
Definition: lock.h:265
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 1078 of file lmgr.c.

References InvalidOid, LockRelease(), and SET_LOCKTAG_OBJECT.

Referenced by dbase_redo(), and movedb().

1080 {
1081  LOCKTAG tag;
1082 
1083  SET_LOCKTAG_OBJECT(tag,
1084  InvalidOid,
1085  classid,
1086  objid,
1087  objsubid);
1088 
1089  LockRelease(&tag, lockmode, true);
1090 }
Definition: lock.h:167
#define InvalidOid
Definition: postgres_ext.h:36
#define SET_LOCKTAG_OBJECT(locktag, dboid, classoid, objoid, objsubid)
Definition: lock.h:265
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:220
LockRelId lockRelId
Definition: rel.h:45
Oid dbId
Definition: rel.h:40
Definition: lock.h:167
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 958 of file lmgr.c.

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

Referenced by DefineIndex(), and index_drop().

959 {
960  List *l;
961 
962  l = list_make1(&heaplocktag);
963  WaitForLockersMultiple(l, lockmode, progress);
964  list_free(l);
965 }
void WaitForLockersMultiple(List *locktags, LOCKMODE lockmode, bool progress)
Definition: lmgr.c:880
#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 880 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().

881 {
882  List *holders = NIL;
883  ListCell *lc;
884  int total = 0;
885  int done = 0;
886 
887  /* Done if no locks to wait for */
888  if (list_length(locktags) == 0)
889  return;
890 
891  /* Collect the transactions we need to wait on */
892  foreach(lc, locktags)
893  {
894  LOCKTAG *locktag = lfirst(lc);
895  int count;
896 
897  holders = lappend(holders,
898  GetLockConflicts(locktag, lockmode,
899  progress ? &count : NULL));
900  if (progress)
901  total += count;
902  }
903 
904  if (progress)
906 
907  /*
908  * Note: GetLockConflicts() never reports our own xid, hence we need not
909  * check for that. Also, prepared xacts are reported and awaited.
910  */
911 
912  /* Finally wait for each such transaction to complete */
913  foreach(lc, holders)
914  {
915  VirtualTransactionId *lockholders = lfirst(lc);
916 
917  while (VirtualTransactionIdIsValid(*lockholders))
918  {
919  /* If requested, publish who we're going to wait for. */
920  if (progress)
921  {
922  PGPROC *holder = BackendIdGetProc(lockholders->backendId);
923 
924  if (holder)
926  holder->pid);
927  }
928  VirtualXactLock(*lockholders, true);
929  lockholders++;
930 
931  if (progress)
933  }
934  }
935  if (progress)
936  {
937  const int index[] = {
941  };
942  const int64 values[] = {
943  0, 0, 0
944  };
945 
946  pgstat_progress_update_multi_param(3, index, values);
947  }
948 
949  list_free_deep(holders);
950 }
#define NIL
Definition: pg_list.h:65
Definition: lock.h:167
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:4599
#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:72
int progress
Definition: pgbench.c:272
VirtualTransactionId * GetLockConflicts(const LOCKTAG *locktag, LOCKMODE lockmode, int *countp)
Definition: lock.c:2914
#define lfirst(lc)
Definition: pg_list.h:169
void pgstat_progress_update_param(int index, int64 val)
BackendId backendId
Definition: lock.h:66
#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:156
#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:167
#define SET_LOCKTAG_TRANSACTION(locktag, xid)
Definition: lock.h:229
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:167
#define SET_LOCKTAG_TRANSACTION(locktag, xid)
Definition: lock.h:229

◆ 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:167
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:426
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:229
#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