Header And Logo

PostgreSQL
| The world's most advanced open source database.

Functions

lmgr.c File Reference

#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"
Include dependency graph for lmgr.c:

Go to the source code of this file.

Functions

void RelationInitLockInfo (Relation relation)
static void SetLocktagRelationOid (LOCKTAG *tag, Oid relid)
void LockRelationOid (Oid relid, LOCKMODE lockmode)
bool ConditionalLockRelationOid (Oid relid, LOCKMODE lockmode)
void UnlockRelationId (LockRelId *relid, LOCKMODE lockmode)
void UnlockRelationOid (Oid relid, LOCKMODE lockmode)
void LockRelation (Relation relation, LOCKMODE lockmode)
bool ConditionalLockRelation (Relation relation, LOCKMODE lockmode)
void UnlockRelation (Relation relation, LOCKMODE lockmode)
bool LockHasWaitersRelation (Relation relation, LOCKMODE lockmode)
void LockRelationIdForSession (LockRelId *relid, LOCKMODE lockmode)
void UnlockRelationIdForSession (LockRelId *relid, LOCKMODE lockmode)
void LockRelationForExtension (Relation relation, LOCKMODE lockmode)
void UnlockRelationForExtension (Relation relation, LOCKMODE lockmode)
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)
bool ConditionalXactLockTableWait (TransactionId xid)
void LockDatabaseObject (Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
void UnlockDatabaseObject (Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
void LockSharedObject (Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
void UnlockSharedObject (Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
void LockSharedObjectForSession (Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
void UnlockSharedObjectForSession (Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
void DescribeLockTag (StringInfo buf, const LOCKTAG *tag)

Function Documentation

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

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;
}

bool ConditionalLockRelationOid ( Oid  relid,
LOCKMODE  lockmode 
)

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 
)
bool ConditionalXactLockTableWait ( TransactionId  xid  ) 
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;
    }
}

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

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();
}

bool LockHasWaitersRelation ( Relation  relation,
LOCKMODE  lockmode 
)
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);
}

void LockRelation ( Relation  relation,
LOCKMODE  lockmode 
)

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();
}

void LockRelationForExtension ( Relation  relation,
LOCKMODE  lockmode 
)
void LockRelationIdForSession ( LockRelId relid,
LOCKMODE  lockmode 
)

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);
}

void LockRelationOid ( Oid  relid,
LOCKMODE  lockmode 
)

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();
}

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

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();
}

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

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 
)
void RelationInitLockInfo ( Relation  relation  ) 
static void SetLocktagRelationOid ( LOCKTAG tag,
Oid  relid 
) [inline, static]

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);
}

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

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);
}

void UnlockRelation ( Relation  relation,
LOCKMODE  lockmode 
)
void UnlockRelationForExtension ( Relation  relation,
LOCKMODE  lockmode 
)
void UnlockRelationId ( LockRelId relid,
LOCKMODE  lockmode 
)

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);
}

void UnlockRelationIdForSession ( LockRelId relid,
LOCKMODE  lockmode 
)

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);
}

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

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);
}

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

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