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 331 of file lmgr.c.

332 {
333  LOCKTAG tag;
334 
336  relation->rd_lockInfo.lockRelId.dbId,
337  relation->rd_lockInfo.lockRelId.relId);
338 
339  if (LockHeldByMe(&tag, lockmode))
340  return true;
341 
342  if (orstronger)
343  {
344  LOCKMODE slockmode;
345 
346  for (slockmode = lockmode + 1;
347  slockmode <= MaxLockMode;
348  slockmode++)
349  {
350  if (LockHeldByMe(&tag, slockmode))
351  {
352 #ifdef NOT_USED
353  /* Sometimes this might be useful for debugging purposes */
354  elog(WARNING, "lock mode %s substituted for %s on relation %s",
355  GetLockmodeName(tag.locktag_lockmethodid, slockmode),
356  GetLockmodeName(tag.locktag_lockmethodid, lockmode),
357  RelationGetRelationName(relation));
358 #endif
359  return true;
360  }
361  }
362  }
363 
364  return false;
365 }
#define WARNING
Definition: elog.h:36
bool LockHeldByMe(const LOCKTAG *locktag, LOCKMODE lockmode)
Definition: lock.c:586
const char * GetLockmodeName(LOCKMETHODID lockmethodid, LOCKMODE mode)
Definition: lock.c:4021
#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:538
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 533 of file lmgr.c.

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

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 276 of file lmgr.c.

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

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 449 of file lmgr.c.

450 {
451  LOCKTAG tag;
452 
454  relation->rd_lockInfo.lockRelId.dbId,
455  relation->rd_lockInfo.lockRelId.relId);
456 
457  return (LockAcquire(&tag, lockmode, false, true) != LOCKACQUIRE_NOT_AVAIL);
458 }
#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 152 of file lmgr.c.

153 {
154  LOCKTAG tag;
155  LOCALLOCK *locallock;
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  */
170  {
172  MarkLockClear(locallock);
173  }
174 
175  return true;
176 }
static void SetLocktagRelationOid(LOCKTAG *tag, Oid relid)
Definition: lmgr.c:90

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 1070 of file lmgr.c.

1072 {
1073  LOCKTAG tag;
1074  LOCALLOCK *locallock;
1076 
1077  SET_LOCKTAG_OBJECT(tag,
1078  InvalidOid,
1079  classid,
1080  objid,
1081  objsubid);
1082 
1083  res = LockAcquireExtended(&tag, lockmode, false, true, true, &locallock);
1084 
1085  if (res == LOCKACQUIRE_NOT_AVAIL)
1086  return false;
1087 
1088  /*
1089  * Now that we have the lock, check for invalidation messages; see notes
1090  * in LockRelationOid.
1091  */
1093  {
1095  MarkLockClear(locallock);
1096  }
1097 
1098  return true;
1099 }
#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 589 of file lmgr.c.

