Header And Logo

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

Functions

resowner_private.h File Reference

#include "storage/fd.h"
#include "storage/lock.h"
#include "utils/catcache.h"
#include "utils/plancache.h"
#include "utils/resowner.h"
#include "utils/snapshot.h"
Include dependency graph for resowner_private.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void ResourceOwnerEnlargeBuffers (ResourceOwner owner)
void ResourceOwnerRememberBuffer (ResourceOwner owner, Buffer buffer)
void ResourceOwnerForgetBuffer (ResourceOwner owner, Buffer buffer)
void ResourceOwnerRememberLock (ResourceOwner owner, LOCALLOCK *locallock)
void ResourceOwnerForgetLock (ResourceOwner owner, LOCALLOCK *locallock)
void ResourceOwnerEnlargeCatCacheRefs (ResourceOwner owner)
void ResourceOwnerRememberCatCacheRef (ResourceOwner owner, HeapTuple tuple)
void ResourceOwnerForgetCatCacheRef (ResourceOwner owner, HeapTuple tuple)
void ResourceOwnerEnlargeCatCacheListRefs (ResourceOwner owner)
void ResourceOwnerRememberCatCacheListRef (ResourceOwner owner, CatCList *list)
void ResourceOwnerForgetCatCacheListRef (ResourceOwner owner, CatCList *list)
void ResourceOwnerEnlargeRelationRefs (ResourceOwner owner)
void ResourceOwnerRememberRelationRef (ResourceOwner owner, Relation rel)
void ResourceOwnerForgetRelationRef (ResourceOwner owner, Relation rel)
void ResourceOwnerEnlargePlanCacheRefs (ResourceOwner owner)
void ResourceOwnerRememberPlanCacheRef (ResourceOwner owner, CachedPlan *plan)
void ResourceOwnerForgetPlanCacheRef (ResourceOwner owner, CachedPlan *plan)
void ResourceOwnerEnlargeTupleDescs (ResourceOwner owner)
void ResourceOwnerRememberTupleDesc (ResourceOwner owner, TupleDesc tupdesc)
void ResourceOwnerForgetTupleDesc (ResourceOwner owner, TupleDesc tupdesc)
void ResourceOwnerEnlargeSnapshots (ResourceOwner owner)
void ResourceOwnerRememberSnapshot (ResourceOwner owner, Snapshot snapshot)
void ResourceOwnerForgetSnapshot (ResourceOwner owner, Snapshot snapshot)
void ResourceOwnerEnlargeFiles (ResourceOwner owner)
void ResourceOwnerRememberFile (ResourceOwner owner, File file)
void ResourceOwnerForgetFile (ResourceOwner owner, File file)

Function Documentation

void ResourceOwnerEnlargeBuffers ( ResourceOwner  owner  ) 

Definition at line 552 of file resowner.c.

References ResourceOwnerData::buffers, ResourceOwnerData::maxbuffers, MemoryContextAlloc(), ResourceOwnerData::nbuffers, NULL, repalloc(), and TopMemoryContext.

Referenced by BgBufferSync(), BufferSync(), FlushDatabaseBuffers(), FlushRelationBuffers(), IncrBufferRefCount(), and ReadBuffer_common().

{
    int         newmax;

    if (owner == NULL ||
        owner->nbuffers < owner->maxbuffers)
        return;                 /* nothing to do */

    if (owner->buffers == NULL)
    {
        newmax = 16;
        owner->buffers = (Buffer *)
            MemoryContextAlloc(TopMemoryContext, newmax * sizeof(Buffer));
        owner->maxbuffers = newmax;
    }
    else
    {
        newmax = owner->maxbuffers * 2;
        owner->buffers = (Buffer *)
            repalloc(owner->buffers, newmax * sizeof(Buffer));
        owner->maxbuffers = newmax;
    }
}

void ResourceOwnerEnlargeCatCacheListRefs ( ResourceOwner  owner  ) 

