#include "storage/fd.h"
#include "storage/lock.h"
#include "utils/catcache.h"
#include "utils/plancache.h"
#include "utils/resowner.h"
#include "utils/snapshot.h"
Go to the source code of this file.
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().
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().
void ResourceOwnerRememberCatCacheListRef | ( | ResourceOwner | owner, | |
CatCList * | list | |||
) |
Definition at line 791 of file resowner.c.
References Assert, ResourceOwnerData::catlistrefs, ResourceOwnerData::maxcatlistrefs, and ResourceOwnerData::ncatlistrefs.
Referenced by SearchCatCacheList().
{ Assert(owner->ncatlistrefs < owner->maxcatlistrefs); owner->catlistrefs[owner->ncatlistrefs] = list; owner->ncatlistrefs++; }
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().
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().
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().
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().
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().