PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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 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 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)
 
void WaitForLockersMultiple (List *locktags, LOCKMODE lockmode)
 
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

Enumeration Type Documentation

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

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

Definition at line 419 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().

420 {
421  LOCKTAG tag;
422 
423  SET_LOCKTAG_PAGE(tag,
424  relation->rd_lockInfo.lockRelId.dbId,
425  relation->rd_lockInfo.lockRelId.relId,
426  blkno);
427 
428  return (LockAcquire(&tag, lockmode, false, true) != LOCKACQUIRE_NOT_AVAIL);
429 }
LockRelId lockRelId
Definition: rel.h:44
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:683
Oid dbId
Definition: rel.h:39
Definition: lock.h:179
LockInfoData rd_lockInfo
Definition: rel.h:117
#define SET_LOCKTAG_PAGE(locktag, dboid, reloid, blocknum)
Definition: lock.h:210
Oid relId
Definition: rel.h:38
bool ConditionalLockRelation ( Relation  relation,
LOCKMODE  lockmode 
)

Definition at line 226 of file lmgr.c.

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

Referenced by lazy_truncate_heap().

227 {
228  LOCKTAG tag;
229  LockAcquireResult res;
230 
232  relation->rd_lockInfo.lockRelId.dbId,
233  relation->rd_lockInfo.lockRelId.relId);
234 
235  res = LockAcquire(&tag, lockmode, false, true);
236 
237  if (res == LOCKACQUIRE_NOT_AVAIL)
238  return false;
239 
240  /*
241  * Now that we have the lock, check for invalidation messages; see notes
242  * in LockRelationOid.
243  */
244  if (res != LOCKACQUIRE_ALREADY_HELD)
246 
247  return true;
248 }
LockRelId lockRelId
Definition: rel.h:44
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:683
void AcceptInvalidationMessages(void)
Definition: inval.c:679
Oid dbId
Definition: rel.h:39
Definition: lock.h:179
#define SET_LOCKTAG_RELATION(locktag, dboid, reloid)
Definition: lock.h:194
LockInfoData rd_lockInfo
Definition: rel.h:117
LockAcquireResult
Definition: lock.h:472
Oid relId
Definition: rel.h:38
bool ConditionalLockRelationForExtension ( Relation  relation,
LOCKMODE  lockmode 
)

Definition at line 350 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().

351 {
352  LOCKTAG tag;
353 
355  relation->rd_lockInfo.lockRelId.dbId,
356  relation->rd_lockInfo.lockRelId.relId);
357 
358  return (LockAcquire(&tag, lockmode, false, true) != LOCKACQUIRE_NOT_AVAIL);
359 }
LockRelId lockRelId
Definition: rel.h:44
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:683
Oid dbId
Definition: rel.h:39
Definition: lock.h:179
LockInfoData rd_lockInfo
Definition: rel.h:117
#define SET_LOCKTAG_RELATION_EXTEND(locktag, dboid, reloid)
Definition: lock.h:202
Oid relId
Definition: rel.h:38
bool ConditionalLockRelationOid ( Oid  relid,
LOCKMODE  lockmode 
)

Definition at line 138 of file lmgr.c.

References AcceptInvalidationMessages(), LockAcquire(), LOCKACQUIRE_ALREADY_HELD, LOCKACQUIRE_NOT_AVAIL, and SetLocktagRelationOid().

Referenced by AlterTableMoveAll(), analyze_rel(), do_autovacuum(), LockTableRecurse(), RangeVarGetRelidExtended(), and vacuum_rel().

139 {
140  LOCKTAG tag;
141  LockAcquireResult res;
142 
143  SetLocktagRelationOid(&tag, relid);
144 
145  res = LockAcquire(&tag, lockmode, false, true);
146 
147  if (res == LOCKACQUIRE_NOT_AVAIL)
148  return false;
149 
150  /*
151  * Now that we have the lock, check for invalidation messages; see notes
152  * in LockRelationOid.
153  */
154  if (res != LOCKACQUIRE_ALREADY_HELD)
156 
157  return true;
158 }
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:683
void AcceptInvalidationMessages(void)
Definition: inval.c:679
static void SetLocktagRelationOid(LOCKTAG *tag, Oid relid)
Definition: lmgr.c:86
Definition: lock.h:179
LockAcquireResult
Definition: lock.h:472
bool ConditionalLockTuple ( Relation  relation,
ItemPointer  tid,
LOCKMODE  lockmode 
)

Definition at line 475 of file lmgr.c.

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