Definition at line 762 of file resowner.c.

References ResourceOwnerData::catlistrefs, ResourceOwnerData::maxcatlistrefs, MemoryContextAlloc(), ResourceOwnerData::ncatlistrefs, NULL, repalloc(), and TopMemoryContext.

Referenced by SearchCatCacheList().

{
    int         newmax;

    if (owner->ncatlistrefs < owner->maxcatlistrefs)
        return;                 /* nothing to do */

    if (owner->catlistrefs == NULL)
    {
        newmax = 16;
        owner->catlistrefs = (CatCList **)
            MemoryContextAlloc(TopMemoryContext, newmax * sizeof(CatCList *));
        owner->maxcatlistrefs = newmax;
    }
    else
    {
        newmax = owner->maxcatlistrefs * 2;
        owner->catlistrefs = (CatCList **)
            repalloc(owner->catlistrefs, newmax * sizeof(CatCList *));
        owner->maxcatlistrefs = newmax;
    }
}

void ResourceOwnerEnlargeCatCacheRefs ( ResourceOwner  owner  ) 

Definition at line 691 of file resowner.c.

References ResourceOwnerData::catrefs, ResourceOwnerData::maxcatrefs, MemoryContextAlloc(), ResourceOwnerData::ncatrefs, NULL, repalloc(), and TopMemoryContext.

Referenced by SearchCatCache().

{
    int         newmax;

    if (owner->ncatrefs < owner->maxcatrefs)
        return;                 /* nothing to do */

    if (owner->catrefs == NULL)
    {
        newmax = 16;
        owner->catrefs = (HeapTuple *)
            MemoryContextAlloc(TopMemoryContext, newmax * sizeof(HeapTuple));
        owner->maxcatrefs = newmax;
    }
    else
    {
        newmax = owner->maxcatrefs * 2;
        owner->catrefs = (HeapTuple *)
            repalloc(owner->catrefs, newmax * sizeof(HeapTuple));
        owner->maxcatrefs = newmax;
    }
}

void ResourceOwnerEnlargeFiles ( ResourceOwner  owner  ) 

Definition at line 1159 of file resowner.c.

References ResourceOwnerData::files, ResourceOwnerData::maxfiles, MemoryContextAlloc(), ResourceOwnerData::nfiles, NULL, repalloc(), and TopMemoryContext.

Referenced by OpenTemporaryFile().

{
    int         newmax;

    if (owner->nfiles < owner->maxfiles)
        return;                 /* nothing to do */

    if (owner->files == NULL)
    {
        newmax = 16;
        owner->files = (File *)
            MemoryContextAlloc(TopMemoryContext, newmax * sizeof(File));
        owner->maxfiles = newmax;
    }
    else
    {
        newmax = owner->maxfiles * 2;
        owner->files = (File *)
            repalloc(owner->files, newmax * sizeof(File));
        owner->maxfiles = newmax;
    }
}

void ResourceOwnerEnlargePlanCacheRefs ( ResourceOwner  owner  ) 

Definition at line 914 of file resowner.c.

References ResourceOwnerData::maxplanrefs, MemoryContextAlloc(), ResourceOwnerData::nplanrefs, NULL, ResourceOwnerData::planrefs, repalloc(), and TopMemoryContext.

Referenced by GetCachedPlan().

{
    int         newmax;

    if (owner->nplanrefs < owner->maxplanrefs)
        return;                 /* nothing to do */

    if (owner->planrefs == NULL)
    {
        newmax = 16;
        owner->planrefs = (CachedPlan **)
            MemoryContextAlloc(TopMemoryContext, newmax * sizeof(CachedPlan *));
        owner->maxplanrefs = newmax;
    }
    else
    {
        newmax = owner->maxplanrefs * 2;
        owner->planrefs = (CachedPlan **)
            repalloc(owner->planrefs, newmax * sizeof(CachedPlan *));
        owner->maxplanrefs = newmax;
    }
}

