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)
 
void LockRelationId (LockRelId *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)
 
bool ConditionalLockSharedObject (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 LockApplyTransactionForSession (Oid suboid, TransactionId xid, uint16 objid, LOCKMODE lockmode)
 
void UnlockApplyTransactionForSession (Oid suboid, TransactionId xid, uint16 objid, 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.

25 {
26  XLTW_None,
29  XLTW_Lock,
35 } XLTW_Oper;
XLTW_Oper
Definition: lmgr.h:25
@ XLTW_FetchUpdated
Definition: lmgr.h:33
@ XLTW_None
Definition: lmgr.h:26
@ XLTW_Lock
Definition: lmgr.h:29
@ XLTW_Delete
Definition: lmgr.h:28
@ XLTW_InsertIndex
Definition: lmgr.h:31
@ XLTW_LockUpdated
Definition: lmgr.h:30
@ XLTW_RecheckExclusionConstr
Definition: lmgr.h:34
@ XLTW_Update
Definition: lmgr.h:27
@ XLTW_InsertIndexUnique
Definition: lmgr.h:32

Function Documentation

◆ CheckRelationLockedByMe()

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

Definition at line 330 of file lmgr.c.

331 {
332  LOCKTAG tag;
333 
335  relation->rd_lockInfo.lockRelId.dbId,
336  relation->rd_lockInfo.lockRelId.relId);
337 
338  if (LockHeldByMe(&tag, lockmode))
339  return true;
340 
341  if (orstronger)
342  {
343  LOCKMODE slockmode;
344 
345  for (slockmode = lockmode + 1;
346  slockmode <= MaxLockMode;
347  slockmode++)
348  {
349  if (LockHeldByMe(&tag, slockmode))
350  {
351 #ifdef NOT_USED
352  /* Sometimes this might be useful for debugging purposes */
353  elog(WARNING, "lock mode %s substituted for %s on relation %s",
354  GetLockmodeName(tag.locktag_lockmethodid, slockmode),
355  GetLockmodeName(tag.locktag_lockmethodid, lockmode),
356  RelationGetRelationName(relation));
357 #endif
358  return true;
359  }
360  }
361  }
362 
363  return false;
364 }
#define WARNING
Definition: elog.h:36
#define elog(elevel,...)
Definition: elog.h:224
bool LockHeldByMe(const LOCKTAG *locktag, LOCKMODE lockmode)
Definition: lock.c:585
const char * GetLockmodeName(LOCKMETHODID lockmethodid, LOCKMODE mode)
Definition: lock.c:4038
#define SET_LOCKTAG_RELATION(locktag, dboid, reloid)
Definition: lock.h:181
int LOCKMODE
Definition: lockdefs.h:26
#define MaxLockMode
Definition: lockdefs.h:45
#define RelationGetRelationName(relation)
Definition: rel.h:539
Definition: lock.h:165
uint8 locktag_lockmethodid
Definition: lock.h:171
LockRelId lockRelId
Definition: rel.h:46
Oid relId
Definition: rel.h:40
Oid dbId
Definition: rel.h:41
LockInfoData rd_lockInfo
Definition: rel.h:114

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().

◆ ConditionalLockPage()

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

Definition at line 532 of file lmgr.c.

533 {
534  LOCKTAG tag;
535 
536  SET_LOCKTAG_PAGE(tag,
537  relation->rd_lockInfo.lockRelId.dbId,
538  relation->rd_lockInfo.lockRelId.relId,
539  blkno);
540 
541  return (LockAcquire(&tag, lockmode, false, true) != LOCKACQUIRE_NOT_AVAIL);
542 }
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:734
#define SET_LOCKTAG_PAGE(locktag, dboid, reloid, blocknum)
Definition: lock.h:208
@ LOCKACQUIRE_NOT_AVAIL
Definition: lock.h:501

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

Referenced by ginInsertCleanup().

◆ ConditionalLockRelation()

bool ConditionalLockRelation ( Relation  relation,
LOCKMODE  lockmode 
)

Definition at line 275 of file lmgr.c.

276 {
277  LOCKTAG tag;
278  LOCALLOCK *locallock;
280 
282  relation->rd_lockInfo.lockRelId.dbId,
283  relation->rd_lockInfo.lockRelId.relId);
284 
285  res = LockAcquireExtended(&tag, lockmode, false, true, true, &locallock);
286 
287  if (res == LOCKACQUIRE_NOT_AVAIL)
288  return false;
289 
290  /*
291  * Now that we have the lock, check for invalidation messages; see notes
292  * in LockRelationOid.
293  */
295  {
297  MarkLockClear(locallock);
298  }
299 
300  return true;
301 }
void AcceptInvalidationMessages(void)
Definition: inval.c:806
LockAcquireResult LockAcquireExtended(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait, bool reportMemoryError, LOCALLOCK **locallockp)
Definition: lock.c:758
void MarkLockClear(LOCALLOCK *locallock)
Definition: lock.c:1780
LockAcquireResult
Definition: lock.h:500
@ LOCKACQUIRE_ALREADY_CLEAR
Definition: lock.h:504

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