476 {
477  LOCKTAG tag;
478 
479  SET_LOCKTAG_TUPLE(tag,
480  relation->rd_lockInfo.lockRelId.dbId,
481  relation->rd_lockInfo.lockRelId.relId,
484 
485  return (LockAcquire(&tag, lockmode, false, true) != LOCKACQUIRE_NOT_AVAIL);
486 }
#define SET_LOCKTAG_TUPLE(locktag, dboid, reloid, blocknum, offnum)
Definition: lock.h:218
LockRelId lockRelId
Definition: rel.h:44
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:683
Oid dbId
Definition: rel.h:39
Definition: lock.h:179
LockInfoData rd_lockInfo
Definition: rel.h:117
#define ItemPointerGetOffsetNumber(pointer)
Definition: itemptr.h:94
#define ItemPointerGetBlockNumber(pointer)
Definition: itemptr.h:75
Oid relId
Definition: rel.h:38
bool ConditionalXactLockTableWait ( TransactionId  xid)

Definition at line 607 of file lmgr.c.

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

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

608 {
609  LOCKTAG tag;
610 
611  for (;;)
612  {
615 
616  SET_LOCKTAG_TRANSACTION(tag, xid);
617 
618  if (LockAcquire(&tag, ShareLock, false, true) == LOCKACQUIRE_NOT_AVAIL)
619  return false;
620 
621  LockRelease(&tag, ShareLock, false);
622 
623  if (!TransactionIdIsInProgress(xid))
624  break;
625  xid = SubTransGetParent(xid);
626  }
627 
628  return true;
629 }
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:683
#define TransactionIdEquals(id1, id2)
Definition: transam.h:43
TransactionId SubTransGetParent(TransactionId xid)
Definition: subtrans.c:108
bool TransactionIdIsInProgress(TransactionId xid)
Definition: procarray.c:998
Definition: lock.h:179
TransactionId GetTopTransactionIdIfAny(void)
Definition: xact.c:404
#define Assert(condition)
Definition: c.h:675
#define SET_LOCKTAG_TRANSACTION(locktag, xid)
Definition: lock.h:226
#define ShareLock
Definition: lockdefs.h:41
bool LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
Definition: lock.c:1818
#define TransactionIdIsValid(xid)
Definition: transam.h:41
void DescribeLockTag ( StringInfo  buf,
const LOCKTAG tag 
)

Definition at line 954 of file lmgr.c.

References _, appendStringInfo(), LOCKTAG_ADVISORY, 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().

955 {
956  switch ((LockTagType) tag->locktag_type)
957  {
958  case LOCKTAG_RELATION:
959  appendStringInfo(buf,
960  _("relation %u of database %u"),
961  tag->locktag_field2,
962  tag->locktag_field1);
963  break;
965  appendStringInfo(buf,
966  _("extension of relation %u of database %u"),
967  tag->locktag_field2,
968  tag->locktag_field1);
969  break;
970  case LOCKTAG_PAGE:
971  appendStringInfo(buf,
972  _("page %u of relation %u of database %u"),
973  tag->locktag_field3,
974  tag->locktag_field2,
975  tag->locktag_field1);
976  break;
977  case LOCKTAG_TUPLE:
978  appendStringInfo(buf,
979  _("tuple (%u,%u) of relation %u of database %u"),
980  tag->locktag_field3,
981  tag->locktag_field4,
982  tag->locktag_field2,
983  tag->locktag_field1);
984  break;
985  case LOCKTAG_TRANSACTION:
986  appendStringInfo(buf,
987  _("transaction %u"),
988  tag->locktag_field1);
989  break;
991  appendStringInfo(buf,
992  _("virtual transaction %d/%u"),
993  tag->locktag_field1,
994  tag->locktag_field2);
995  break;
997  appendStringInfo(buf,
998  _("speculative token %u of transaction %u"),
999  tag->locktag_field2,
1000  tag->locktag_field1);
1001  break;
1002  case LOCKTAG_OBJECT:
1003  appendStringInfo(buf,
1004  _("object %u of class %u of database %u"),
1005  tag->locktag_field3,
1006  tag->locktag_field2,
1007  tag->locktag_field1);
1008  break;
1009  case LOCKTAG_USERLOCK:
1010  /* reserved for old contrib code, now on pgfoundry */
1011  appendStringInfo(buf,
1012  _("user lock [%u,%u,%u]"),
1013  tag->locktag_field1,
1014  tag->locktag_field2,
1015  tag->locktag_field3);
1016  break;
1017  case LOCKTAG_ADVISORY:
1018  appendStringInfo(buf,
1019  _("advisory lock [%u,%u,%u,%u]"),
1020  tag->locktag_field1,
1021  tag->locktag_field2,
1022  tag->locktag_field3,
1023  tag->locktag_field4);
1024  break;
1025  default:
1026  appendStringInfo(buf,
1027  _("unrecognized locktag type %d"),
1028  (int) tag->locktag_type);
1029  break;
1030  }
1031 }
uint16 locktag_field4
Definition: lock.h:184
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:78
uint32 locktag_field2
Definition: lock.h:182
uint8 locktag_type
Definition: lock.h:185
LockTagType
Definition: lock.h:139
uint32 locktag_field1
Definition: lock.h:181
#define _(x)
Definition: elog.c:84
uint32 locktag_field3
Definition: lock.h:183
const char* GetLockNameFromTagType ( uint16  locktag_type)

Definition at line 1039 of file lmgr.c.

References LOCKTAG_LAST_TYPE, and LockTagTypeNames.

Referenced by pgstat_get_wait_event().

1040 {
1041  if (locktag_type > LOCKTAG_LAST_TYPE)
1042  return "???";
1043  return LockTagTypeNames[locktag_type];
1044 }
#define LOCKTAG_LAST_TYPE
Definition: lock.h:167
const char *const LockTagTypeNames[]
Definition: lockfuncs.c:26
void LockDatabaseObject ( Oid  classid,
Oid  objid,
uint16  objsubid,
LOCKMODE  lockmode 
)

Definition at line 830 of file lmgr.c.

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

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

832 {
833  LOCKTAG tag;
834 
835  SET_LOCKTAG_OBJECT(tag,
836  MyDatabaseId,
837  classid,
838  objid,
839  objsubid);
840 
841  (void) LockAcquire(&tag, lockmode, false, false);
842 
843  /* Make sure syscaches are up-to-date with any changes we waited for */
845 }
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:683
void AcceptInvalidationMessages(void)
Definition: inval.c:679
Definition: lock.h:179
Oid MyDatabaseId
Definition: globals.c:76
#define SET_LOCKTAG_OBJECT(locktag, dboid, classoid, objoid, objsubid)
Definition: lock.h:250
bool LockHasWaitersRelation ( Relation  relation,
LOCKMODE  lockmode 
)

Definition at line 275 of file lmgr.c.

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

Referenced by count_nondeletable_pages().

276 {
277  LOCKTAG tag;
278 
280  relation->rd_lockInfo.lockRelId.dbId,
281  relation->rd_lockInfo.lockRelId.relId);
282 
283  return LockHasWaiters(&tag, lockmode, false);
284 }
LockRelId lockRelId
Definition: rel.h:44
Oid dbId
Definition: rel.h:39
Definition: lock.h:179
#define SET_LOCKTAG_RELATION(locktag, dboid, reloid)
Definition: lock.h:194
LockInfoData rd_lockInfo
Definition: rel.h:117
bool LockHasWaiters(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
Definition: lock.c:571
Oid relId
Definition: rel.h:38
void LockPage ( Relation  relation,
BlockNumber  blkno,
LOCKMODE  lockmode 
)

Definition at line 400 of file lmgr.c.

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

Referenced by ginInsertCleanup().

401 {
402  LOCKTAG tag;
403 
404  SET_LOCKTAG_PAGE(tag,
405  relation->rd_lockInfo.lockRelId.dbId,
406  relation->rd_lockInfo.lockRelId.relId,
407  blkno);
408 
409  (void) LockAcquire(&tag, lockmode, false, false);
410 }
LockRelId lockRelId
Definition: rel.h:44
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:683
Oid dbId
Definition: rel.h:39
Definition: lock.h:179
LockInfoData rd_lockInfo
Definition: rel.h:117
#define SET_LOCKTAG_PAGE(locktag, dboid, reloid, blocknum)
Definition: lock.h:210
Oid relId
Definition: rel.h:38
void LockRelation ( Relation  relation,
LOCKMODE  lockmode 
)

Definition at line 199 of file lmgr.c.

References AcceptInvalidationMessages(), LockRelId::dbId, LockAcquire(), LOCKACQUIRE_ALREADY_HELD, LockInfoData::lockRelId, RelationData::rd_lockInfo, LockRelId::relId, and SET_LOCKTAG_RELATION.

Referenced by index_create().

200 {
201  LOCKTAG tag;
202  LockAcquireResult res;
203 
205  relation->rd_lockInfo.lockRelId.dbId,
206  relation->rd_lockInfo.lockRelId.relId);
207 
208  res = LockAcquire(&tag, lockmode, false, false);
209 
210  /*
211  * Now that we have the lock, check for invalidation messages; see notes
212  * in LockRelationOid.
213  */
214  if (res != LOCKACQUIRE_ALREADY_HELD)
216 }
LockRelId lockRelId
Definition: rel.h:44
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:683
void AcceptInvalidationMessages(void)
Definition: inval.c:679
Oid dbId
Definition: rel.h:39
Definition: lock.h:179
#define SET_LOCKTAG_RELATION(locktag, dboid, reloid)
Definition: lock.h:194
LockInfoData rd_lockInfo
Definition: rel.h:117
LockAcquireResult
Definition: lock.h:472
Oid relId
Definition: rel.h:38
void LockRelationForExtension ( Relation  relation,
LOCKMODE  lockmode 
)