void ResourceOwnerEnlargeRelationRefs ( ResourceOwner  owner  ) 

Definition at line 833 of file resowner.c.

References ResourceOwnerData::maxrelrefs, MemoryContextAlloc(), ResourceOwnerData::nrelrefs, NULL, ResourceOwnerData::relrefs, repalloc(), and TopMemoryContext.

Referenced by RelationIncrementReferenceCount().

{
    int         newmax;

    if (owner->nrelrefs < owner->maxrelrefs)
        return;                 /* nothing to do */

    if (owner->relrefs == NULL)
    {
        newmax = 16;
        owner->relrefs = (Relation *)
            MemoryContextAlloc(TopMemoryContext, newmax * sizeof(Relation));
        owner->maxrelrefs = newmax;
    }
    else
    {
        newmax = owner->maxrelrefs * 2;
        owner->relrefs = (Relation *)
            repalloc(owner->relrefs, newmax * sizeof(Relation));
        owner->maxrelrefs = newmax;
    }
}

void ResourceOwnerEnlargeSnapshots ( ResourceOwner  owner  ) 

Definition at line 1076 of file resowner.c.

References ResourceOwnerData::maxsnapshots, MemoryContextAlloc(), ResourceOwnerData::nsnapshots, NULL, repalloc(), ResourceOwnerData::snapshots, and TopMemoryContext.

Referenced by RegisterSnapshotOnOwner().

{
    int         newmax;

    if (owner->nsnapshots < owner->maxsnapshots)
        return;                 /* nothing to do */

    if (owner->snapshots == NULL)
    {
        newmax = 16;
        owner->snapshots = (Snapshot *)
            MemoryContextAlloc(TopMemoryContext, newmax * sizeof(Snapshot));
        owner->maxsnapshots = newmax;
    }
    else
    {
        newmax = owner->maxsnapshots * 2;
        owner->snapshots = (Snapshot *)
            repalloc(owner->snapshots, newmax * sizeof(Snapshot));
        owner->maxsnapshots = newmax;
    }
}

void ResourceOwnerEnlargeTupleDescs ( ResourceOwner  owner  ) 

Definition at line 994 of file resowner.c.

References ResourceOwnerData::maxtupdescs, MemoryContextAlloc(), ResourceOwnerData::ntupdescs, NULL, repalloc(), TopMemoryContext, and ResourceOwnerData::tupdescs.

Referenced by IncrTupleDescRefCount().

{
    int         newmax;

    if (owner->ntupdescs < owner->maxtupdescs)
        return;                 /* nothing to do */

    if (owner->tupdescs == NULL)
    {
        newmax = 16;
        owner->tupdescs = (TupleDesc *)
            MemoryContextAlloc(TopMemoryContext, newmax * sizeof(TupleDesc));
        owner->maxtupdescs = newmax;
    }
    else
    {
        newmax = owner->maxtupdescs * 2;
        owner->tupdescs = (TupleDesc *)
            repalloc(owner->tupdescs, newmax * sizeof(TupleDesc));
        owner->maxtupdescs = newmax;
    }
}

void ResourceOwnerForgetBuffer ( ResourceOwner  owner,
Buffer  buffer 
)

Definition at line 602 of file resowner.c.

References ResourceOwnerData::buffers, elog, ERROR, i, ResourceOwnerData::name, ResourceOwnerData::nbuffers, and NULL.

Referenced by ReleaseAndReadBuffer(), ReleaseBuffer(), and UnpinBuffer().

{
    if (owner != NULL)
    {
        Buffer     *buffers = owner->buffers;
        int         nb1 = owner->nbuffers - 1;
        int         i;

        /*
         * Scan back-to-front because it's more likely we are releasing a
         * recently pinned buffer.  This isn't always the case of course, but
         * it's the way to bet.
         */
        for (i = nb1; i >= 0; i--)
        {
            if (buffers[i] == buffer)
            {
                while (i < nb1)
                {
                    buffers[i] = buffers[i + 1];
                    i++;
                }
                owner->nbuffers = nb1;
                return;
            }
        }
        elog(ERROR, "buffer %d is not owned by resource owner %s",
             buffer, owner->name);
    }
}