Referenced by lazy_truncate_heap().

◆ ConditionalLockRelationForExtension()

bool ConditionalLockRelationForExtension ( Relation  relation,
LOCKMODE  lockmode 
)

Definition at line 448 of file lmgr.c.

449 {
450  LOCKTAG tag;
451 
453  relation->rd_lockInfo.lockRelId.dbId,
454  relation->rd_lockInfo.lockRelId.relId);
455 
456  return (LockAcquire(&tag, lockmode, false, true) != LOCKACQUIRE_NOT_AVAIL);
457 }
#define SET_LOCKTAG_RELATION_EXTEND(locktag, dboid, reloid)
Definition: lock.h:190

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

◆ ConditionalLockRelationOid()

bool ConditionalLockRelationOid ( Oid  relid,
LOCKMODE  lockmode 
)

Definition at line 151 of file lmgr.c.

152 {
153  LOCKTAG tag;
154  LOCALLOCK *locallock;
156 
157  SetLocktagRelationOid(&tag, relid);
158 
159  res = LockAcquireExtended(&tag, lockmode, false, true, true, &locallock);
160 
161  if (res == LOCKACQUIRE_NOT_AVAIL)
162  return false;
163 
164  /*
165  * Now that we have the lock, check for invalidation messages; see notes
166  * in LockRelationOid.
167  */
169  {
171  MarkLockClear(locallock);
172  }
173 
174  return true;
175 }
static void SetLocktagRelationOid(LOCKTAG *tag, Oid relid)
Definition: lmgr.c:89

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

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

◆ ConditionalLockSharedObject()

bool ConditionalLockSharedObject ( Oid  classid,
Oid  objid,
uint16  objsubid,
LOCKMODE  lockmode 
)

Definition at line 1069 of file lmgr.c.

1071 {
1072  LOCKTAG tag;
1073  LOCALLOCK *locallock;
1075 
1076  SET_LOCKTAG_OBJECT(tag,
1077  InvalidOid,
1078  classid,
1079  objid,
1080  objsubid);
1081 
1082  res = LockAcquireExtended(&tag, lockmode, false, true, true, &locallock);
1083 
1084  if (res == LOCKACQUIRE_NOT_AVAIL)
1085  return false;
1086 
1087  /*
1088  * Now that we have the lock, check for invalidation messages; see notes
1089  * in LockRelationOid.
1090  */
1092  {
1094  MarkLockClear(locallock);
1095  }
1096 
1097  return true;
1098 }
#define SET_LOCKTAG_OBJECT(locktag, dboid, classoid, objoid, objsubid)
Definition: lock.h:262
#define InvalidOid
Definition: postgres_ext.h:36

References AcceptInvalidationMessages(), InvalidOid, LOCKACQUIRE_ALREADY_CLEAR, LOCKACQUIRE_NOT_AVAIL, LockAcquireExtended(), MarkLockClear(), res, and SET_LOCKTAG_OBJECT.

Referenced by EventTriggerOnLogin().

◆ ConditionalLockTuple()

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

Definition at line 588 of file lmgr.c.