Definition at line 332 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(), gistvacuumcleanup(), lazy_scan_heap(), pgstat_index(), RelationGetBufferForTuple(), revmap_physical_extend(), SpGistNewBuffer(), spgvacuumscan(), and vm_extend().

333 {
334  LOCKTAG tag;
335 
337  relation->rd_lockInfo.lockRelId.dbId,
338  relation->rd_lockInfo.lockRelId.relId);
339 
340  (void) LockAcquire(&tag, lockmode, false, false);
341 }
LockRelId lockRelId
Definition: rel.h:44
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:683
Oid dbId
Definition: rel.h:39
Definition: lock.h:179
LockInfoData rd_lockInfo
Definition: rel.h:117
#define SET_LOCKTAG_RELATION_EXTEND(locktag, dboid, reloid)
Definition: lock.h:202
Oid relId
Definition: rel.h:38
void LockRelationIdForSession ( LockRelId relid,
LOCKMODE  lockmode 
)

Definition at line 299 of file lmgr.c.

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

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

300 {
301  LOCKTAG tag;
302 
303  SET_LOCKTAG_RELATION(tag, relid->dbId, relid->relId);
304 
305  (void) LockAcquire(&tag, lockmode, true, false);
306 }
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:683
Oid dbId
Definition: rel.h:39
Definition: lock.h:179
#define SET_LOCKTAG_RELATION(locktag, dboid, reloid)
Definition: lock.h:194
Oid relId
Definition: rel.h:38
void LockRelationOid ( Oid  relid,
LOCKMODE  lockmode 
)