590 {
591  LOCKTAG tag;
592 
593  SET_LOCKTAG_TUPLE(tag,
594  relation->rd_lockInfo.lockRelId.dbId,
595  relation->rd_lockInfo.lockRelId.relId,
598 
599  return (LockAcquire(&tag, lockmode, false, true) != LOCKACQUIRE_NOT_AVAIL);
600 }
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 741 of file lmgr.c.

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

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 1206 of file lmgr.c.

1207 {
1208  switch ((LockTagType) tag->locktag_type)
1209  {
1210  case LOCKTAG_RELATION:
1212  _("relation %u of database %u"),
1213  tag->locktag_field2,
1214  tag->locktag_field1);
1215  break;
1218  _("extension of relation %u of database %u"),
1219  tag->locktag_field2,
1220  tag->locktag_field1);
1221  break;
1224  _("pg_database.datfrozenxid of database %u"),
1225  tag->locktag_field1);
1226  break;
1227  case LOCKTAG_PAGE:
1229  _("page %u of relation %u of database %u"),
1230  tag->locktag_field3,
1231  tag->locktag_field2,
1232  tag->locktag_field1);
1233  break;
1234  case LOCKTAG_TUPLE:
1236  _("tuple (%u,%u) of relation %u of database %u"),
1237  tag->locktag_field3,
1238  tag->locktag_field4,
1239  tag->locktag_field2,
1240  tag->locktag_field1);
1241  break;
1242  case LOCKTAG_TRANSACTION:
1244  _("transaction %u"),
1245  tag->locktag_field1);
1246  break;
1249  _("virtual transaction %d/%u"),
1250  tag->locktag_field1,
1251  tag->locktag_field2);
1252  break;
1255  _("speculative token %u of transaction %u"),
1256  tag->locktag_field2,
1257  tag->locktag_field1);
1258  break;
1259  case LOCKTAG_OBJECT:
1261  _("object %u of class %u of database %u"),
1262  tag->locktag_field3,
1263  tag->locktag_field2,
1264  tag->locktag_field1);
1265  break;
1266  case LOCKTAG_USERLOCK:
1267  /* reserved for old contrib code, now on pgfoundry */
1269  _("user lock [%u,%u,%u]"),
1270  tag->locktag_field1,
1271  tag->locktag_field2,
1272  tag->locktag_field3);
1273  break;
1274  case LOCKTAG_ADVISORY:
1276  _("advisory lock [%u,%u,%u,%u]"),
1277  tag->locktag_field1,
1278  tag->locktag_field2,
1279  tag->locktag_field3,
1280  tag->locktag_field4);
1281  break;
1284  _("remote transaction %u of subscription %u of database %u"),
1285  tag->locktag_field3,
1286  tag->locktag_field2,
1287  tag->locktag_field1);
1288  break;
1289  default:
1291  _("unrecognized locktag type %d"),
1292  (int) tag->locktag_type);
1293  break;
1294  }
1295 }
#define _(x)
Definition: elog.c:91
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 1303 of file lmgr.c.

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

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 1166 of file lmgr.c.

1168 {
1169  LOCKTAG tag;
1170 
1172  MyDatabaseId,
1173  suboid,
1174  xid,
1175  objid);
1176 
1177  (void) LockAcquire(&tag, lockmode, true, false);
1178 }
Oid MyDatabaseId
Definition: globals.c:90
#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 498 of file lmgr.c.

499 {
500  LOCKTAG tag;
501 
503 
504  (void) LockAcquire(&tag, lockmode, false, false);
505 }
#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 1005 of file lmgr.c.

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

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 374 of file lmgr.c.

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

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 514 of file lmgr.c.

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

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 245 of file lmgr.c.

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

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 185 of file lmgr.c.

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

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 398 of file lmgr.c.

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

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 109 of file lmgr.c.

110 {
111  LOCKTAG tag;
112  LOCALLOCK *locallock;
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  */
136  {
138  MarkLockClear(locallock);
139  }
140 }

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 1126 of file lmgr.c.

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

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 569 of file lmgr.c.

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

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 466 of file lmgr.c.

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

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 72 of file lmgr.c.

73 {
74  Assert(RelationIsValid(relation));
76 
77  relation->rd_lockInfo.lockRelId.relId = RelationGetRelid(relation);
78 
79  if (relation->rd_rel->relisshared)
81  else
83 }
#define OidIsValid(objectId)
Definition: c.h:764
#define RelationGetRelid(relation)
Definition: rel.h:504
#define RelationIsValid(relation)
Definition: rel.h:477
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 783 of file lmgr.c.

784 {
785  LOCKTAG tag;
786 
788 
789  /*
790  * Check for wrap-around. Zero means no token is held, so don't use that.
791  */
792  if (speculativeInsertionToken == 0)
794 
796 
797  (void) LockAcquire(&tag, ExclusiveLock, false, false);
798 
800 }
static uint32 speculativeInsertionToken
Definition: lmgr.c:47
#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 809 of file lmgr.c.

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

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