589 {
590  LOCKTAG tag;
591 
592  SET_LOCKTAG_TUPLE(tag,
593  relation->rd_lockInfo.lockRelId.dbId,
594  relation->rd_lockInfo.lockRelId.relId,
597 
598  return (LockAcquire(&tag, lockmode, false, true) != LOCKACQUIRE_NOT_AVAIL);
599 }
static OffsetNumber ItemPointerGetOffsetNumber(const ItemPointerData *pointer)
Definition: itemptr.h:124
static BlockNumber ItemPointerGetBlockNumber(const ItemPointerData *pointer)
Definition: itemptr.h:103
#define SET_LOCKTAG_TUPLE(locktag, dboid, reloid, blocknum, offnum)
Definition: lock.h:217

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

◆ ConditionalXactLockTableWait()

bool ConditionalXactLockTableWait ( TransactionId  xid)

Definition at line 740 of file lmgr.c.

741 {
742  LOCKTAG tag;
743  bool first = true;
744 
745  for (;;)
746  {
749 
750  SET_LOCKTAG_TRANSACTION(tag, xid);
751 
752  if (LockAcquire(&tag, ShareLock, false, true) == LOCKACQUIRE_NOT_AVAIL)
753  return false;
754 
755  LockRelease(&tag, ShareLock, false);
756 
757  if (!TransactionIdIsInProgress(xid))
758  break;
759 
760  /* See XactLockTableWait about this case */
761  if (!first)
762  pg_usleep(1000L);
763  first = false;
765  }
766 
767  return true;
768 }
Assert(fmt[strlen(fmt) - 1] !='\n')
bool LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
Definition: lock.c:1942
#define SET_LOCKTAG_TRANSACTION(locktag, xid)
Definition: lock.h:226
#define ShareLock
Definition: lockdefs.h:40
bool TransactionIdIsInProgress(TransactionId xid)
Definition: procarray.c:1390
void pg_usleep(long microsec)
Definition: signal.c:53
TransactionId SubTransGetTopmostTransaction(TransactionId xid)
Definition: subtrans.c:163
#define TransactionIdEquals(id1, id2)
Definition: transam.h:43
#define TransactionIdIsValid(xid)
Definition: transam.h:41
TransactionId GetTopTransactionIdIfAny(void)
Definition: xact.c:433

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().

◆ DescribeLockTag()

void DescribeLockTag ( StringInfo  buf,
const LOCKTAG tag 
)

Definition at line 1205 of file lmgr.c.

1206 {
1207  switch ((LockTagType) tag->locktag_type)
1208  {
1209  case LOCKTAG_RELATION:
1211  _("relation %u of database %u"),
1212  tag->locktag_field2,
1213  tag->locktag_field1);
1214  break;
1217  _("extension of relation %u of database %u"),
1218  tag->locktag_field2,
1219  tag->locktag_field1);
1220  break;
1223  _("pg_database.datfrozenxid of database %u"),
1224  tag->locktag_field1);
1225  break;
1226  case LOCKTAG_PAGE:
1228  _("page %u of relation %u of database %u"),
1229  tag->locktag_field3,
1230  tag->locktag_field2,
1231  tag->locktag_field1);
1232  break;
1233  case LOCKTAG_TUPLE:
1235  _("tuple (%u,%u) of relation %u of database %u"),
1236  tag->locktag_field3,
1237  tag->locktag_field4,
1238  tag->locktag_field2,
1239  tag->locktag_field1);
1240  break;
1241  case LOCKTAG_TRANSACTION:
1243  _("transaction %u"),
1244  tag->locktag_field1);
1245  break;
1248  _("virtual transaction %d/%u"),
1249  tag->locktag_field1,
1250  tag->locktag_field2);
1251  break;
1254  _("speculative token %u of transaction %u"),
1255  tag->locktag_field2,
1256  tag->locktag_field1);
1257  break;
1258  case LOCKTAG_OBJECT:
1260  _("object %u of class %u of database %u"),
1261  tag->locktag_field3,
1262  tag->locktag_field2,
1263  tag->locktag_field1);
1264  break;
1265  case LOCKTAG_USERLOCK:
1266  /* reserved for old contrib code, now on pgfoundry */
1268  _("user lock [%u,%u,%u]"),
1269  tag->locktag_field1,
1270  tag->locktag_field2,
1271  tag->locktag_field3);
1272  break;
1273  case LOCKTAG_ADVISORY:
1275  _("advisory lock [%u,%u,%u,%u]"),
1276  tag->locktag_field1,
1277  tag->locktag_field2,
1278  tag->locktag_field3,
1279  tag->locktag_field4);
1280  break;
1283  _("remote transaction %u of subscription %u of database %u"),
1284  tag->locktag_field3,
1285  tag->locktag_field2,
1286  tag->locktag_field1);
1287  break;
1288  default:
1290  _("unrecognized locktag type %d"),
1291  (int) tag->locktag_type);
1292  break;
1293  }
1294 }
#define _(x)
Definition: elog.c:90
LockTagType
Definition: lock.h:136
@ LOCKTAG_OBJECT
Definition: lock.h:145
@ LOCKTAG_RELATION_EXTEND
Definition: lock.h:138
@ LOCKTAG_RELATION
Definition: lock.h:137
@ LOCKTAG_TUPLE
Definition: lock.h:141
@ LOCKTAG_SPECULATIVE_TOKEN
Definition: lock.h:144
@ LOCKTAG_APPLY_TRANSACTION
Definition: lock.h:148
@ LOCKTAG_USERLOCK
Definition: lock.h:146
@ LOCKTAG_DATABASE_FROZEN_IDS
Definition: lock.h:139
@ LOCKTAG_VIRTUALTRANSACTION
Definition: lock.h:143
@ LOCKTAG_TRANSACTION
Definition: lock.h:142
@ LOCKTAG_PAGE
Definition: lock.h:140
@ LOCKTAG_ADVISORY
Definition: lock.h:147
static char * buf
Definition: pg_test_fsync.c:73
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:97
uint8 locktag_type
Definition: lock.h:170
uint32 locktag_field3
Definition: lock.h:168
uint32 locktag_field1
Definition: lock.h:166
uint16 locktag_field4
Definition: lock.h:169
uint32 locktag_field2
Definition: lock.h:167

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