void ResourceOwnerForgetCatCacheListRef ( ResourceOwner  owner,
CatCList list 
)

Definition at line 802 of file resowner.c.

References ResourceOwnerData::catlistrefs, elog, ERROR, i, ResourceOwnerData::name, and ResourceOwnerData::ncatlistrefs.

Referenced by ReleaseCatCacheList().

{
    CatCList  **catlistrefs = owner->catlistrefs;
    int         nc1 = owner->ncatlistrefs - 1;
    int         i;

    for (i = nc1; i >= 0; i--)
    {
        if (catlistrefs[i] == list)
        {
            while (i < nc1)
            {
                catlistrefs[i] = catlistrefs[i + 1];
                i++;
            }
            owner->ncatlistrefs = nc1;
            return;
        }
    }
    elog(ERROR, "catcache list reference %p is not owned by resource owner %s",
         list, owner->name);
}

void ResourceOwnerForgetCatCacheRef ( ResourceOwner  owner,
HeapTuple  tuple 
)

Definition at line 731 of file resowner.c.

References ResourceOwnerData::catrefs, elog, ERROR, i, ResourceOwnerData::name, and ResourceOwnerData::ncatrefs.

Referenced by ReleaseCatCache().

{
    HeapTuple  *catrefs = owner->catrefs;
    int         nc1 = owner->ncatrefs - 1;
    int         i;

    for (i = nc1; i >= 0; i--)
    {
        if (catrefs[i] == tuple)
        {
            while (i < nc1)
            {
                catrefs[i] = catrefs[i + 1];
                i++;
            }
            owner->ncatrefs = nc1;
            return;
        }
    }
    elog(ERROR, "catcache reference %p is not owned by resource owner %s",
         tuple, owner->name);
}

void ResourceOwnerForgetFile ( ResourceOwner  owner,
File  file 
)

Definition at line 1199 of file resowner.c.

References elog, ERROR, ResourceOwnerData::files, i, ResourceOwnerData::name, and ResourceOwnerData::nfiles.

Referenced by FileClose().

{
    File       *files = owner->files;
    int         ns1 = owner->nfiles - 1;
    int         i;

    for (i = ns1; i >= 0; i--)
    {
        if (files[i] == file)
        {
            while (i < ns1)
            {
                files[i] = files[i + 1];
                i++;
            }
            owner->nfiles = ns1;
            return;
        }
    }
    elog(ERROR, "temporery file %d is not owned by resource owner %s",
         file, owner->name);
}

void ResourceOwnerForgetLock ( ResourceOwner  owner,
LOCALLOCK locallock 
)

Definition at line 662 of file resowner.c.

References Assert, elog, ERROR, i, ResourceOwnerData::locks, MAX_RESOWNER_LOCKS, ResourceOwnerData::name, and ResourceOwnerData::nlocks.

Referenced by LockReassignOwner(), LockRelease(), LockReleaseAll(), ReleaseLockIfHeld(), and RemoveLocalLock().

{
    int         i;

    if (owner->nlocks > MAX_RESOWNER_LOCKS)
        return;     /* we have overflowed */

    Assert(owner->nlocks > 0);
    for (i = owner->nlocks - 1; i >= 0; i--)
    {
        if (locallock == owner->locks[i])
        {
            owner->locks[i] = owner->locks[owner->nlocks - 1];
            owner->nlocks--;
            return;
        }
    }
    elog(ERROR, "lock reference %p is not owned by resource owner %s",
         locallock, owner->name);
}

void ResourceOwnerForgetPlanCacheRef ( ResourceOwner  owner,
CachedPlan plan 
)

Definition at line 954 of file resowner.c.