Definition at line 105 of file lmgr.c.

References AcceptInvalidationMessages(), LockAcquire(), LOCKACQUIRE_ALREADY_HELD, and SetLocktagRelationOid().

Referenced by AcquireDeletionLock(), AcquireExecutorLocks(), AlterTableMoveAll(), copy_heap_data(), CreateTrigger(), ExecLockNonLeafAppendTables(), ExecRefreshMatView(), find_inheritance_children(), heap_drop_with_catalog(), InitCatCachePhase2(), InitPlan(), load_critical_index(), lock_and_open_sequence(), LockTableRecurse(), pg_replication_origin_advance(), RangeVarCallbackForDropRelation(), RangeVarCallbackForReindexIndex(), RangeVarGetAndCheckCreationNamespace(), RangeVarGetRelidExtended(), relation_open(), ScanQueryForLocks(), and try_relation_open().

106 {
107  LOCKTAG tag;
108  LockAcquireResult res;
109 
110  SetLocktagRelationOid(&tag, relid);
111 
112  res = LockAcquire(&tag, lockmode, false, false);
113 
114  /*
115  * Now that we have the lock, check for invalidation messages, so that we
116  * will update or flush any stale relcache entry before we try to use it.
117  * RangeVarGetRelid() specifically relies on us for this. We can skip
118  * this in the not-uncommon case that we already had the same type of lock
119  * being requested, since then no one else could have modified the
120  * relcache entry in an undesirable way. (In the case where our own xact
121  * modifies the rel, the relcache update happens via
122  * CommandCounterIncrement, not here.)
123  */
124  if (res != LOCKACQUIRE_ALREADY_HELD)
126 }
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:683
void AcceptInvalidationMessages(void)
Definition: inval.c:679
static void SetLocktagRelationOid(LOCKTAG *tag, Oid relid)
Definition: lmgr.c:86
Definition: lock.h:179
LockAcquireResult
Definition: lock.h:472
void LockSharedObject ( Oid  classid,
Oid  objid,
uint16  objsubid,
LOCKMODE  lockmode 
)

Definition at line 871 of file lmgr.c.

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

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

873 {
874  LOCKTAG tag;
875 
876  SET_LOCKTAG_OBJECT(tag,
877  InvalidOid,
878  classid,
879  objid,
880  objsubid);
881 
882  (void) LockAcquire(&tag, lockmode, false, false);
883 
884  /* Make sure syscaches are up-to-date with any changes we waited for */
886 }
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:683
void AcceptInvalidationMessages(void)
Definition: inval.c:679
Definition: lock.h:179
#define InvalidOid
Definition: postgres_ext.h:36
#define SET_LOCKTAG_OBJECT(locktag, dboid, classoid, objoid, objsubid)
Definition: lock.h:250
void LockSharedObjectForSession ( Oid  classid,
Oid  objid,
uint16  objsubid,
LOCKMODE  lockmode 
)

Definition at line 913 of file lmgr.c.

References InvalidOid, LockAcquire(), and SET_LOCKTAG_OBJECT.

Referenced by dbase_redo(), and movedb().

915 {
916  LOCKTAG tag;
917 
918  SET_LOCKTAG_OBJECT(tag,
919  InvalidOid,
920  classid,
921  objid,
922  objsubid);
923 
924  (void) LockAcquire(&tag, lockmode, true, false);
925 }
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:683
Definition: lock.h:179
#define InvalidOid
Definition: postgres_ext.h:36
#define SET_LOCKTAG_OBJECT(locktag, dboid, classoid, objoid, objsubid)
Definition: lock.h:250
void LockTuple ( Relation  relation,
ItemPointer  tid,
LOCKMODE  lockmode 
)

Definition at line 455 of file lmgr.c.

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