◆ GetLockNameFromTagType()

const char* GetLockNameFromTagType ( uint16  locktag_type)

Definition at line 1302 of file lmgr.c.

1303 {
1304  if (locktag_type > LOCKTAG_LAST_TYPE)
1305  return "???";
1306  return LockTagTypeNames[locktag_type];
1307 }
#define LOCKTAG_LAST_TYPE
Definition: lock.h:152
const char *const LockTagTypeNames[]
Definition: lockfuncs.c:29

References LOCKTAG_LAST_TYPE, and LockTagTypeNames.

Referenced by pgstat_get_wait_event().

◆ LockApplyTransactionForSession()

void LockApplyTransactionForSession ( Oid  suboid,
TransactionId  xid,
uint16  objid,
LOCKMODE  lockmode 
)

Definition at line 1165 of file lmgr.c.

1167 {
1168  LOCKTAG tag;
1169 
1171  MyDatabaseId,
1172  suboid,
1173  xid,
1174  objid);
1175 
1176  (void) LockAcquire(&tag, lockmode, true, false);
1177 }
Oid MyDatabaseId
Definition: globals.c:91
#define SET_LOCKTAG_APPLY_TRANSACTION(locktag, dboid, suboid, xid, objid)
Definition: lock.h:282

References LockAcquire(), MyDatabaseId, and SET_LOCKTAG_APPLY_TRANSACTION.

Referenced by pa_lock_stream(), and pa_lock_transaction().

◆ LockDatabaseFrozenIds()

void LockDatabaseFrozenIds ( LOCKMODE  lockmode)

Definition at line 497 of file lmgr.c.

498 {
499  LOCKTAG tag;
500 
502 
503  (void) LockAcquire(&tag, lockmode, false, false);
504 }
#define SET_LOCKTAG_DATABASE_FROZEN_IDS(locktag, dboid)
Definition: lock.h:199

References LockAcquire(), MyDatabaseId, and SET_LOCKTAG_DATABASE_FROZEN_IDS.

Referenced by vac_update_datfrozenxid().

◆ LockDatabaseObject()

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

Definition at line 1004 of file lmgr.c.

1006 {
1007  LOCKTAG tag;
1008 
1009  SET_LOCKTAG_OBJECT(tag,
1010  MyDatabaseId,
1011  classid,
1012  objid,
1013  objsubid);
1014 
1015  (void) LockAcquire(&tag, lockmode, false, false);
1016 
1017  /* Make sure syscaches are up-to-date with any changes we waited for */
1019 }

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

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

◆ LockHasWaitersRelation()

bool LockHasWaitersRelation ( Relation  relation,
LOCKMODE  lockmode 
)

Definition at line 373 of file lmgr.c.

374 {
375  LOCKTAG tag;
376 
378  relation->rd_lockInfo.lockRelId.dbId,
379  relation->rd_lockInfo.lockRelId.relId);
380 
381  return LockHasWaiters(&tag, lockmode, false);
382 }
bool LockHasWaiters(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
Definition: lock.c:621

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

Referenced by count_nondeletable_pages().

◆ LockPage()

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

Definition at line 513 of file lmgr.c.

514 {
515  LOCKTAG tag;
516 
517  SET_LOCKTAG_PAGE(tag,
518  relation->rd_lockInfo.lockRelId.dbId,
519  relation->rd_lockInfo.lockRelId.relId,
520  blkno);
521 
522  (void) LockAcquire(&tag, lockmode, false, false);
523 }

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

Referenced by ginInsertCleanup().

◆ LockRelation()

void LockRelation ( Relation  relation,
LOCKMODE  lockmode 
)

Definition at line 244 of file lmgr.c.

245 {
246  LOCKTAG tag;
247  LOCALLOCK *locallock;
249 
251  relation->rd_lockInfo.lockRelId.dbId,
252  relation->rd_lockInfo.lockRelId.relId);
253 
254  res = LockAcquireExtended(&tag, lockmode, false, false, true, &locallock);
255 
256  /*
257  * Now that we have the lock, check for invalidation messages; see notes
258  * in LockRelationOid.
259  */
261  {
263  MarkLockClear(locallock);
264  }
265 }

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