References elog, ERROR, i, ResourceOwnerData::name, ResourceOwnerData::nplanrefs, and ResourceOwnerData::planrefs.

Referenced by ReleaseCachedPlan().

{
    CachedPlan **planrefs = owner->planrefs;
    int         np1 = owner->nplanrefs - 1;
    int         i;

    for (i = np1; i >= 0; i--)
    {
        if (planrefs[i] == plan)
        {
            while (i < np1)
            {
                planrefs[i] = planrefs[i + 1];
                i++;
            }
            owner->nplanrefs = np1;
            return;
        }
    }
    elog(ERROR, "plancache reference %p is not owned by resource owner %s",
         plan, owner->name);
}

void ResourceOwnerForgetRelationRef ( ResourceOwner  owner,
Relation  rel 
)

Definition at line 873 of file resowner.c.

References elog, ERROR, i, ResourceOwnerData::name, ResourceOwnerData::nrelrefs, RelationGetRelationName, and ResourceOwnerData::relrefs.

Referenced by RelationDecrementReferenceCount().

{
    Relation   *relrefs = owner->relrefs;
    int         nr1 = owner->nrelrefs - 1;
    int         i;

    for (i = nr1; i >= 0; i--)
    {
        if (relrefs[i] == rel)
        {
            while (i < nr1)
            {
                relrefs[i] = relrefs[i + 1];
                i++;
            }
            owner->nrelrefs = nr1;
            return;
        }
    }
    elog(ERROR, "relcache reference %s is not owned by resource owner %s",
         RelationGetRelationName(rel), owner->name);
}

void ResourceOwnerForgetSnapshot ( ResourceOwner  owner,
Snapshot  snapshot 
)

Definition at line 1116 of file resowner.c.

References elog, ERROR, i, ResourceOwnerData::name, ResourceOwnerData::nsnapshots, and ResourceOwnerData::snapshots.

Referenced by UnregisterSnapshotFromOwner().

{
    Snapshot   *snapshots = owner->snapshots;
    int         ns1 = owner->nsnapshots - 1;
    int         i;

    for (i = ns1; i >= 0; i--)
    {
        if (snapshots[i] == snapshot)
        {
            while (i < ns1)
            {
                snapshots[i] = snapshots[i + 1];
                i++;
            }
            owner->nsnapshots = ns1;
            return;
        }
    }
    elog(ERROR, "snapshot reference %p is not owned by resource owner %s",
         snapshot, owner->name);
}

void ResourceOwnerForgetTupleDesc ( ResourceOwner  owner,
TupleDesc  tupdesc 
)

Definition at line 1034 of file resowner.c.

References elog, ERROR, i, ResourceOwnerData::name, ResourceOwnerData::ntupdescs, and ResourceOwnerData::tupdescs.

Referenced by DecrTupleDescRefCount().

{
    TupleDesc  *tupdescs = owner->tupdescs;
    int         nt1 = owner->ntupdescs - 1;
    int         i;

    for (i = nt1; i >= 0; i--)
    {
        if (tupdescs[i] == tupdesc)
        {
            while (i < nt1)
            {
                tupdescs[i] = tupdescs[i + 1];
                i++;
            }
            owner->ntupdescs = nt1;
            return;
        }
    }
    elog(ERROR, "tupdesc reference %p is not owned by resource owner %s",
         tupdesc, owner->name);
}

void ResourceOwnerRememberBuffer ( ResourceOwner  owner,
Buffer  buffer 
)

Definition at line 585 of file resowner.c.

References Assert, ResourceOwnerData::buffers, ResourceOwnerData::maxbuffers, ResourceOwnerData::nbuffers, and NULL.

Referenced by IncrBufferRefCount(), LocalBufferAlloc(), PinBuffer(), and PinBuffer_Locked().

{
    if (owner != NULL)
    {
        Assert(owner->nbuffers < owner->maxbuffers);
        owner->buffers[owner->nbuffers] = buffer;
        owner->nbuffers++;
    }
}