456 {
457  LOCKTAG tag;
458 
459  SET_LOCKTAG_TUPLE(tag,
460  relation->rd_lockInfo.lockRelId.dbId,
461  relation->rd_lockInfo.lockRelId.relId,
464 
465  (void) LockAcquire(&tag, lockmode, false, false);
466 }
#define SET_LOCKTAG_TUPLE(locktag, dboid, reloid, blocknum, offnum)
Definition: lock.h:218
LockRelId lockRelId
Definition: rel.h:44
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:683
Oid dbId
Definition: rel.h:39
Definition: lock.h:179
LockInfoData rd_lockInfo
Definition: rel.h:117
#define ItemPointerGetOffsetNumber(pointer)
Definition: itemptr.h:94
#define ItemPointerGetBlockNumber(pointer)
Definition: itemptr.h:75
Oid relId
Definition: rel.h:38
int RelationExtensionLockWaiterCount ( Relation  relation)

Definition at line 367 of file lmgr.c.

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

Referenced by RelationAddExtraBlocks().

368 {
369  LOCKTAG tag;
370 
372  relation->rd_lockInfo.lockRelId.dbId,
373  relation->rd_lockInfo.lockRelId.relId);
374 
375  return LockWaiterCount(&tag);
376 }
LockRelId lockRelId
Definition: rel.h:44
Oid dbId
Definition: rel.h:39
Definition: lock.h:179
LockInfoData rd_lockInfo
Definition: rel.h:117
int LockWaiterCount(const LOCKTAG *locktag)
Definition: lock.c:4387
#define SET_LOCKTAG_RELATION_EXTEND(locktag, dboid, reloid)
Definition: lock.h:202
Oid relId
Definition: rel.h:38
void RelationInitLockInfo ( Relation  relation)

Definition at line 68 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().

69 {
70  Assert(RelationIsValid(relation));
72 
73  relation->rd_lockInfo.lockRelId.relId = RelationGetRelid(relation);
74 
75  if (relation->rd_rel->relisshared)
77  else
79 }
LockRelId lockRelId
Definition: rel.h:44
Oid dbId
Definition: rel.h:39
Form_pg_class rd_rel
Definition: rel.h:114
#define OidIsValid(objectId)
Definition: c.h:538
#define RelationIsValid(relation)
Definition: rel.h:390
LockInfoData rd_lockInfo
Definition: rel.h:117
Oid MyDatabaseId
Definition: globals.c:76
#define InvalidOid
Definition: postgres_ext.h:36
#define Assert(condition)
Definition: c.h:675
#define RelationGetRelid(relation)
Definition: rel.h:417
Oid relId
Definition: rel.h:38
uint32 SpeculativeInsertionLockAcquire ( TransactionId  xid)

Definition at line 643 of file lmgr.c.

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

Referenced by ExecInsert().

644 {
645  LOCKTAG tag;
646 
648 
649  /*
650  * Check for wrap-around. Zero means no token is held, so don't use that.
651  */
652  if (speculativeInsertionToken == 0)
654 
656 
657  (void) LockAcquire(&tag, ExclusiveLock, false, false);
658 
660 }
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:683
#define ExclusiveLock
Definition: lockdefs.h:44
Definition: lock.h:179
#define SET_LOCKTAG_SPECULATIVE_INSERTION(locktag, xid, token)
Definition: lock.h:242
static uint32 speculativeInsertionToken
Definition: lmgr.c:43
void SpeculativeInsertionLockRelease ( TransactionId  xid)

Definition at line 669 of file lmgr.c.

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

Referenced by ExecInsert().

670 {
671  LOCKTAG tag;
672 
674 
675  LockRelease(&tag, ExclusiveLock, false);
676 }
#define ExclusiveLock
Definition: lockdefs.h:44
Definition: lock.h:179
#define SET_LOCKTAG_SPECULATIVE_INSERTION(locktag, xid, token)
Definition: lock.h:242
static uint32 speculativeInsertionToken
Definition: lmgr.c:43
bool LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
Definition: lock.c:1818
void SpeculativeInsertionWait ( TransactionId  xid,
uint32  token 
)

Definition at line 685 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().

686 {
687  LOCKTAG tag;
688 
689  SET_LOCKTAG_SPECULATIVE_INSERTION(tag, xid, token);
690 
692  Assert(token != 0);
693 
694  (void) LockAcquire(&tag, ShareLock, false, false);
695  LockRelease(&tag, ShareLock, false);
696 }
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:683
Definition: lock.h:179
#define SET_LOCKTAG_SPECULATIVE_INSERTION(locktag, xid, token)
Definition: lock.h:242
#define Assert(condition)
Definition: c.h:675
#define ShareLock
Definition: lockdefs.h:41
bool LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
Definition: lock.c:1818
#define TransactionIdIsValid(xid)
Definition: transam.h:41
void UnlockDatabaseObject ( Oid  classid,
Oid  objid,
uint16  objsubid,
LOCKMODE  lockmode 
)