Referenced by index_create().

◆ LockRelationForExtension()

void LockRelationForExtension ( Relation  relation,
LOCKMODE  lockmode 
)

◆ LockRelationId()

void LockRelationId ( LockRelId relid,
LOCKMODE  lockmode 
)

Definition at line 184 of file lmgr.c.

185 {
186  LOCKTAG tag;
187  LOCALLOCK *locallock;
189 
190  SET_LOCKTAG_RELATION(tag, relid->dbId, relid->relId);
191 
192  res = LockAcquireExtended(&tag, lockmode, false, false, true, &locallock);
193 
194  /*
195  * Now that we have the lock, check for invalidation messages; see notes
196  * in LockRelationOid.
197  */
199  {
201  MarkLockClear(locallock);
202  }
203 }

References AcceptInvalidationMessages(), LockRelId::dbId, LOCKACQUIRE_ALREADY_CLEAR, LockAcquireExtended(), MarkLockClear(), LockRelId::relId, res, and SET_LOCKTAG_RELATION.

Referenced by CreateDatabaseUsingWalLog(), and ScanSourceDatabasePgClass().

◆ LockRelationIdForSession()

void LockRelationIdForSession ( LockRelId relid,
LOCKMODE  lockmode 
)

Definition at line 397 of file lmgr.c.

398 {
399  LOCKTAG tag;
400 
401  SET_LOCKTAG_RELATION(tag, relid->dbId, relid->relId);
402 
403  (void) LockAcquire(&tag, lockmode, true, false);
404 }

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

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

◆ LockRelationOid()

void LockRelationOid ( Oid  relid,
LOCKMODE  lockmode 
)

Definition at line 108 of file lmgr.c.

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

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

Referenced by AcquireDeletionLock(), AcquireExecutorLocks(), AlterTableMoveAll(), ATExecAttachPartition(), ATExecDetachPartition(), ATPostAlterTypeCleanup(), binary_upgrade_replorigin_advance(), 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().

◆ LockSharedObject()

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

◆ LockSharedObjectForSession()

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

Definition at line 1125 of file lmgr.c.

1127 {
1128  LOCKTAG tag;
1129 
1130  SET_LOCKTAG_OBJECT(tag,
1131  InvalidOid,
1132  classid,
1133  objid,
1134  objsubid);
1135 
1136  (void) LockAcquire(&tag, lockmode, true, false);
1137 }

References InvalidOid, LockAcquire(), and SET_LOCKTAG_OBJECT.

Referenced by dbase_redo(), and movedb().

◆ LockTuple()

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

Definition at line 568 of file lmgr.c.

569 {
570  LOCKTAG tag;
571 
572  SET_LOCKTAG_TUPLE(tag,
573  relation->rd_lockInfo.lockRelId.dbId,
574  relation->rd_lockInfo.lockRelId.relId,
577 
578  (void) LockAcquire(&tag, lockmode, false, false);
579 }

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

◆ RelationExtensionLockWaiterCount()

int RelationExtensionLockWaiterCount ( Relation  relation)

Definition at line 465 of file lmgr.c.

466 {
467  LOCKTAG tag;
468 
470  relation->rd_lockInfo.lockRelId.dbId,
471  relation->rd_lockInfo.lockRelId.relId);
472 
473  return LockWaiterCount(&tag);
474 }
int LockWaiterCount(const LOCKTAG *locktag)
Definition: lock.c:4639

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

Referenced by RelationAddBlocks().

◆ RelationInitLockInfo()

void RelationInitLockInfo ( Relation  relation)

Definition at line 71 of file lmgr.c.

72 {
73  Assert(RelationIsValid(relation));
75 
76  relation->rd_lockInfo.lockRelId.relId = RelationGetRelid(relation);
77 
78  if (relation->rd_rel->relisshared)
80  else
82 }
#define OidIsValid(objectId)
Definition: c.h:762
#define RelationGetRelid(relation)
Definition: rel.h:505
#define RelationIsValid(relation)
Definition: rel.h:478
Form_pg_class rd_rel
Definition: rel.h:111

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().

◆ SpeculativeInsertionLockAcquire()

uint32 SpeculativeInsertionLockAcquire ( TransactionId  xid)

Definition at line 782 of file lmgr.c.