void ResourceOwnerRememberCatCacheListRef ( ResourceOwner  owner,
CatCList list 
)
void ResourceOwnerRememberCatCacheRef ( ResourceOwner  owner,
HeapTuple  tuple 
)

Definition at line 720 of file resowner.c.

References Assert, ResourceOwnerData::catrefs, ResourceOwnerData::maxcatrefs, and ResourceOwnerData::ncatrefs.

Referenced by SearchCatCache().

{
    Assert(owner->ncatrefs < owner->maxcatrefs);
    owner->catrefs[owner->ncatrefs] = tuple;
    owner->ncatrefs++;
}

void ResourceOwnerRememberFile ( ResourceOwner  owner,
File  file 
)

Definition at line 1188 of file resowner.c.

References Assert, ResourceOwnerData::files, ResourceOwnerData::maxfiles, and ResourceOwnerData::nfiles.

Referenced by OpenTemporaryFile().

{
    Assert(owner->nfiles < owner->maxfiles);
    owner->files[owner->nfiles] = file;
    owner->nfiles++;
}

void ResourceOwnerRememberLock ( ResourceOwner  owner,
LOCALLOCK locallock 
)

Definition at line 644 of file resowner.c.

References ResourceOwnerData::locks, MAX_RESOWNER_LOCKS, and ResourceOwnerData::nlocks.

Referenced by GrantLockLocal(), and LockReassignOwner().

{
    if (owner->nlocks > MAX_RESOWNER_LOCKS)
        return;     /* we have already overflowed */

    if (owner->nlocks < MAX_RESOWNER_LOCKS)
        owner->locks[owner->nlocks] = locallock;
    else
    {
        /* overflowed */
    }
    owner->nlocks++;
}

void ResourceOwnerRememberPlanCacheRef ( ResourceOwner  owner,
CachedPlan plan 
)

Definition at line 943 of file resowner.c.

References Assert, ResourceOwnerData::maxplanrefs, ResourceOwnerData::nplanrefs, and ResourceOwnerData::planrefs.

Referenced by GetCachedPlan().

{
    Assert(owner->nplanrefs < owner->maxplanrefs);
    owner->planrefs[owner->nplanrefs] = plan;
    owner->nplanrefs++;
}

void ResourceOwnerRememberRelationRef ( ResourceOwner  owner,
Relation  rel 
)

Definition at line 862 of file resowner.c.

References Assert, ResourceOwnerData::maxrelrefs, ResourceOwnerData::nrelrefs, and ResourceOwnerData::relrefs.

Referenced by RelationIncrementReferenceCount().

{
    Assert(owner->nrelrefs < owner->maxrelrefs);
    owner->relrefs[owner->nrelrefs] = rel;
    owner->nrelrefs++;
}

void ResourceOwnerRememberSnapshot ( ResourceOwner  owner,
Snapshot  snapshot 
)

Definition at line 1105 of file resowner.c.

References Assert, ResourceOwnerData::maxsnapshots, ResourceOwnerData::nsnapshots, and ResourceOwnerData::snapshots.

Referenced by RegisterSnapshotOnOwner().

{
    Assert(owner->nsnapshots < owner->maxsnapshots);
    owner->snapshots[owner->nsnapshots] = snapshot;
    owner->nsnapshots++;
}

void ResourceOwnerRememberTupleDesc ( ResourceOwner  owner,
TupleDesc  tupdesc 
)

Definition at line 1023 of file resowner.c.

References Assert, ResourceOwnerData::maxtupdescs, ResourceOwnerData::ntupdescs, and ResourceOwnerData::tupdescs.

Referenced by IncrTupleDescRefCount().

{
    Assert(owner->ntupdescs < owner->maxtupdescs);
    owner->tupdescs[owner->ntupdescs] = tupdesc;
    owner->ntupdescs++;
}