Definition at line 851 of file lmgr.c.

References LockRelease(), MyDatabaseId, and SET_LOCKTAG_OBJECT.

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

853 {
854  LOCKTAG tag;
855 
856  SET_LOCKTAG_OBJECT(tag,
857  MyDatabaseId,
858  classid,
859  objid,
860  objsubid);
861 
862  LockRelease(&tag, lockmode, false);
863 }
Definition: lock.h:179
Oid MyDatabaseId
Definition: globals.c:76
#define SET_LOCKTAG_OBJECT(locktag, dboid, classoid, objoid, objsubid)
Definition: lock.h:250
bool LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
Definition: lock.c:1818
void UnlockPage ( Relation  relation,
BlockNumber  blkno,
LOCKMODE  lockmode 
)

Definition at line 435 of file lmgr.c.

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

Referenced by ginInsertCleanup().

436 {
437  LOCKTAG tag;
438 
439  SET_LOCKTAG_PAGE(tag,
440  relation->rd_lockInfo.lockRelId.dbId,
441  relation->rd_lockInfo.lockRelId.relId,
442  blkno);
443 
444  LockRelease(&tag, lockmode, false);
445 }
LockRelId lockRelId
Definition: rel.h:44
Oid dbId
Definition: rel.h:39
Definition: lock.h:179
LockInfoData rd_lockInfo
Definition: rel.h:117
#define SET_LOCKTAG_PAGE(locktag, dboid, reloid, blocknum)
Definition: lock.h:210
bool LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
Definition: lock.c:1818
Oid relId
Definition: rel.h:38
void UnlockRelation ( Relation  relation,
LOCKMODE  lockmode 
)

Definition at line 257 of file lmgr.c.

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

Referenced by lazy_truncate_heap().

258 {
259  LOCKTAG tag;
260 
262  relation->rd_lockInfo.lockRelId.dbId,
263  relation->rd_lockInfo.lockRelId.relId);
264 
265  LockRelease(&tag, lockmode, false);
266 }
LockRelId lockRelId
Definition: rel.h:44
Oid dbId
Definition: rel.h:39
Definition: lock.h:179
#define SET_LOCKTAG_RELATION(locktag, dboid, reloid)
Definition: lock.h:194
LockInfoData rd_lockInfo
Definition: rel.h:117
bool LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
Definition: lock.c:1818
Oid relId
Definition: rel.h:38
void UnlockRelationForExtension ( Relation  relation,
LOCKMODE  lockmode 
)

Definition at line 382 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(), gistvacuumcleanup(), lazy_scan_heap(), pgstat_index(), RelationGetBufferForTuple(), revmap_physical_extend(), SpGistNewBuffer(), spgvacuumscan(), and vm_extend().

383 {
384  LOCKTAG tag;
385 
387  relation->rd_lockInfo.lockRelId.dbId,
388  relation->rd_lockInfo.lockRelId.relId);
389 
390  LockRelease(&tag, lockmode, false);
391 }
LockRelId lockRelId
Definition: rel.h:44
Oid dbId
Definition: rel.h:39
Definition: lock.h:179
LockInfoData rd_lockInfo
Definition: rel.h:117
bool LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
Definition: lock.c:1818
#define SET_LOCKTAG_RELATION_EXTEND(locktag, dboid, reloid)
Definition: lock.h:202
Oid relId
Definition: rel.h:38
void UnlockRelationId ( LockRelId relid,
LOCKMODE  lockmode 
)

Definition at line 167 of file lmgr.c.

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

Referenced by index_close(), and relation_close().

168 {
169  LOCKTAG tag;
170 
171  SET_LOCKTAG_RELATION(tag, relid->dbId, relid->relId);
172 
173  LockRelease(&tag, lockmode, false);
174 }
Oid dbId
Definition: rel.h:39
Definition: lock.h:179
#define SET_LOCKTAG_RELATION(locktag, dboid, reloid)
Definition: lock.h:194
bool LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
Definition: lock.c:1818
Oid relId
Definition: rel.h:38
void UnlockRelationIdForSession ( LockRelId relid,
LOCKMODE  lockmode 
)

Definition at line 312 of file lmgr.c.

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

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

313 {
314  LOCKTAG tag;
315 
316  SET_LOCKTAG_RELATION(tag, relid->dbId, relid->relId);
317 
318  LockRelease(&tag, lockmode, true);
319 }
Oid dbId
Definition: rel.h:39
Definition: lock.h:179
#define SET_LOCKTAG_RELATION(locktag, dboid, reloid)
Definition: lock.h:194
bool LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
Definition: lock.c:1818
Oid relId
Definition: rel.h:38
void UnlockRelationOid ( Oid  relid,
LOCKMODE  lockmode 
)

Definition at line 182 of file lmgr.c.

References LockRelease(), and SetLocktagRelationOid().