783 {
784  LOCKTAG tag;
785 
787 
788  /*
789  * Check for wrap-around. Zero means no token is held, so don't use that.
790  */
791  if (speculativeInsertionToken == 0)
793 
795 
796  (void) LockAcquire(&tag, ExclusiveLock, false, false);
797 
799 }
static uint32 speculativeInsertionToken
Definition: lmgr.c:46
#define SET_LOCKTAG_SPECULATIVE_INSERTION(locktag, xid, token)
Definition: lock.h:247
#define ExclusiveLock
Definition: lockdefs.h:42

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

Referenced by ExecInsert().

◆ SpeculativeInsertionLockRelease()

void SpeculativeInsertionLockRelease ( TransactionId  xid)

Definition at line 808 of file lmgr.c.

809 {
810  LOCKTAG tag;
811 
813 
814  LockRelease(&tag, ExclusiveLock, false);
815 }

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

Referenced by ExecInsert().

◆ SpeculativeInsertionWait()

void SpeculativeInsertionWait ( TransactionId  xid,
uint32  token 
)

Definition at line 824 of file lmgr.c.

825 {
826  LOCKTAG tag;
827 
829 
831  Assert(token != 0);
832 
833  (void) LockAcquire(&tag, ShareLock, false, false);
834  LockRelease(&tag, ShareLock, false);
835 }
#define token
Definition: indent_globs.h:126

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

Referenced by _bt_doinsert(), and check_exclusion_or_unique_constraint().

◆ UnlockApplyTransactionForSession()

void UnlockApplyTransactionForSession ( Oid  suboid,
TransactionId  xid,
uint16  objid,
LOCKMODE  lockmode 
)

Definition at line 1183 of file lmgr.c.

1185 {
1186  LOCKTAG tag;
1187 
1189  MyDatabaseId,
1190  suboid,
1191  xid,
1192  objid);
1193 
1194  LockRelease(&tag, lockmode, true);
1195 }

References LockRelease(), MyDatabaseId, and SET_LOCKTAG_APPLY_TRANSACTION.

Referenced by pa_unlock_stream(), and pa_unlock_transaction().

◆ UnlockDatabaseObject()

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

Definition at line 1025 of file lmgr.c.

1027 {
1028  LOCKTAG tag;
1029 
1030  SET_LOCKTAG_OBJECT(tag,
1031  MyDatabaseId,
1032  classid,
1033  objid,
1034  objsubid);
1035 
1036  LockRelease(&tag, lockmode, false);
1037 }

References LockRelease(), MyDatabaseId, and SET_LOCKTAG_OBJECT.

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

◆ UnlockPage()

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

Definition at line 548 of file lmgr.c.

549 {
550  LOCKTAG tag;
551 
552  SET_LOCKTAG_PAGE(tag,
553  relation->rd_lockInfo.lockRelId.dbId,
554  relation->rd_lockInfo.lockRelId.relId,
555  blkno);
556 
557  LockRelease(&tag, lockmode, false);
558 }

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

Referenced by ginInsertCleanup().

◆ UnlockRelation()

void UnlockRelation ( Relation  relation,
LOCKMODE  lockmode 
)

Definition at line 310 of file lmgr.c.

311 {
312  LOCKTAG tag;
313 
315  relation->rd_lockInfo.lockRelId.dbId,
316  relation->rd_lockInfo.lockRelId.relId);
317 
318  LockRelease(&tag, lockmode, false);
319 }

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

Referenced by lazy_truncate_heap().

◆ UnlockRelationForExtension()

void UnlockRelationForExtension ( Relation  relation,
LOCKMODE  lockmode 
)

◆ UnlockRelationId()

void UnlockRelationId ( LockRelId relid,
LOCKMODE  lockmode 
)

Definition at line 212 of file lmgr.c.

213 {
214  LOCKTAG tag;
215 
216  SET_LOCKTAG_RELATION(tag, relid->dbId, relid->relId);
217 
218  LockRelease(&tag, lockmode, false);
219 }

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

Referenced by CreateDatabaseUsingWalLog(), index_close(), relation_close(), and ScanSourceDatabasePgClass().

◆ UnlockRelationIdForSession()

void UnlockRelationIdForSession ( LockRelId relid,
LOCKMODE  lockmode 
)

Definition at line 410 of file lmgr.c.

411 {
412  LOCKTAG tag;
413 
414  SET_LOCKTAG_RELATION(tag, relid->dbId, relid->relId);
415 
416  LockRelease(&tag, lockmode, true);
417 }

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

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

◆ UnlockRelationOid()

◆ UnlockSharedObject()

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

Definition at line 1104 of file lmgr.c.

