PostgreSQL Source Code  git master
lmgr.c File Reference
#include "postgres.h"
#include "access/subtrans.h"
#include "access/transam.h"
#include "access/xact.h"
#include "catalog/catalog.h"
#include "commands/progress.h"
#include "miscadmin.h"
#include "pgstat.h"
#include "storage/lmgr.h"
#include "storage/proc.h"
#include "storage/procarray.h"
#include "storage/sinvaladt.h"
#include "utils/inval.h"
Include dependency graph for lmgr.c:

Go to the source code of this file.

Data Structures

struct  XactLockTableWaitInfo
 

Typedefs

typedef struct XactLockTableWaitInfo XactLockTableWaitInfo
 

Functions

static void XactLockTableWaitErrorCb (void *arg)
 
void RelationInitLockInfo (Relation relation)
 
static void SetLocktagRelationOid (LOCKTAG *tag, Oid relid)
 
void LockRelationOid (Oid relid, LOCKMODE lockmode)
 
bool ConditionalLockRelationOid (Oid relid, LOCKMODE lockmode)
 
void LockRelationId (LockRelId *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)
 
bool ConditionalLockRelationForExtension (Relation relation, LOCKMODE lockmode)
 
int RelationExtensionLockWaiterCount (Relation relation)
 
void UnlockRelationForExtension (Relation relation, LOCKMODE lockmode)
 
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)
 
uint32 SpeculativeInsertionLockAcquire (TransactionId xid)
 
void SpeculativeInsertionLockRelease (TransactionId xid)
 
void SpeculativeInsertionWait (TransactionId xid, uint32 token)
 
void WaitForLockersMultiple (List *locktags, LOCKMODE lockmode, bool progress)
 
void WaitForLockers (LOCKTAG heaplocktag, LOCKMODE lockmode, bool progress)
 
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 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)
 

Variables

static uint32 speculativeInsertionToken = 0
 

Typedef Documentation

◆ XactLockTableWaitInfo

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

◆ 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:1383
void pg_usleep(long microsec)
Definition: signal.c:53
TransactionId SubTransGetTopmostTransaction(TransactionId xid)
Definition: subtrans.c:150
#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 1168 of file lmgr.c.

1169 {
1170  switch ((LockTagType) tag->locktag_type)
1171  {
1172  case LOCKTAG_RELATION:
1174  _("relation %u of database %u"),
1175  tag->locktag_field2,
1176  tag->locktag_field1);
1177  break;
1180  _("extension of relation %u of database %u"),
1181  tag->locktag_field2,
1182  tag->locktag_field1);
1183  break;
1186  _("pg_database.datfrozenxid of database %u"),
1187  tag->locktag_field1);
1188  break;
1189  case LOCKTAG_PAGE:
1191  _("page %u of relation %u of database %u"),
1192  tag->locktag_field3,
1193  tag->locktag_field2,
1194  tag->locktag_field1);
1195  break;
1196  case LOCKTAG_TUPLE:
1198  _("tuple (%u,%u) of relation %u of database %u"),
1199  tag->locktag_field3,
1200  tag->locktag_field4,
1201  tag->locktag_field2,
1202  tag->locktag_field1);
1203  break;
1204  case LOCKTAG_TRANSACTION:
1206  _("transaction %u"),
1207  tag->locktag_field1);
1208  break;
1211  _("virtual transaction %d/%u"),
1212  tag->locktag_field1,
1213  tag->locktag_field2);
1214  break;
1217  _("speculative token %u of transaction %u"),
1218  tag->locktag_field2,
1219  tag->locktag_field1);
1220  break;
1221  case LOCKTAG_OBJECT:
1223  _("object %u of class %u of database %u"),
1224  tag->locktag_field3,
1225  tag->locktag_field2,
1226  tag->locktag_field1);
1227  break;
1228  case LOCKTAG_USERLOCK:
1229  /* reserved for old contrib code, now on pgfoundry */
1231  _("user lock [%u,%u,%u]"),
1232  tag->locktag_field1,
1233  tag->locktag_field2,
1234  tag->locktag_field3);
1235  break;
1236  case LOCKTAG_ADVISORY:
1238  _("advisory lock [%u,%u,%u,%u]"),
1239  tag->locktag_field1,
1240  tag->locktag_field2,
1241  tag->locktag_field3,
1242  tag->locktag_field4);
1243  break;
1246  _("remote transaction %u of subscription %u of database %u"),
1247  tag->locktag_field3,
1248  tag->locktag_field2,
1249  tag->locktag_field1);
1250  break;
1251  default:
1253  _("unrecognized locktag type %d"),
1254  (int) tag->locktag_type);
1255  break;
1256  }
1257 }
#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:67
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
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 1265 of file lmgr.c.

1266 {
1267  if (locktag_type > LOCKTAG_LAST_TYPE)
1268  return "???";
1269  return LockTagTypeNames[locktag_type];
1270 }
#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 1128 of file lmgr.c.

1130 {
1131  LOCKTAG tag;
1132 
1134  MyDatabaseId,
1135  suboid,
1136  xid,
1137  objid);
1138 
1139  (void) LockAcquire(&tag, lockmode, true, false);
1140 }
Oid MyDatabaseId
Definition: globals.c:89
#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 }
#define SET_LOCKTAG_OBJECT(locktag, dboid, classoid, objoid, objsubid)
Definition: lock.h:262

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

Definition at line 1046 of file lmgr.c.

