#include "postgres.h"
#include "access/subtrans.h"
#include "access/transam.h"
#include "access/xact.h"
#include "catalog/catalog.h"
#include "miscadmin.h"
#include "storage/lmgr.h"
#include "storage/procarray.h"
#include "utils/inval.h"
Go to the source code of this file.
bool ConditionalLockPage | ( | Relation | relation, | |
BlockNumber | blkno, | |||
LOCKMODE | lockmode | |||
) |
Definition at line 351 of file lmgr.c.
References LockRelId::dbId, LockAcquire(), LOCKACQUIRE_NOT_AVAIL, LockInfoData::lockRelId, RelationData::rd_lockInfo, LockRelId::relId, and SET_LOCKTAG_PAGE.
Referenced by _hash_try_getlock().
{ LOCKTAG tag; SET_LOCKTAG_PAGE(tag, relation->rd_lockInfo.lockRelId.dbId, relation->rd_lockInfo.lockRelId.relId, blkno); return (LockAcquire(&tag, lockmode, false, true) != LOCKACQUIRE_NOT_AVAIL); }
Definition at line 193 of file lmgr.c.
References AcceptInvalidationMessages(), LockRelId::dbId, LockAcquire(), LOCKACQUIRE_ALREADY_HELD, LOCKACQUIRE_NOT_AVAIL, LockInfoData::lockRelId, RelationData::rd_lockInfo, LockRelId::relId, and SET_LOCKTAG_RELATION.
Referenced by lazy_truncate_heap().
{ LOCKTAG tag; LockAcquireResult res; SET_LOCKTAG_RELATION(tag, relation->rd_lockInfo.lockRelId.dbId, relation->rd_lockInfo.lockRelId.relId); res = LockAcquire(&tag, lockmode, false, true); if (res == LOCKACQUIRE_NOT_AVAIL) return false; /* * Now that we have the lock, check for invalidation messages; see notes * in LockRelationOid. */ if (res != LOCKACQUIRE_ALREADY_HELD) AcceptInvalidationMessages(); return true; }
Definition at line 105 of file lmgr.c.
References AcceptInvalidationMessages(), LockAcquire(), LOCKACQUIRE_ALREADY_HELD, LOCKACQUIRE_NOT_AVAIL, and SetLocktagRelationOid().
Referenced by analyze_rel(), LockTableRecurse(), RangeVarGetRelidExtended(), and vacuum_rel().
{ LOCKTAG tag; LockAcquireResult res; SetLocktagRelationOid(&tag, relid); res = LockAcquire(&tag, lockmode, false, true); if (res == LOCKACQUIRE_NOT_AVAIL) return false; /* * Now that we have the lock, check for invalidation messages; see notes * in LockRelationOid. */ if (res != LOCKACQUIRE_ALREADY_HELD) AcceptInvalidationMessages(); return true; }
bool ConditionalLockTuple | ( | Relation | relation, | |
ItemPointer | tid, | |||
LOCKMODE | lockmode | |||
) |
Definition at line 407 of file lmgr.c.
References LockRelId::dbId, ItemPointerGetBlockNumber, ItemPointerGetOffsetNumber, LockAcquire(), LOCKACQUIRE_NOT_AVAIL, LockInfoData::lockRelId, RelationData::rd_lockInfo, LockRelId::relId, and SET_LOCKTAG_TUPLE.
{ LOCKTAG tag; SET_LOCKTAG_TUPLE(tag, relation->rd_lockInfo.lockRelId.dbId, relation->rd_lockInfo.lockRelId.relId, ItemPointerGetBlockNumber(tid), ItemPointerGetOffsetNumber(tid)); return (LockAcquire(&tag, lockmode, false, true) != LOCKACQUIRE_NOT_AVAIL); }
bool ConditionalXactLockTableWait | ( | TransactionId | xid | ) |
Definition at line 512 of file lmgr.c.
References Assert, GetTopTransactionIdIfAny(), LockAcquire(), LOCKACQUIRE_NOT_AVAIL, LockRelease(), SET_LOCKTAG_TRANSACTION, ShareLock, SubTransGetParent(), TransactionIdEquals, TransactionIdIsInProgress(), and TransactionIdIsValid.
Referenced by Do_MultiXactIdWait(), and heap_lock_tuple().
{ LOCKTAG tag; for (;;) { Assert(TransactionIdIsValid(xid)); Assert(!TransactionIdEquals(xid, GetTopTransactionIdIfAny())); SET_LOCKTAG_TRANSACTION(tag, xid); if (LockAcquire(&tag, ShareLock, false, true) == LOCKACQUIRE_NOT_AVAIL) return false; LockRelease(&tag, ShareLock, false); if (!TransactionIdIsInProgress(xid)) break; xid = SubTransGetParent(xid); } return true; }
void DescribeLockTag | ( | StringInfo | buf, | |
const LOCKTAG * | tag | |||
) |
Definition at line 669 of file lmgr.c.
References _, appendStringInfo(), LOCKTAG_ADVISORY, LOCKTAG::locktag_field1, LOCKTAG::locktag_field2, LOCKTAG::locktag_field3, LOCKTAG::locktag_field4, LOCKTAG_OBJECT, LOCKTAG_PAGE, LOCKTAG_RELATION, LOCKTAG_RELATION_EXTEND, LOCKTAG_TRANSACTION, LOCKTAG_TUPLE, LOCKTAG::locktag_type, LOCKTAG_USERLOCK, and LOCKTAG_VIRTUALTRANSACTION.
Referenced by DeadLockReport(), and ProcSleep().
{ switch ((LockTagType) tag->locktag_type) { case LOCKTAG_RELATION: appendStringInfo(buf, _("relation %u of database %u"), tag->locktag_field2, tag->locktag_field1); break; case LOCKTAG_RELATION_EXTEND: appendStringInfo(buf, _("extension of relation %u of database %u"), tag->locktag_field2, tag->locktag_field1); break; case LOCKTAG_PAGE: appendStringInfo(buf, _("page %u of relation %u of database %u"), tag->locktag_field3, tag->locktag_field2, tag->locktag_field1); break; case LOCKTAG_TUPLE: appendStringInfo(buf, _("tuple (%u,%u) of relation %u of database %u"), tag->locktag_field3, tag->locktag_field4, tag->locktag_field2, tag->locktag_field1); break; case LOCKTAG_TRANSACTION: appendStringInfo(buf, _("transaction %u"), tag->locktag_field1); break; case LOCKTAG_VIRTUALTRANSACTION: appendStringInfo(buf, _("virtual transaction %d/%u"), tag->locktag_field1, tag->locktag_field2); break; case LOCKTAG_OBJECT: appendStringInfo(buf, _("object %u of class %u of database %u"), tag->locktag_field3, tag->locktag_field2, tag->locktag_field1); break; case LOCKTAG_USERLOCK: /* reserved for old contrib code, now on pgfoundry */ appendStringInfo(buf, _("user lock [%u,%u,%u]"), tag->locktag_field1, tag->locktag_field2, tag->locktag_field3); break; case LOCKTAG_ADVISORY: appendStringInfo(buf, _("advisory lock [%u,%u,%u,%u]"), tag->locktag_field1, tag->locktag_field2, tag->locktag_field3, tag->locktag_field4); break; default: appendStringInfo(buf, _("unrecognized locktag type %d"), (int) tag->locktag_type); break; } }
Definition at line 545 of file lmgr.c.
References AcceptInvalidationMessages(), LockAcquire(), MyDatabaseId, and SET_LOCKTAG_OBJECT.
Referenced by AcquireDeletionLock(), AddEnumLabel(), get_object_address(), and RangeVarGetAndCheckCreationNamespace().
{ LOCKTAG tag; SET_LOCKTAG_OBJECT(tag, MyDatabaseId, classid, objid, objsubid); (void) LockAcquire(&tag, lockmode, false, false); /* Make sure syscaches are up-to-date with any changes we waited for */ AcceptInvalidationMessages(); }
Definition at line 242 of file lmgr.c.
References LockRelId::dbId, LockHasWaiters(), LockInfoData::lockRelId, RelationData::rd_lockInfo, LockRelId::relId, and SET_LOCKTAG_RELATION.
Referenced by count_nondeletable_pages().
{ LOCKTAG tag; SET_LOCKTAG_RELATION(tag, relation->rd_lockInfo.lockRelId.dbId, relation->rd_lockInfo.lockRelId.relId); return LockHasWaiters(&tag, lockmode, false); }
void LockPage | ( | Relation | relation, | |
BlockNumber | blkno, | |||
LOCKMODE | lockmode | |||
) |
Definition at line 332 of file lmgr.c.
References LockRelId::dbId, LockAcquire(), LockInfoData::lockRelId, RelationData::rd_lockInfo, LockRelId::relId, and SET_LOCKTAG_PAGE.
Referenced by _hash_getlock().
{ LOCKTAG tag; SET_LOCKTAG_PAGE(tag, relation->rd_lockInfo.lockRelId.dbId, relation->rd_lockInfo.lockRelId.relId, blkno); (void) LockAcquire(&tag, lockmode, false, false); }
Definition at line 166 of file lmgr.c.
References AcceptInvalidationMessages(), LockRelId::dbId, LockAcquire(), LOCKACQUIRE_ALREADY_HELD, LockInfoData::lockRelId, RelationData::rd_lockInfo, LockRelId::relId, and SET_LOCKTAG_RELATION.
Referenced by index_create().
{ LOCKTAG tag; LockAcquireResult res; SET_LOCKTAG_RELATION(tag, relation->rd_lockInfo.lockRelId.dbId, relation->rd_lockInfo.lockRelId.relId); res = LockAcquire(&tag, lockmode, false, false); /* * Now that we have the lock, check for invalidation messages; see notes * in LockRelationOid. */ if (res != LOCKACQUIRE_ALREADY_HELD) AcceptInvalidationMessages(); }
Definition at line 299 of file lmgr.c.
References LockRelId::dbId, LockAcquire(), LockInfoData::lockRelId, RelationData::rd_lockInfo, LockRelId::relId, and SET_LOCKTAG_RELATION_EXTEND.
Referenced by _bt_getbuf(), btvacuumscan(), fsm_extend(), GinNewBuffer(), ginvacuumcleanup(), gistNewBuffer(), gistvacuumcleanup(), lazy_scan_heap(), pgstat_index(), RelationGetBufferForTuple(), SpGistNewBuffer(), spgvacuumscan(), and vm_extend().
{ LOCKTAG tag; SET_LOCKTAG_RELATION_EXTEND(tag, relation->rd_lockInfo.lockRelId.dbId, relation->rd_lockInfo.lockRelId.relId); (void) LockAcquire(&tag, lockmode, false, false); }
Definition at line 266 of file lmgr.c.
References LockRelId::dbId, LockAcquire(), LockRelId::relId, and SET_LOCKTAG_RELATION.
Referenced by DefineIndex(), index_drop(), and vacuum_rel().
{ LOCKTAG tag; SET_LOCKTAG_RELATION(tag, relid->dbId, relid->relId); (void) LockAcquire(&tag, lockmode, true, false); }
Definition at line 72 of file lmgr.c.
References AcceptInvalidationMessages(), LockAcquire(), LOCKACQUIRE_ALREADY_HELD, and SetLocktagRelationOid().
Referenced by AcquireDeletionLock(), AcquireExecutorLocks(), copy_heap_data(), find_inheritance_children(), InitCatCachePhase2(), load_critical_index(), LockTableRecurse(), open_share_lock(), RangeVarCallbackForDropRelation(), RangeVarCallbackForReindexIndex(), RangeVarGetAndCheckCreationNamespace(), RangeVarGetRelidExtended(), relation_open(), ScanQueryForLocks(), and try_relation_open().
{ LOCKTAG tag; LockAcquireResult res; SetLocktagRelationOid(&tag, relid); res = LockAcquire(&tag, lockmode, false, false); /* * Now that we have the lock, check for invalidation messages, so that we * will update or flush any stale relcache entry before we try to use it. * RangeVarGetRelid() specifically relies on us for this. We can skip * this in the not-uncommon case that we already had the same type of lock * being requested, since then no one else could have modified the * relcache entry in an undesirable way. (In the case where our own xact * modifies the rel, the relcache update happens via * CommandCounterIncrement, not here.) */ if (res != LOCKACQUIRE_ALREADY_HELD) AcceptInvalidationMessages(); }
Definition at line 586 of file lmgr.c.
References AcceptInvalidationMessages(), InvalidOid, LockAcquire(), and SET_LOCKTAG_OBJECT.
Referenced by DropRole(), get_db_info(), get_object_address(), InitPostgres(), PreCommit_Notify(), and shdepLockAndCheckObject().
{ LOCKTAG tag; SET_LOCKTAG_OBJECT(tag, InvalidOid, classid, objid, objsubid); (void) LockAcquire(&tag, lockmode, false, false); /* Make sure syscaches are up-to-date with any changes we waited for */ AcceptInvalidationMessages(); }
Definition at line 628 of file lmgr.c.
References InvalidOid, LockAcquire(), and SET_LOCKTAG_OBJECT.
Referenced by dbase_redo(), and movedb().
{ LOCKTAG tag; SET_LOCKTAG_OBJECT(tag, InvalidOid, classid, objid, objsubid); (void) LockAcquire(&tag, lockmode, true, false); }
void LockTuple | ( | Relation | relation, | |
ItemPointer | tid, | |||
LOCKMODE | lockmode | |||
) |
Definition at line 387 of file lmgr.c.
References LockRelId::dbId, ItemPointerGetBlockNumber, ItemPointerGetOffsetNumber, LockAcquire(), LockInfoData::lockRelId, RelationData::rd_lockInfo, LockRelId::relId, and SET_LOCKTAG_TUPLE.
{ LOCKTAG tag; SET_LOCKTAG_TUPLE(tag, relation->rd_lockInfo.lockRelId.dbId, relation->rd_lockInfo.lockRelId.relId, ItemPointerGetBlockNumber(tid), ItemPointerGetOffsetNumber(tid)); (void) LockAcquire(&tag, lockmode, false, false); }
void RelationInitLockInfo | ( | Relation | relation | ) |
Definition at line 35 of file lmgr.c.
References Assert, LockRelId::dbId, 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().
{ Assert(RelationIsValid(relation)); Assert(OidIsValid(RelationGetRelid(relation))); relation->rd_lockInfo.lockRelId.relId = RelationGetRelid(relation); if (relation->rd_rel->relisshared) relation->rd_lockInfo.lockRelId.dbId = InvalidOid; else relation->rd_lockInfo.lockRelId.dbId = MyDatabaseId; }
Definition at line 53 of file lmgr.c.
References IsSharedRelation(), MyDatabaseId, and SET_LOCKTAG_RELATION.
Referenced by ConditionalLockRelationOid(), LockRelationOid(), and UnlockRelationOid().
{ Oid dbid; if (IsSharedRelation(relid)) dbid = InvalidOid; else dbid = MyDatabaseId; SET_LOCKTAG_RELATION(*tag, dbid, relid); }
Definition at line 566 of file lmgr.c.
References LockRelease(), MyDatabaseId, and SET_LOCKTAG_OBJECT.
Referenced by get_object_address(), RangeVarGetAndCheckCreationNamespace(), and ReleaseDeletionLock().
{ LOCKTAG tag; SET_LOCKTAG_OBJECT(tag, MyDatabaseId, classid, objid, objsubid); LockRelease(&tag, lockmode, false); }
void UnlockPage | ( | Relation | relation, | |
BlockNumber | blkno, | |||
LOCKMODE | lockmode | |||
) |
Definition at line 367 of file lmgr.c.
References LockRelId::dbId, LockRelease(), LockInfoData::lockRelId, RelationData::rd_lockInfo, LockRelId::relId, and SET_LOCKTAG_PAGE.
Referenced by _hash_droplock().
{ LOCKTAG tag; SET_LOCKTAG_PAGE(tag, relation->rd_lockInfo.lockRelId.dbId, relation->rd_lockInfo.lockRelId.relId, blkno); LockRelease(&tag, lockmode, false); }
Definition at line 224 of file lmgr.c.
References LockRelId::dbId, LockRelease(), LockInfoData::lockRelId, RelationData::rd_lockInfo, LockRelId::relId, and SET_LOCKTAG_RELATION.
Referenced by lazy_truncate_heap().
{ LOCKTAG tag; SET_LOCKTAG_RELATION(tag, relation->rd_lockInfo.lockRelId.dbId, relation->rd_lockInfo.lockRelId.relId); LockRelease(&tag, lockmode, false); }
Definition at line 314 of file lmgr.c.
References LockRelId::dbId, LockRelease(), LockInfoData::lockRelId, RelationData::rd_lockInfo, LockRelId::relId, and SET_LOCKTAG_RELATION_EXTEND.
Referenced by _bt_getbuf(), btvacuumscan(), fsm_extend(), GinNewBuffer(), ginvacuumcleanup(), gistNewBuffer(), gistvacuumcleanup(), lazy_scan_heap(), pgstat_index(), RelationGetBufferForTuple(), SpGistNewBuffer(), spgvacuumscan(), and vm_extend().
{ LOCKTAG tag; SET_LOCKTAG_RELATION_EXTEND(tag, relation->rd_lockInfo.lockRelId.dbId, relation->rd_lockInfo.lockRelId.relId); LockRelease(&tag, lockmode, false); }
Definition at line 134 of file lmgr.c.
References LockRelId::dbId, LockRelease(), LockRelId::relId, and SET_LOCKTAG_RELATION.
Referenced by index_close(), and relation_close().
{ LOCKTAG tag; SET_LOCKTAG_RELATION(tag, relid->dbId, relid->relId); LockRelease(&tag, lockmode, false); }
Definition at line 279 of file lmgr.c.
References LockRelId::dbId, LockRelease(), LockRelId::relId, and SET_LOCKTAG_RELATION.
Referenced by DefineIndex(), index_drop(), and vacuum_rel().
{ LOCKTAG tag; SET_LOCKTAG_RELATION(tag, relid->dbId, relid->relId); LockRelease(&tag, lockmode, true); }
Definition at line 149 of file lmgr.c.
References LockRelease(), and SetLocktagRelationOid().
Referenced by AcquireExecutorLocks(), find_inheritance_children(), InitCatCachePhase2(), load_critical_index(), LockTableRecurse(), RangeVarCallbackForDropRelation(), RangeVarCallbackForReindexIndex(), RangeVarGetAndCheckCreationNamespace(), RangeVarGetRelidExtended(), ReleaseDeletionLock(), ScanQueryForLocks(), and try_relation_open().
{ LOCKTAG tag; SetLocktagRelationOid(&tag, relid); LockRelease(&tag, lockmode, false); }
Definition at line 607 of file lmgr.c.
References InvalidOid, LockRelease(), and SET_LOCKTAG_OBJECT.
Referenced by AlterDatabaseSet(), createdb_failure_callback(), get_db_info(), and get_object_address().
{ LOCKTAG tag; SET_LOCKTAG_OBJECT(tag, InvalidOid, classid, objid, objsubid); LockRelease(&tag, lockmode, false); }
Definition at line 646 of file lmgr.c.
References InvalidOid, LockRelease(), and SET_LOCKTAG_OBJECT.
Referenced by dbase_redo(), and movedb().
{ LOCKTAG tag; SET_LOCKTAG_OBJECT(tag, InvalidOid, classid, objid, objsubid); LockRelease(&tag, lockmode, true); }
void UnlockTuple | ( | Relation | relation, | |
ItemPointer | tid, | |||
LOCKMODE | lockmode | |||
) |
Definition at line 424 of file lmgr.c.
References LockRelId::dbId, ItemPointerGetBlockNumber, ItemPointerGetOffsetNumber, LockRelease(), LockInfoData::lockRelId, RelationData::rd_lockInfo, LockRelId::relId, and SET_LOCKTAG_TUPLE.
{ LOCKTAG tag; SET_LOCKTAG_TUPLE(tag, relation->rd_lockInfo.lockRelId.dbId, relation->rd_lockInfo.lockRelId.relId, ItemPointerGetBlockNumber(tid), ItemPointerGetOffsetNumber(tid)); LockRelease(&tag, lockmode, false); }
void XactLockTableDelete | ( | TransactionId | xid | ) |
Definition at line 462 of file lmgr.c.
References ExclusiveLock, LockRelease(), and SET_LOCKTAG_TRANSACTION.
Referenced by CommitSubTransaction().
{ LOCKTAG tag; SET_LOCKTAG_TRANSACTION(tag, xid); LockRelease(&tag, ExclusiveLock, false); }
void XactLockTableInsert | ( | TransactionId | xid | ) |
Definition at line 445 of file lmgr.c.
References ExclusiveLock, LockAcquire(), and SET_LOCKTAG_TRANSACTION.
Referenced by AssignTransactionId().
{ LOCKTAG tag; SET_LOCKTAG_TRANSACTION(tag, xid); (void) LockAcquire(&tag, ExclusiveLock, false, false); }
void XactLockTableWait | ( | TransactionId | xid | ) |
Definition at line 484 of file lmgr.c.
References Assert, GetTopTransactionIdIfAny(), LockAcquire(), LockRelease(), SET_LOCKTAG_TRANSACTION, ShareLock, SubTransGetParent(), TransactionIdEquals, TransactionIdIsInProgress(), and TransactionIdIsValid.
Referenced by _bt_doinsert(), check_exclusion_constraint(), Do_MultiXactIdWait(), EvalPlanQualFetch(), heap_delete(), heap_lock_tuple(), heap_lock_updated_tuple_rec(), heap_update(), and IndexBuildHeapScan().
{ LOCKTAG tag; for (;;) { Assert(TransactionIdIsValid(xid)); Assert(!TransactionIdEquals(xid, GetTopTransactionIdIfAny())); SET_LOCKTAG_TRANSACTION(tag, xid); (void) LockAcquire(&tag, ShareLock, false, false); LockRelease(&tag, ShareLock, false); if (!TransactionIdIsInProgress(xid)) break; xid = SubTransGetParent(xid); } }