1106 {
1107  LOCKTAG tag;
1108 
1109  SET_LOCKTAG_OBJECT(tag,
1110  InvalidOid,
1111  classid,
1112  objid,
1113  objsubid);
1114 
1115  LockRelease(&tag, lockmode, false);
1116 }

References InvalidOid, LockRelease(), and SET_LOCKTAG_OBJECT.

Referenced by AddSubscriptionRelState(), AlterDatabaseSet(), createdb_failure_callback(), drop_local_obsolete_slots(), get_db_info(), get_object_address(), replorigin_drop_by_name(), and synchronize_slots().

◆ UnlockSharedObjectForSession()

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

Definition at line 1143 of file lmgr.c.

1145 {
1146  LOCKTAG tag;
1147 
1148  SET_LOCKTAG_OBJECT(tag,
1149  InvalidOid,
1150  classid,
1151  objid,
1152  objsubid);
1153 
1154  LockRelease(&tag, lockmode, true);
1155 }

References InvalidOid, LockRelease(), and SET_LOCKTAG_OBJECT.

Referenced by dbase_redo(), and movedb().

◆ UnlockTuple()

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

Definition at line 605 of file lmgr.c.

606 {
607  LOCKTAG tag;
608 
609  SET_LOCKTAG_TUPLE(tag,
610  relation->rd_lockInfo.lockRelId.dbId,
611  relation->rd_lockInfo.lockRelId.relId,
614 
615  LockRelease(&tag, lockmode, false);
616 }

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

◆ WaitForLockers()

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

Definition at line 985 of file lmgr.c.

986 {
987  List *l;
988 
989  l = list_make1(&heaplocktag);
990  WaitForLockersMultiple(l, lockmode, progress);
991  list_free(l);
992 }
void list_free(List *list)
Definition: list.c:1546
void WaitForLockersMultiple(List *locktags, LOCKMODE lockmode, bool progress)
Definition: lmgr.c:907
#define list_make1(x1)
Definition: pg_list.h:212
int progress
Definition: pgbench.c:261
Definition: pg_list.h:54

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

Referenced by DefineIndex(), and index_drop().

◆ WaitForLockersMultiple()

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

Definition at line 907 of file lmgr.c.

908 {
909  List *holders = NIL;
910  ListCell *lc;
911  int total = 0;
912  int done = 0;
913 
914  /* Done if no locks to wait for */
915  if (locktags == NIL)
916  return;
917 
918  /* Collect the transactions we need to wait on */
919  foreach(lc, locktags)
920  {
921  LOCKTAG *locktag = lfirst(lc);
922  int count;
923 
924  holders = lappend(holders,
925  GetLockConflicts(locktag, lockmode,
926  progress ? &count : NULL));
927  if (progress)
928  total += count;
929  }
930 
931  if (progress)
933 
934  /*
935  * Note: GetLockConflicts() never reports our own xid, hence we need not
936  * check for that. Also, prepared xacts are reported and awaited.
937  */
938 
939  /* Finally wait for each such transaction to complete */
940  foreach(lc, holders)
941  {
942  VirtualTransactionId *lockholders = lfirst(lc);
943 
944  while (VirtualTransactionIdIsValid(*lockholders))
945  {
946  /* If requested, publish who we're going to wait for. */
947  if (progress)
948  {
949  PGPROC *holder = ProcNumberGetProc(lockholders->procNumber);
950 
951  if (holder)
953  holder->pid);
954  }
955  VirtualXactLock(*lockholders, true);
956  lockholders++;
957 
958  if (progress)
960  }
961  }
962  if (progress)
963  {
964  const int index[] = {
968  };
969  const int64 values[] = {
970  0, 0, 0
971  };
972 
974  }
975 
976  list_free_deep(holders);
977 }
void pgstat_progress_update_param(int index, int64 val)
void pgstat_progress_update_multi_param(int nparam, const int *index, const int64 *val)
static Datum values[MAXATTR]
Definition: bootstrap.c:152
List * lappend(List *list, void *datum)
Definition: list.c:339
void list_free_deep(List *list)
Definition: list.c:1560
VirtualTransactionId * GetLockConflicts(const LOCKTAG *locktag, LOCKMODE lockmode, int *countp)
Definition: lock.c:2872
bool VirtualXactLock(VirtualTransactionId vxid, bool wait)
Definition: lock.c:4528
#define VirtualTransactionIdIsValid(vxid)
Definition: lock.h:67
#define lfirst(lc)
Definition: pg_list.h:172
#define NIL
Definition: pg_list.h:68
PGPROC * ProcNumberGetProc(ProcNumber procNumber)
Definition: procarray.c:3125
#define PROGRESS_WAITFOR_DONE
Definition: progress.h:117
#define PROGRESS_WAITFOR_TOTAL
Definition: progress.h:116
#define PROGRESS_WAITFOR_CURRENT_PID
Definition: progress.h:118
Definition: proc.h:157
int pid
Definition: proc.h:178
ProcNumber procNumber
Definition: lock.h:61
Definition: type.h:95