1048 {
1049  LOCKTAG tag;
1050 
1051  SET_LOCKTAG_OBJECT(tag,
1052  InvalidOid,
1053  classid,
1054  objid,
1055  objsubid);
1056 
1057  (void) LockAcquire(&tag, lockmode, false, false);
1058 
1059  /* Make sure syscaches are up-to-date with any changes we waited for */
1061 }
#define InvalidOid
Definition: postgres_ext.h:36

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

Referenced by AcquireDeletionLock(), AddRoleMems(), AddSubscriptionRelState(), AlterSubscription(), clear_subscription_skip_lsn(), createdb(), DelRoleMems(), DisableSubscription(), DropRole(), DropSubscription(), get_db_info(), get_object_address(), InitPostgres(), PreCommit_Notify(), replorigin_drop_by_name(), shdepLockAndCheckObject(), and UpdateSubscriptionRelState().

◆ LockSharedObjectForSession()

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

Definition at line 1088 of file lmgr.c.

1090 {
1091  LOCKTAG tag;
1092 
1093  SET_LOCKTAG_OBJECT(tag,
1094  InvalidOid,
1095  classid,
1096  objid,
1097  objsubid);
1098 
1099  (void) LockAcquire(&tag, lockmode, true, false);
1100 }

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

◆ SetLocktagRelationOid()

static void SetLocktagRelationOid ( LOCKTAG tag,
Oid  relid 
)
inlinestatic

Definition at line 90 of file lmgr.c.

91 {
92  Oid dbid;
93 
94  if (IsSharedRelation(relid))
95  dbid = InvalidOid;
96  else
97  dbid = MyDatabaseId;
98 
99  SET_LOCKTAG_RELATION(*tag, dbid, relid);
100 }
bool IsSharedRelation(Oid relationId)
Definition: catalog.c:245
unsigned int Oid
Definition: postgres_ext.h:31

References InvalidOid, IsSharedRelation(), MyDatabaseId, and SET_LOCKTAG_RELATION.

Referenced by ConditionalLockRelationOid(), LockRelationOid(), and UnlockRelationOid().

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

1148 {
1149  LOCKTAG tag;
1150 
1152  MyDatabaseId,
1153  suboid,
1154  xid,
1155  objid);
1156 
1157  LockRelease(&tag, lockmode, true);
1158 }

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

1069 {
1070  LOCKTAG tag;
1071 
1072  SET_LOCKTAG_OBJECT(tag,
1073  InvalidOid,
1074  classid,
1075  objid,
1076  objsubid);
1077 
1078  LockRelease(&tag, lockmode, false);
1079 }

References InvalidOid, LockRelease(), and SET_LOCKTAG_OBJECT.

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

◆ UnlockSharedObjectForSession()

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

Definition at line 1106 of file lmgr.c.

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

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:1545
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:338
void list_free_deep(List *list)
Definition: list.c:1559
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
@ XLTW_None
Definition: lmgr.h:26
Operator oper(ParseState *pstate, List *opname, Oid ltypeId, Oid rtypeId, bool noError, int location)
Definition: parse_oper.c:382
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().

◆ XactLockTableWaitErrorCb()

static void XactLockTableWaitErrorCb ( void *  arg)
static

Definition at line 843 of file lmgr.c.

844 {
846 
847  /*
848  * We would like to print schema name too, but that would require a
849  * syscache lookup.
850  */
851  if (info->oper != XLTW_None &&
852  ItemPointerIsValid(info->ctid) && RelationIsValid(info->rel))
853  {
854  const char *cxt;
855 
856  switch (info->oper)
857  {
858  case XLTW_Update:
859  cxt = gettext_noop("while updating tuple (%u,%u) in relation \"%s\"");
860  break;
861  case XLTW_Delete:
862  cxt = gettext_noop("while deleting tuple (%u,%u) in relation \"%s\"");
863  break;
864  case XLTW_Lock:
865  cxt = gettext_noop("while locking tuple (%u,%u) in relation \"%s\"");
866  break;
867  case XLTW_LockUpdated:
868  cxt = gettext_noop("while locking updated version (%u,%u) of tuple in relation \"%s\"");
869  break;
870  case XLTW_InsertIndex:
871  cxt = gettext_noop("while inserting index tuple (%u,%u) in relation \"%s\"");
872  break;
874  cxt = gettext_noop("while checking uniqueness of tuple (%u,%u) in relation \"%s\"");
875  break;
876  case XLTW_FetchUpdated:
877  cxt = gettext_noop("while rechecking updated tuple (%u,%u) in relation \"%s\"");
878  break;
880  cxt = gettext_noop("while checking exclusion constraint on tuple (%u,%u) in relation \"%s\"");
881  break;
882 
883  default:
884  return;
885  }
886 
887  errcontext(cxt,
891  }
892 }
#define gettext_noop(x)
Definition: c.h:1209
#define errcontext
Definition: elog.h:196
@ XLTW_FetchUpdated
Definition: lmgr.h:33
@ 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
void * arg

References arg, XactLockTableWaitInfo::ctid, errcontext, gettext_noop, ItemPointerGetBlockNumber(), ItemPointerGetOffsetNumber(), ItemPointerIsValid(), XactLockTableWaitInfo::oper, XactLockTableWaitInfo::rel, RelationGetRelationName, RelationIsValid, XLTW_Delete, XLTW_FetchUpdated, XLTW_InsertIndex, XLTW_InsertIndexUnique, XLTW_Lock, XLTW_LockUpdated, XLTW_None, XLTW_RecheckExclusionConstr, and XLTW_Update.

Referenced by XactLockTableWait().

Variable Documentation

◆ speculativeInsertionToken

uint32 speculativeInsertionToken = 0
static

Definition at line 47 of file lmgr.c.

Referenced by SpeculativeInsertionLockAcquire(), and SpeculativeInsertionLockRelease().