Referenced by AcquireExecutorLocks(), do_autovacuum(), find_inheritance_children(), InitCatCachePhase2(), load_critical_index(), LockTableRecurse(), pg_replication_origin_advance(), RangeVarCallbackForDropRelation(), RangeVarCallbackForReindexIndex(), RangeVarGetAndCheckCreationNamespace(), RangeVarGetRelidExtended(), ReleaseDeletionLock(), ScanQueryForLocks(), and try_relation_open().

183 {
184  LOCKTAG tag;
185 
186  SetLocktagRelationOid(&tag, relid);
187 
188  LockRelease(&tag, lockmode, false);
189 }
static void SetLocktagRelationOid(LOCKTAG *tag, Oid relid)
Definition: lmgr.c:86
Definition: lock.h:179
bool LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
Definition: lock.c:1818
void UnlockSharedObject ( Oid  classid,
Oid  objid,
uint16  objsubid,
LOCKMODE  lockmode 
)

Definition at line 892 of file lmgr.c.

References InvalidOid, LockRelease(), and SET_LOCKTAG_OBJECT.

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

894 {
895  LOCKTAG tag;
896 
897  SET_LOCKTAG_OBJECT(tag,
898  InvalidOid,
899  classid,
900  objid,
901  objsubid);
902 
903  LockRelease(&tag, lockmode, false);
904 }
Definition: lock.h:179
#define InvalidOid
Definition: postgres_ext.h:36
#define SET_LOCKTAG_OBJECT(locktag, dboid, classoid, objoid, objsubid)
Definition: lock.h:250
bool LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
Definition: lock.c:1818
void UnlockSharedObjectForSession ( Oid  classid,
Oid  objid,
uint16  objsubid,
LOCKMODE  lockmode 
)

Definition at line 931 of file lmgr.c.

References InvalidOid, LockRelease(), and SET_LOCKTAG_OBJECT.

Referenced by dbase_redo(), and movedb().

933 {
934  LOCKTAG tag;
935 
936  SET_LOCKTAG_OBJECT(tag,
937  InvalidOid,
938  classid,
939  objid,
940  objsubid);
941 
942  LockRelease(&tag, lockmode, true);
943 }
Definition: lock.h:179
#define InvalidOid
Definition: postgres_ext.h:36
#define SET_LOCKTAG_OBJECT(locktag, dboid, classoid, objoid, objsubid)
Definition: lock.h:250
bool LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
Definition: lock.c:1818
void UnlockTuple ( Relation  relation,
ItemPointer  tid,
LOCKMODE  lockmode 
)

Definition at line 492 of file lmgr.c.

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