References GetLockConflicts(), lappend(), lfirst, list_free_deep(), NIL, pgstat_progress_update_multi_param(), pgstat_progress_update_param(), PGPROC::pid, VirtualTransactionId::procNumber, ProcNumberGetProc(), progress, PROGRESS_WAITFOR_CURRENT_PID, PROGRESS_WAITFOR_DONE, PROGRESS_WAITFOR_TOTAL, values, VirtualTransactionIdIsValid, and VirtualXactLock().

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

◆ XactLockTableDelete()

void XactLockTableDelete ( TransactionId  xid)

Definition at line 643 of file lmgr.c.

644 {
645  LOCKTAG tag;
646 
647  SET_LOCKTAG_TRANSACTION(tag, xid);
648 
649  LockRelease(&tag, ExclusiveLock, false);
650 }

References ExclusiveLock, LockRelease(), and SET_LOCKTAG_TRANSACTION.

Referenced by CommitSubTransaction().

◆ XactLockTableInsert()

void XactLockTableInsert ( TransactionId  xid)

Definition at line 626 of file lmgr.c.

627 {
628  LOCKTAG tag;
629 
630  SET_LOCKTAG_TRANSACTION(tag, xid);
631 
632  (void) LockAcquire(&tag, ExclusiveLock, false, false);
633 }

References ExclusiveLock, LockAcquire(), and SET_LOCKTAG_TRANSACTION.

Referenced by AssignTransactionId().

◆ XactLockTableWait()

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

Definition at line 667 of file lmgr.c.

669 {
670  LOCKTAG tag;
673  bool first = true;
674 
675  /*
676  * If an operation is specified, set up our verbose error context
677  * callback.
678  */
679  if (oper != XLTW_None)
680  {
681  Assert(RelationIsValid(rel));
682  Assert(ItemPointerIsValid(ctid));
683 
684  info.rel = rel;
685  info.ctid = ctid;
686  info.oper = oper;
687 
689  callback.arg = &info;
690  callback.previous = error_context_stack;
692  }
693 
694  for (;;)
695  {
698 
699  SET_LOCKTAG_TRANSACTION(tag, xid);
700 
701  (void) LockAcquire(&tag, ShareLock, false, false);
702 
703  LockRelease(&tag, ShareLock, false);
704 
705  if (!TransactionIdIsInProgress(xid))
706  break;
707 
708  /*
709  * If the Xid belonged to a subtransaction, then the lock would have
710  * gone away as soon as it was finished; for correct tuple visibility,
711  * the right action is to wait on its parent transaction to go away.
712  * But instead of going levels up one by one, we can just wait for the
713  * topmost transaction to finish with the same end result, which also
714  * incurs less locktable traffic.
715  *
716  * Some uses of this function don't involve tuple visibility -- such
717  * as when building snapshots for logical decoding. It is possible to
718  * see a transaction in ProcArray before it registers itself in the
719  * locktable. The topmost transaction in that case is the same xid,
720  * so we try again after a short sleep. (Don't sleep the first time
721  * through, to avoid slowing down the normal case.)
722  */
723  if (!first)
724  pg_usleep(1000L);
725  first = false;
727  }
728 
729  if (oper != XLTW_None)
730  error_context_stack = callback.previous;
731 }
ErrorContextCallback * error_context_stack
Definition: elog.c:94
static bool ItemPointerIsValid(const ItemPointerData *pointer)
Definition: itemptr.h:83
static void XactLockTableWaitErrorCb(void *arg)
Definition: lmgr.c:842
Operator oper(ParseState *pstate, List *opname, Oid ltypeId, Oid rtypeId, bool noError, int location)
Definition: parse_oper.c:370
ItemPointer ctid
Definition: lmgr.c:59
XLTW_Oper oper
Definition: lmgr.c:57
Relation rel
Definition: lmgr.c:58
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:46

References Assert(), callback(), XactLockTableWaitInfo::ctid, error_context_stack, GetTopTransactionIdIfAny(), ItemPointerIsValid(), LockAcquire(), LockRelease(), oper(), XactLockTableWaitInfo::oper, pg_usleep(), 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().