Referenced by ExecInsert().

◆ SpeculativeInsertionWait()

void SpeculativeInsertionWait ( TransactionId  xid,
uint32  token 
)

Definition at line 825 of file lmgr.c.

826 {
827  LOCKTAG tag;
828 
830 
832  Assert(token != 0);
833 
834  (void) LockAcquire(&tag, ShareLock, false, false);
835  LockRelease(&tag, ShareLock, false);
836 }
#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 1184 of file lmgr.c.

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

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 1026 of file lmgr.c.

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

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 549 of file lmgr.c.

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

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 311 of file lmgr.c.

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

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 213 of file lmgr.c.

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

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 411 of file lmgr.c.

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

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 1105 of file lmgr.c.

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

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 1144 of file lmgr.c.

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

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 606 of file lmgr.c.

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

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 986 of file lmgr.c.

987 {
988  List *l;
989 
990  l = list_make1(&heaplocktag);
991  WaitForLockersMultiple(l, lockmode, progress);
992  list_free(l);
993 }
void list_free(List *list)
Definition: list.c:1546
void WaitForLockersMultiple(List *locktags, LOCKMODE lockmode, bool progress)
Definition: lmgr.c:908
#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 908 of file lmgr.c.

909 {
910  List *holders = NIL;
911  ListCell *lc;
912  int total = 0;
913  int done = 0;
914 
915  /* Done if no locks to wait for */
916  if (locktags == NIL)
917  return;
918 
919  /* Collect the transactions we need to wait on */
920  foreach(lc, locktags)
921  {
922  LOCKTAG *locktag = lfirst(lc);
923  int count;
924 
925  holders = lappend(holders,
926  GetLockConflicts(locktag, lockmode,
927  progress ? &count : NULL));
928  if (progress)
929  total += count;
930  }
931 
932  if (progress)
934 
935  /*
936  * Note: GetLockConflicts() never reports our own xid, hence we need not
937  * check for that. Also, prepared xacts are reported and awaited.
938  */
939 
940  /* Finally wait for each such transaction to complete */
941  foreach(lc, holders)
942  {
943  VirtualTransactionId *lockholders = lfirst(lc);
944 
945  while (VirtualTransactionIdIsValid(*lockholders))
946  {
947  /* If requested, publish who we're going to wait for. */
948  if (progress)
949  {
950  PGPROC *holder = BackendIdGetProc(lockholders->backendId);
951 
952  if (holder)
954  holder->pid);
955  }
956  VirtualXactLock(*lockholders, true);
957  lockholders++;
958 
959  if (progress)
961  }
962  }
963  if (progress)
964  {
965  const int index[] = {
969  };
970  const int64 values[] = {
971  0, 0, 0
972  };
973 
975  }
976 
977  list_free_deep(holders);
978 }
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:156
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:2855
bool VirtualXactLock(VirtualTransactionId vxid, bool wait)
Definition: lock.c:4511
#define VirtualTransactionIdIsValid(vxid)
Definition: lock.h:67
#define lfirst(lc)
Definition: pg_list.h:172
#define NIL
Definition: pg_list.h:68
#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
PGPROC * BackendIdGetProc(int backendID)
Definition: sinvaladt.c:385
Definition: proc.h:162
int pid
Definition: proc.h:186
BackendId backendId
Definition: lock.h:61
Definition: type.h:95

References VirtualTransactionId::backendId, BackendIdGetProc(), GetLockConflicts(), lappend(), lfirst, list_free_deep(), NIL, pgstat_progress_update_multi_param(), pgstat_progress_update_param(), PGPROC::pid, 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 644 of file lmgr.c.

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

References ExclusiveLock, LockRelease(), and SET_LOCKTAG_TRANSACTION.

Referenced by CommitSubTransaction().

◆ XactLockTableInsert()

void XactLockTableInsert ( TransactionId  xid)

Definition at line 627 of file lmgr.c.

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

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 668 of file lmgr.c.

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