493 {
494  LOCKTAG tag;
495 
496  SET_LOCKTAG_TUPLE(tag,
497  relation->rd_lockInfo.lockRelId.dbId,
498  relation->rd_lockInfo.lockRelId.relId,
501 
502  LockRelease(&tag, lockmode, false);
503 }
#define SET_LOCKTAG_TUPLE(locktag, dboid, reloid, blocknum, offnum)
Definition: lock.h:218
LockRelId lockRelId
Definition: rel.h:44
Oid dbId
Definition: rel.h:39
Definition: lock.h:179
LockInfoData rd_lockInfo
Definition: rel.h:117
#define ItemPointerGetOffsetNumber(pointer)
Definition: itemptr.h:94
bool LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
Definition: lock.c:1818
#define ItemPointerGetBlockNumber(pointer)
Definition: itemptr.h:75
Oid relId
Definition: rel.h:38
void WaitForLockers ( LOCKTAG  heaplocktag,
LOCKMODE  lockmode 
)

Definition at line 811 of file lmgr.c.

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

Referenced by DefineIndex(), and index_drop().

812 {
813  List *l;
814 
815  l = list_make1(&heaplocktag);
816  WaitForLockersMultiple(l, lockmode);
817  list_free(l);
818 }
#define list_make1(x1)
Definition: pg_list.h:139
void list_free(List *list)
Definition: list.c:1133
Definition: pg_list.h:45
void WaitForLockersMultiple(List *locktags, LOCKMODE lockmode)
Definition: lmgr.c:767
void WaitForLockersMultiple ( List locktags,
LOCKMODE  lockmode 
)

Definition at line 767 of file lmgr.c.

References GetLockConflicts(), lappend(), lfirst, list_free_deep(), list_length(), NIL, VirtualTransactionIdIsValid, and VirtualXactLock().

Referenced by WaitForLockers().

768 {
769  List *holders = NIL;
770  ListCell *lc;
771 
772  /* Done if no locks to wait for */
773  if (list_length(locktags) == 0)
774  return;
775 
776  /* Collect the transactions we need to wait on */
777  foreach(lc, locktags)
778  {
779  LOCKTAG *locktag = lfirst(lc);
780 
781  holders = lappend(holders, GetLockConflicts(locktag, lockmode));
782  }
783 
784  /*
785  * Note: GetLockConflicts() never reports our own xid, hence we need not
786  * check for that. Also, prepared xacts are not reported, which is fine
787  * since they certainly aren't going to do anything anymore.
788  */
789 
790  /* Finally wait for each such transaction to complete */
791  foreach(lc, holders)
792  {
793  VirtualTransactionId *lockholders = lfirst(lc);
794 
795  while (VirtualTransactionIdIsValid(*lockholders))
796  {
797  VirtualXactLock(*lockholders, true);
798  lockholders++;
799  }
800  }
801 
802  list_free_deep(holders);
803 }
#define NIL
Definition: pg_list.h:69
Definition: lock.h:179
void list_free_deep(List *list)
Definition: list.c:1147
bool VirtualXactLock(VirtualTransactionId vxid, bool wait)
Definition: lock.c:4291
List * lappend(List *list, void *datum)
Definition: list.c:128
#define VirtualTransactionIdIsValid(vxid)
Definition: lock.h:72
#define lfirst(lc)
Definition: pg_list.h:106
static int list_length(const List *l)
Definition: pg_list.h:89
VirtualTransactionId * GetLockConflicts(const LOCKTAG *locktag, LOCKMODE lockmode)
Definition: lock.c:2745
Definition: pg_list.h:45
void XactLockTableDelete ( TransactionId  xid)

Definition at line 530 of file lmgr.c.

References ExclusiveLock, LockRelease(), and SET_LOCKTAG_TRANSACTION.

Referenced by CommitSubTransaction().

531 {
532  LOCKTAG tag;
533 
534  SET_LOCKTAG_TRANSACTION(tag, xid);
535 
536  LockRelease(&tag, ExclusiveLock, false);
537 }
#define ExclusiveLock
Definition: lockdefs.h:44
Definition: lock.h:179
#define SET_LOCKTAG_TRANSACTION(locktag, xid)
Definition: lock.h:226
bool LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
Definition: lock.c:1818
void XactLockTableInsert ( TransactionId  xid)

Definition at line 513 of file lmgr.c.

References ExclusiveLock, LockAcquire(), and SET_LOCKTAG_TRANSACTION.

Referenced by AssignTransactionId().

514 {
515  LOCKTAG tag;
516 
517  SET_LOCKTAG_TRANSACTION(tag, xid);
518 
519  (void) LockAcquire(&tag, ExclusiveLock, false, false);
520 }
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:683
#define ExclusiveLock
Definition: lockdefs.h:44
Definition: lock.h:179
#define SET_LOCKTAG_TRANSACTION(locktag, xid)
Definition: lock.h:226
void XactLockTableWait ( TransactionId  xid,
Relation  rel,
ItemPointer  ctid,
XLTW_Oper  oper 
)

Definition at line 554 of file lmgr.c.

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

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

556 {
557  LOCKTAG tag;
560 
561  /*
562  * If an operation is specified, set up our verbose error context
563  * callback.
564  */
565  if (oper != XLTW_None)
566  {
567  Assert(RelationIsValid(rel));
568  Assert(ItemPointerIsValid(ctid));
569 
570  info.rel = rel;
571  info.ctid = ctid;
572  info.oper = oper;
573 
575  callback.arg = &info;
576  callback.previous = error_context_stack;
578  }
579 
580  for (;;)
581  {
584 
585  SET_LOCKTAG_TRANSACTION(tag, xid);
586 
587  (void) LockAcquire(&tag, ShareLock, false, false);
588 
589  LockRelease(&tag, ShareLock, false);
590 
591  if (!TransactionIdIsInProgress(xid))
592  break;
593  xid = SubTransGetParent(xid);
594  }
595 
596  if (oper != XLTW_None)
597  error_context_stack = callback.previous;
598 }
#define ItemPointerIsValid(pointer)
Definition: itemptr.h:59
Relation rel
Definition: lmgr.c:55
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:683
#define TransactionIdEquals(id1, id2)
Definition: transam.h:43
TransactionId SubTransGetParent(TransactionId xid)
Definition: subtrans.c:108
bool TransactionIdIsInProgress(TransactionId xid)
Definition: procarray.c:998
Definition: lock.h:179
struct ErrorContextCallback * previous
Definition: elog.h:238
XLTW_Oper oper
Definition: lmgr.c:54
ErrorContextCallback * error_context_stack
Definition: elog.c:88
Definition: lmgr.h:26
#define RelationIsValid(relation)
Definition: rel.h:390
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:48
ItemPointer ctid
Definition: lmgr.c:56
TransactionId GetTopTransactionIdIfAny(void)
Definition: xact.c:404
static void XactLockTableWaitErrorCb(void *arg)
Definition: lmgr.c:703
#define Assert(condition)
Definition: c.h:675
#define SET_LOCKTAG_TRANSACTION(locktag, xid)
Definition: lock.h:226
void(* callback)(void *arg)
Definition: elog.h:239
#define ShareLock
Definition: lockdefs.h:41
bool LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
Definition: lock.c:1818
#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:377