PostgreSQL Source Code  git master
resowner.c File Reference
#include "postgres.h"
#include "jit/jit.h"
#include "storage/bufmgr.h"
#include "storage/ipc.h"
#include "storage/predicate.h"
#include "storage/proc.h"
#include "utils/hashutils.h"
#include "utils/memutils.h"
#include "utils/rel.h"
#include "utils/resowner_private.h"
#include "utils/snapmgr.h"
Include dependency graph for resowner.c:

Go to the source code of this file.

Data Structures

struct  ResourceArray
 
struct  ResourceOwnerData
 
struct  ResourceReleaseCallbackItem
 

Macros

#define FileGetDatum(file)   Int32GetDatum(file)
 
#define DatumGetFile(datum)   ((File) DatumGetInt32(datum))
 
#define BufferGetDatum(buffer)   Int32GetDatum(buffer)
 
#define DatumGetBuffer(datum)   ((Buffer) DatumGetInt32(datum))
 
#define RESARRAY_INIT_SIZE   16
 
#define RESARRAY_MAX_ARRAY   64
 
#define RESARRAY_IS_ARRAY(resarr)   ((resarr)->capacity <= RESARRAY_MAX_ARRAY)
 
#define RESARRAY_MAX_ITEMS(capacity)   ((capacity) <= RESARRAY_MAX_ARRAY ? (capacity) : (capacity)/4 * 3)
 
#define MAX_RESOWNER_LOCKS   15
 

Typedefs

typedef struct ResourceArray ResourceArray
 
typedef struct ResourceOwnerData ResourceOwnerData
 
typedef struct ResourceReleaseCallbackItem ResourceReleaseCallbackItem
 

Functions

static void ResourceArrayInit (ResourceArray *resarr, Datum invalidval)
 
static void ResourceArrayEnlarge (ResourceArray *resarr)
 
static void ResourceArrayAdd (ResourceArray *resarr, Datum value)
 
static bool ResourceArrayRemove (ResourceArray *resarr, Datum value)
 
static bool ResourceArrayGetAny (ResourceArray *resarr, Datum *value)
 
static void ResourceArrayFree (ResourceArray *resarr)
 
static void ResourceOwnerReleaseInternal (ResourceOwner owner, ResourceReleasePhase phase, bool isCommit, bool isTopLevel)
 
static void ReleaseAuxProcessResourcesCallback (int code, Datum arg)
 
static void PrintRelCacheLeakWarning (Relation rel)
 
static void PrintPlanCacheLeakWarning (CachedPlan *plan)
 
static void PrintTupleDescLeakWarning (TupleDesc tupdesc)
 
static void PrintSnapshotLeakWarning (Snapshot snapshot)
 
static void PrintFileLeakWarning (File file)
 
static void PrintDSMLeakWarning (dsm_segment *seg)
 
ResourceOwner ResourceOwnerCreate (ResourceOwner parent, const char *name)
 
void ResourceOwnerRelease (ResourceOwner owner, ResourceReleasePhase phase, bool isCommit, bool isTopLevel)
 
void ResourceOwnerDelete (ResourceOwner owner)
 
ResourceOwner ResourceOwnerGetParent (ResourceOwner owner)
 
void ResourceOwnerNewParent (ResourceOwner owner, ResourceOwner newparent)
 
void RegisterResourceReleaseCallback (ResourceReleaseCallback callback, void *arg)
 
void UnregisterResourceReleaseCallback (ResourceReleaseCallback callback, void *arg)
 
void CreateAuxProcessResourceOwner (void)
 
void ReleaseAuxProcessResources (bool isCommit)
 
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)
 
void ResourceOwnerEnlargeDSMs (ResourceOwner owner)
 
void ResourceOwnerRememberDSM (ResourceOwner owner, dsm_segment *seg)
 
void ResourceOwnerForgetDSM (ResourceOwner owner, dsm_segment *seg)
 
void ResourceOwnerEnlargeJIT (ResourceOwner owner)
 
void ResourceOwnerRememberJIT (ResourceOwner owner, Datum handle)
 
void ResourceOwnerForgetJIT (ResourceOwner owner, Datum handle)
 

Variables

ResourceOwner CurrentResourceOwner = NULL
 
ResourceOwner CurTransactionResourceOwner = NULL
 
ResourceOwner TopTransactionResourceOwner = NULL
 
ResourceOwner AuxProcessResourceOwner = NULL
 
static ResourceReleaseCallbackItemResourceRelease_callbacks = NULL
 

Macro Definition Documentation

◆ BufferGetDatum

#define BufferGetDatum (   buffer)    Int32GetDatum(buffer)

◆ DatumGetBuffer

#define DatumGetBuffer (   datum)    ((Buffer) DatumGetInt32(datum))

Definition at line 45 of file resowner.c.

Referenced by ResourceOwnerReleaseInternal().

◆ DatumGetFile

#define DatumGetFile (   datum)    ((File) DatumGetInt32(datum))

Definition at line 43 of file resowner.c.

Referenced by ResourceOwnerReleaseInternal().

◆ FileGetDatum

#define FileGetDatum (   file)    Int32GetDatum(file)

◆ MAX_RESOWNER_LOCKS

#define MAX_RESOWNER_LOCKS   15

◆ RESARRAY_INIT_SIZE

#define RESARRAY_INIT_SIZE   16

Definition at line 77 of file resowner.c.

Referenced by ResourceArrayEnlarge().

◆ RESARRAY_IS_ARRAY

#define RESARRAY_IS_ARRAY (   resarr)    ((resarr)->capacity <= RESARRAY_MAX_ARRAY)

Definition at line 83 of file resowner.c.

Referenced by ResourceArrayAdd(), ResourceArrayGetAny(), and ResourceArrayRemove().

◆ RESARRAY_MAX_ARRAY

#define RESARRAY_MAX_ARRAY   64

Definition at line 82 of file resowner.c.

◆ RESARRAY_MAX_ITEMS

#define RESARRAY_MAX_ITEMS (   capacity)    ((capacity) <= RESARRAY_MAX_ARRAY ? (capacity) : (capacity)/4 * 3)

Definition at line 89 of file resowner.c.

Referenced by ResourceArrayEnlarge().

Typedef Documentation

◆ ResourceArray

typedef struct ResourceArray ResourceArray

◆ ResourceOwnerData

◆ ResourceReleaseCallbackItem

Function Documentation

◆ CreateAuxProcessResourceOwner()

void CreateAuxProcessResourceOwner ( void  )

Definition at line 834 of file resowner.c.

References Assert, AuxProcessResourceOwner, on_shmem_exit(), ReleaseAuxProcessResourcesCallback(), and ResourceOwnerCreate().

Referenced by AuxiliaryProcessMain(), and InitPostgres().

835 {
837  Assert(CurrentResourceOwner == NULL);
838  AuxProcessResourceOwner = ResourceOwnerCreate(NULL, "AuxiliaryProcess");
840 
841  /*
842  * Register a shmem-exit callback for cleanup of aux-process resource
843  * owner. (This needs to run after, e.g., ShutdownXLOG.)
844  */
846 
847 }
ResourceOwner CurrentResourceOwner
Definition: resowner.c:142
ResourceOwner AuxProcessResourceOwner
Definition: resowner.c:145
static void ReleaseAuxProcessResourcesCallback(int code, Datum arg)
Definition: resowner.c:877
void on_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:361
#define Assert(condition)
Definition: c.h:739
ResourceOwner ResourceOwnerCreate(ResourceOwner parent, const char *name)
Definition: resowner.c:422

◆ PrintDSMLeakWarning()

static void PrintDSMLeakWarning ( dsm_segment seg)
static

Definition at line 1309 of file resowner.c.

References dsm_segment_handle(), elog, and WARNING.

Referenced by ResourceOwnerReleaseInternal().

1310 {
1311  elog(WARNING, "dynamic shared memory leak: segment %u still referenced",
1312  dsm_segment_handle(seg));
1313 }
dsm_handle dsm_segment_handle(dsm_segment *seg)
Definition: dsm.c:966
#define WARNING
Definition: elog.h:40
#define elog(elevel,...)
Definition: elog.h:228

◆ PrintFileLeakWarning()

static void PrintFileLeakWarning ( File  file)
static

Definition at line 1264 of file resowner.c.

References elog, and WARNING.

Referenced by ResourceOwnerReleaseInternal().

1265 {
1266  elog(WARNING, "temporary file leak: File %d still referenced",
1267  file);
1268 }
#define WARNING
Definition: elog.h:40
#define elog(elevel,...)
Definition: elog.h:228

◆ PrintPlanCacheLeakWarning()

static void PrintPlanCacheLeakWarning ( CachedPlan plan)
static

Definition at line 1128 of file resowner.c.

References elog, and WARNING.

Referenced by ResourceOwnerReleaseInternal().

1129 {
1130  elog(WARNING, "plancache reference leak: plan %p not closed", plan);
1131 }
#define WARNING
Definition: elog.h:40
#define elog(elevel,...)
Definition: elog.h:228

◆ PrintRelCacheLeakWarning()

static void PrintRelCacheLeakWarning ( Relation  rel)
static

Definition at line 1083 of file resowner.c.

References elog, RelationGetRelationName, and WARNING.

Referenced by ResourceOwnerReleaseInternal().

1084 {
1085  elog(WARNING, "relcache reference leak: relation \"%s\" not closed",
1087 }
#define RelationGetRelationName(relation)
Definition: rel.h:456
#define WARNING
Definition: elog.h:40
#define elog(elevel,...)
Definition: elog.h:228

◆ PrintSnapshotLeakWarning()

static void PrintSnapshotLeakWarning ( Snapshot  snapshot)
static

Definition at line 1218 of file resowner.c.

References elog, and WARNING.

Referenced by ResourceOwnerReleaseInternal().

1219 {
1220  elog(WARNING, "Snapshot reference leak: Snapshot %p still referenced",
1221  snapshot);
1222 }
#define WARNING
Definition: elog.h:40
#define elog(elevel,...)
Definition: elog.h:228

◆ PrintTupleDescLeakWarning()

static void PrintTupleDescLeakWarning ( TupleDesc  tupdesc)
static

Definition at line 1172 of file resowner.c.

References elog, TupleDescData::tdtypeid, TupleDescData::tdtypmod, and WARNING.

Referenced by ResourceOwnerReleaseInternal().

1173 {
1174  elog(WARNING,
1175  "TupleDesc reference leak: TupleDesc %p (%u,%d) still referenced",
1176  tupdesc, tupdesc->tdtypeid, tupdesc->tdtypmod);
1177 }
int32 tdtypmod
Definition: tupdesc.h:83
#define WARNING
Definition: elog.h:40
Oid tdtypeid
Definition: tupdesc.h:82
#define elog(elevel,...)
Definition: elog.h:228

◆ RegisterResourceReleaseCallback()

void RegisterResourceReleaseCallback ( ResourceReleaseCallback  callback,
void *  arg 
)

Definition at line 796 of file resowner.c.

References arg, ResourceReleaseCallbackItem::arg, callback(), ResourceReleaseCallbackItem::callback, MemoryContextAlloc(), ResourceReleaseCallbackItem::next, ResourceRelease_callbacks, and TopMemoryContext.

Referenced by px_find_cipher(), and px_find_digest().

797 {
799 
800  item = (ResourceReleaseCallbackItem *)
803  item->callback = callback;
804  item->arg = arg;
807 }
static ResourceReleaseCallbackItem * ResourceRelease_callbacks
Definition: resowner.c:157
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:48
MemoryContext TopMemoryContext
Definition: mcxt.c:44
struct ResourceReleaseCallbackItem * next
Definition: resowner.c:152
ResourceReleaseCallback callback
Definition: resowner.c:153
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:796
void * arg

◆ ReleaseAuxProcessResources()

void ReleaseAuxProcessResources ( bool  isCommit)

Definition at line 855 of file resowner.c.

References RESOURCE_RELEASE_AFTER_LOCKS, RESOURCE_RELEASE_BEFORE_LOCKS, RESOURCE_RELEASE_LOCKS, and ResourceOwnerRelease().

Referenced by AutoVacLauncherMain(), BackgroundWriterMain(), CheckpointerMain(), InitPostgres(), ReleaseAuxProcessResourcesCallback(), and WalWriterMain().

856 {
857  /*
858  * At this writing, the only thing that could actually get released is
859  * buffer pins; but we may as well do the full release protocol.
860  */
863  isCommit, true);
866  isCommit, true);
869  isCommit, true);
870 }
ResourceOwner AuxProcessResourceOwner
Definition: resowner.c:145
void ResourceOwnerRelease(ResourceOwner owner, ResourceReleasePhase phase, bool isCommit, bool isTopLevel)
Definition: resowner.c:478

◆ ReleaseAuxProcessResourcesCallback()

static void ReleaseAuxProcessResourcesCallback ( int  code,
Datum  arg 
)
static

Definition at line 877 of file resowner.c.

References ReleaseAuxProcessResources().

Referenced by CreateAuxProcessResourceOwner().

878 {
879  bool isCommit = (code == 0);
880 
881  ReleaseAuxProcessResources(isCommit);
882 }
void ReleaseAuxProcessResources(bool isCommit)
Definition: resowner.c:855

◆ ResourceArrayAdd()

static void ResourceArrayAdd ( ResourceArray resarr,
Datum  value 
)
static

Definition at line 263 of file resowner.c.

References Assert, ResourceArray::capacity, DatumGetUInt32, hash_any(), idx(), ResourceArray::invalidval, ResourceArray::itemsarr, ResourceArray::lastidx, ResourceArray::maxitems, ResourceArray::nitems, RESARRAY_IS_ARRAY, and value.

Referenced by ResourceArrayEnlarge(), ResourceOwnerRememberBuffer(), ResourceOwnerRememberCatCacheListRef(), ResourceOwnerRememberCatCacheRef(), ResourceOwnerRememberDSM(), ResourceOwnerRememberFile(), ResourceOwnerRememberJIT(), ResourceOwnerRememberPlanCacheRef(), ResourceOwnerRememberRelationRef(), ResourceOwnerRememberSnapshot(), and ResourceOwnerRememberTupleDesc().

264 {
265  uint32 idx;
266 
267  Assert(value != resarr->invalidval);
268  Assert(resarr->nitems < resarr->maxitems);
269 
270  if (RESARRAY_IS_ARRAY(resarr))
271  {
272  /* Append to linear array. */
273  idx = resarr->nitems;
274  }
275  else
276  {
277  /* Insert into first free slot at or after hash location. */
278  uint32 mask = resarr->capacity - 1;
279 
280  idx = DatumGetUInt32(hash_any((void *) &value, sizeof(value))) & mask;
281  for (;;)
282  {
283  if (resarr->itemsarr[idx] == resarr->invalidval)
284  break;
285  idx = (idx + 1) & mask;
286  }
287  }
288  resarr->lastidx = idx;
289  resarr->itemsarr[idx] = value;
290  resarr->nitems++;
291 }
#define DatumGetUInt32(X)
Definition: postgres.h:486
Datum hash_any(const unsigned char *k, int keylen)
Definition: hashfn.c:148
uint32 lastidx
Definition: resowner.c:70
static struct @145 value
uint32 capacity
Definition: resowner.c:67
Datum idx(PG_FUNCTION_ARGS)
Definition: _int_op.c:263
Datum * itemsarr
Definition: resowner.c:65
Datum invalidval
Definition: resowner.c:66
unsigned int uint32
Definition: c.h:359
uint32 maxitems
Definition: resowner.c:69
#define Assert(condition)
Definition: c.h:739
#define RESARRAY_IS_ARRAY(resarr)
Definition: resowner.c:83
uint32 nitems
Definition: resowner.c:68

◆ ResourceArrayEnlarge()

static void ResourceArrayEnlarge ( ResourceArray resarr)
static

Definition at line 208 of file resowner.c.

References Assert, ResourceArray::capacity, i, ResourceArray::invalidval, ResourceArray::itemsarr, ResourceArray::maxitems, MemoryContextAlloc(), ResourceArray::nitems, pfree(), RESARRAY_INIT_SIZE, RESARRAY_MAX_ITEMS, ResourceArrayAdd(), and TopMemoryContext.

Referenced by ResourceOwnerEnlargeBuffers(), ResourceOwnerEnlargeCatCacheListRefs(), ResourceOwnerEnlargeCatCacheRefs(), ResourceOwnerEnlargeDSMs(), ResourceOwnerEnlargeFiles(), ResourceOwnerEnlargeJIT(), ResourceOwnerEnlargePlanCacheRefs(), ResourceOwnerEnlargeRelationRefs(), ResourceOwnerEnlargeSnapshots(), and ResourceOwnerEnlargeTupleDescs().

209 {
210  uint32 i,
211  oldcap,
212  newcap;
213  Datum *olditemsarr;
214  Datum *newitemsarr;
215 
216  if (resarr->nitems < resarr->maxitems)
217  return; /* no work needed */
218 
219  olditemsarr = resarr->itemsarr;
220  oldcap = resarr->capacity;
221 
222  /* Double the capacity of the array (capacity must stay a power of 2!) */
223  newcap = (oldcap > 0) ? oldcap * 2 : RESARRAY_INIT_SIZE;
224  newitemsarr = (Datum *) MemoryContextAlloc(TopMemoryContext,
225  newcap * sizeof(Datum));
226  for (i = 0; i < newcap; i++)
227  newitemsarr[i] = resarr->invalidval;
228 
229  /* We assume we can't fail below this point, so OK to scribble on resarr */
230  resarr->itemsarr = newitemsarr;
231  resarr->capacity = newcap;
232  resarr->maxitems = RESARRAY_MAX_ITEMS(newcap);
233  resarr->nitems = 0;
234 
235  if (olditemsarr != NULL)
236  {
237  /*
238  * Transfer any pre-existing entries into the new array; they don't
239  * necessarily go where they were before, so this simple logic is the
240  * best way. Note that if we were managing the set as a simple array,
241  * the entries after nitems are garbage, but that shouldn't matter
242  * because we won't get here unless nitems was equal to oldcap.
243  */
244  for (i = 0; i < oldcap; i++)
245  {
246  if (olditemsarr[i] != resarr->invalidval)
247  ResourceArrayAdd(resarr, olditemsarr[i]);
248  }
249 
250  /* And release old array. */
251  pfree(olditemsarr);
252  }
253 
254  Assert(resarr->nitems < resarr->maxitems);
255 }
#define RESARRAY_INIT_SIZE
Definition: resowner.c:77
uint32 capacity
Definition: resowner.c:67
#define RESARRAY_MAX_ITEMS(capacity)
Definition: resowner.c:89
void pfree(void *pointer)
Definition: mcxt.c:1056
Datum * itemsarr
Definition: resowner.c:65
Datum invalidval
Definition: resowner.c:66
unsigned int uint32
Definition: c.h:359
MemoryContext TopMemoryContext
Definition: mcxt.c:44
uint32 maxitems
Definition: resowner.c:69
uintptr_t Datum
Definition: postgres.h:367
#define Assert(condition)
Definition: c.h:739
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:796
int i
static void ResourceArrayAdd(ResourceArray *resarr, Datum value)
Definition: resowner.c:263
uint32 nitems
Definition: resowner.c:68

◆ ResourceArrayFree()

static void ResourceArrayFree ( ResourceArray resarr)
static

Definition at line 402 of file resowner.c.

References ResourceArray::itemsarr, and pfree().

Referenced by ResourceOwnerDelete().

403 {
404  if (resarr->itemsarr)
405  pfree(resarr->itemsarr);
406 }
void pfree(void *pointer)
Definition: mcxt.c:1056
Datum * itemsarr
Definition: resowner.c:65

◆ ResourceArrayGetAny()

static bool ResourceArrayGetAny ( ResourceArray resarr,
Datum value 
)
static

Definition at line 370 of file resowner.c.

References ResourceArray::capacity, ResourceArray::invalidval, ResourceArray::itemsarr, ResourceArray::lastidx, ResourceArray::nitems, and RESARRAY_IS_ARRAY.

Referenced by ResourceOwnerReleaseInternal().

371 {
372  if (resarr->nitems == 0)
373  return false;
374 
375  if (RESARRAY_IS_ARRAY(resarr))
376  {
377  /* Linear array: just return the first element. */
378  resarr->lastidx = 0;
379  }
380  else
381  {
382  /* Hash: search forward from wherever we were last. */
383  uint32 mask = resarr->capacity - 1;
384 
385  for (;;)
386  {
387  resarr->lastidx &= mask;
388  if (resarr->itemsarr[resarr->lastidx] != resarr->invalidval)
389  break;
390  resarr->lastidx++;
391  }
392  }
393 
394  *value = resarr->itemsarr[resarr->lastidx];
395  return true;
396 }
uint32 lastidx
Definition: resowner.c:70
static struct @145 value
uint32 capacity
Definition: resowner.c:67
Datum * itemsarr
Definition: resowner.c:65
Datum invalidval
Definition: resowner.c:66
unsigned int uint32
Definition: c.h:359
#define RESARRAY_IS_ARRAY(resarr)
Definition: resowner.c:83
uint32 nitems
Definition: resowner.c:68

◆ ResourceArrayInit()

static void ResourceArrayInit ( ResourceArray resarr,
Datum  invalidval 
)
static

Definition at line 189 of file resowner.c.

References Assert, ResourceArray::capacity, ResourceArray::invalidval, ResourceArray::itemsarr, ResourceArray::maxitems, and ResourceArray::nitems.

Referenced by ResourceOwnerCreate().

190 {
191  /* Assert it's empty */
192  Assert(resarr->itemsarr == NULL);
193  Assert(resarr->capacity == 0);
194  Assert(resarr->nitems == 0);
195  Assert(resarr->maxitems == 0);
196  /* Remember the appropriate "invalid" value */
197  resarr->invalidval = invalidval;
198  /* We don't allocate any storage until needed */
199 }
uint32 capacity
Definition: resowner.c:67
Datum * itemsarr
Definition: resowner.c:65
Datum invalidval
Definition: resowner.c:66
uint32 maxitems
Definition: resowner.c:69
#define Assert(condition)
Definition: c.h:739
uint32 nitems
Definition: resowner.c:68

◆ ResourceArrayRemove()

static bool ResourceArrayRemove ( ResourceArray resarr,
Datum  value 
)
static

Definition at line 301 of file resowner.c.

References Assert, ResourceArray::capacity, DatumGetUInt32, hash_any(), i, idx(), ResourceArray::invalidval, ResourceArray::itemsarr, ResourceArray::lastidx, ResourceArray::nitems, and RESARRAY_IS_ARRAY.

Referenced by ResourceOwnerForgetBuffer(), ResourceOwnerForgetCatCacheListRef(), ResourceOwnerForgetCatCacheRef(), ResourceOwnerForgetDSM(), ResourceOwnerForgetFile(), ResourceOwnerForgetJIT(), ResourceOwnerForgetPlanCacheRef(), ResourceOwnerForgetRelationRef(), ResourceOwnerForgetSnapshot(), and ResourceOwnerForgetTupleDesc().

302 {
303  uint32 i,
304  idx,
305  lastidx = resarr->lastidx;
306 
307  Assert(value != resarr->invalidval);
308 
309  /* Search through all items, but try lastidx first. */
310  if (RESARRAY_IS_ARRAY(resarr))
311  {
312  if (lastidx < resarr->nitems &&
313  resarr->itemsarr[lastidx] == value)
314  {
315  resarr->itemsarr[lastidx] = resarr->itemsarr[resarr->nitems - 1];
316  resarr->nitems--;
317  /* Update lastidx to make reverse-order removals fast. */
318  resarr->lastidx = resarr->nitems - 1;
319  return true;
320  }
321  for (i = 0; i < resarr->nitems; i++)
322  {
323  if (resarr->itemsarr[i] == value)
324  {
325  resarr->itemsarr[i] = resarr->itemsarr[resarr->nitems - 1];
326  resarr->nitems--;
327  /* Update lastidx to make reverse-order removals fast. */
328  resarr->lastidx = resarr->nitems - 1;
329  return true;
330  }
331  }
332  }
333  else
334  {
335  uint32 mask = resarr->capacity - 1;
336 
337  if (lastidx < resarr->capacity &&
338  resarr->itemsarr[lastidx] == value)
339  {
340  resarr->itemsarr[lastidx] = resarr->invalidval;
341  resarr->nitems--;
342  return true;
343  }
344  idx = DatumGetUInt32(hash_any((void *) &value, sizeof(value))) & mask;
345  for (i = 0; i < resarr->capacity; i++)
346  {
347  if (resarr->itemsarr[idx] == value)
348  {
349  resarr->itemsarr[idx] = resarr->invalidval;
350  resarr->nitems--;
351  return true;
352  }
353  idx = (idx + 1) & mask;
354  }
355  }
356 
357  return false;
358 }
#define DatumGetUInt32(X)
Definition: postgres.h:486
Datum hash_any(const unsigned char *k, int keylen)
Definition: hashfn.c:148
uint32 lastidx
Definition: resowner.c:70
static struct @145 value
uint32 capacity
Definition: resowner.c:67
Datum idx(PG_FUNCTION_ARGS)
Definition: _int_op.c:263
Datum * itemsarr
Definition: resowner.c:65
Datum invalidval
Definition: resowner.c:66
unsigned int uint32
Definition: c.h:359
#define Assert(condition)
Definition: c.h:739
int i
#define RESARRAY_IS_ARRAY(resarr)
Definition: resowner.c:83
uint32 nitems
Definition: resowner.c:68

◆ ResourceOwnerCreate()

ResourceOwner ResourceOwnerCreate ( ResourceOwner  parent,
const char *  name 
)

Definition at line 422 of file resowner.c.

References ResourceOwnerData::bufferarr, BufferGetDatum, ResourceOwnerData::catlistrefarr, ResourceOwnerData::catrefarr, ResourceOwnerData::dsmarr, ResourceOwnerData::filearr, FileGetDatum, ResourceOwnerData::firstchild, InvalidBuffer, ResourceOwnerData::jitarr, MemoryContextAllocZero(), ResourceOwnerData::name, name, ResourceOwnerData::nextchild, ResourceOwnerData::parent, ResourceOwnerData::planrefarr, PointerGetDatum, ResourceOwnerData::relrefarr, ResourceArrayInit(), ResourceOwnerData::snapshotarr, TopMemoryContext, and ResourceOwnerData::tupdescarr.

Referenced by AtStart_ResourceOwner(), AtSubStart_ResourceOwner(), CreateAuxProcessResourceOwner(), and CreatePortal().

423 {
424  ResourceOwner owner;
425 
427  sizeof(ResourceOwnerData));
428  owner->name = name;
429 
430  if (parent)
431  {
432  owner->parent = parent;
433  owner->nextchild = parent->firstchild;
434  parent->firstchild = owner;
435  }
436 
438  ResourceArrayInit(&(owner->catrefarr), PointerGetDatum(NULL));
440  ResourceArrayInit(&(owner->relrefarr), PointerGetDatum(NULL));
441  ResourceArrayInit(&(owner->planrefarr), PointerGetDatum(NULL));
442  ResourceArrayInit(&(owner->tupdescarr), PointerGetDatum(NULL));
444  ResourceArrayInit(&(owner->filearr), FileGetDatum(-1));
445  ResourceArrayInit(&(owner->dsmarr), PointerGetDatum(NULL));
446  ResourceArrayInit(&(owner->jitarr), PointerGetDatum(NULL));
447 
448  return owner;
449 }
ResourceArray relrefarr
Definition: resowner.c:124
ResourceArray catrefarr
Definition: resowner.c:122
#define PointerGetDatum(X)
Definition: postgres.h:556
#define InvalidBuffer
Definition: buf.h:25
ResourceArray bufferarr
Definition: resowner.c:121
ResourceArray snapshotarr
Definition: resowner.c:127
struct ResourceOwnerData * ResourceOwner
Definition: resowner.h:27
const char * name
Definition: resowner.c:118
ResourceArray planrefarr
Definition: resowner.c:125
ResourceArray tupdescarr
Definition: resowner.c:126
static void ResourceArrayInit(ResourceArray *resarr, Datum invalidval)
Definition: resowner.c:189
MemoryContext TopMemoryContext
Definition: mcxt.c:44
ResourceOwner firstchild
Definition: resowner.c:116
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition: mcxt.c:839
#define BufferGetDatum(buffer)
Definition: resowner.c:44
#define FileGetDatum(file)
Definition: resowner.c:42
ResourceArray jitarr
Definition: resowner.c:130
ResourceOwner parent
Definition: resowner.c:115
const char * name
Definition: encode.c:521
ResourceArray catlistrefarr
Definition: resowner.c:123
ResourceArray dsmarr
Definition: resowner.c:129
ResourceOwner nextchild
Definition: resowner.c:117
ResourceArray filearr
Definition: resowner.c:128

◆ ResourceOwnerDelete()

void ResourceOwnerDelete ( ResourceOwner  owner)

Definition at line 688 of file resowner.c.

References Assert, ResourceOwnerData::bufferarr, ResourceOwnerData::catlistrefarr, ResourceOwnerData::catrefarr, ResourceOwnerData::dsmarr, ResourceOwnerData::filearr, ResourceOwnerData::firstchild, ResourceOwnerData::jitarr, MAX_RESOWNER_LOCKS, ResourceArray::nitems, ResourceOwnerData::nlocks, pfree(), ResourceOwnerData::planrefarr, ResourceOwnerData::relrefarr, ResourceArrayFree(), ResourceOwnerDelete(), ResourceOwnerNewParent(), ResourceOwnerData::snapshotarr, and ResourceOwnerData::tupdescarr.

Referenced by CleanupSubTransaction(), CleanupTransaction(), CommitSubTransaction(), CommitTransaction(), PortalDrop(), PrepareTransaction(), and ResourceOwnerDelete().

689 {
690  /* We had better not be deleting CurrentResourceOwner ... */
691  Assert(owner != CurrentResourceOwner);
692 
693  /* And it better not own any resources, either */
694  Assert(owner->bufferarr.nitems == 0);
695  Assert(owner->catrefarr.nitems == 0);
696  Assert(owner->catlistrefarr.nitems == 0);
697  Assert(owner->relrefarr.nitems == 0);
698  Assert(owner->planrefarr.nitems == 0);
699  Assert(owner->tupdescarr.nitems == 0);
700  Assert(owner->snapshotarr.nitems == 0);
701  Assert(owner->filearr.nitems == 0);
702  Assert(owner->dsmarr.nitems == 0);
703  Assert(owner->jitarr.nitems == 0);
704  Assert(owner->nlocks == 0 || owner->nlocks == MAX_RESOWNER_LOCKS + 1);
705 
706  /*
707  * Delete children. The recursive call will delink the child from me, so
708  * just iterate as long as there is a child.
709  */
710  while (owner->firstchild != NULL)
712 
713  /*
714  * We delink the owner from its parent before deleting it, so that if
715  * there's an error we won't have deleted/busted owners still attached to
716  * the owner tree. Better a leak than a crash.
717  */
718  ResourceOwnerNewParent(owner, NULL);
719 
720  /* And free the object. */
721  ResourceArrayFree(&(owner->bufferarr));
722  ResourceArrayFree(&(owner->catrefarr));
723  ResourceArrayFree(&(owner->catlistrefarr));
724  ResourceArrayFree(&(owner->relrefarr));
725  ResourceArrayFree(&(owner->planrefarr));
726  ResourceArrayFree(&(owner->tupdescarr));
727  ResourceArrayFree(&(owner->snapshotarr));
728  ResourceArrayFree(&(owner->filearr));
729  ResourceArrayFree(&(owner->dsmarr));
730  ResourceArrayFree(&(owner->jitarr));
731 
732  pfree(owner);
733 }
ResourceArray relrefarr
Definition: resowner.c:124
ResourceArray catrefarr
Definition: resowner.c:122
ResourceOwner CurrentResourceOwner
Definition: resowner.c:142
void ResourceOwnerDelete(ResourceOwner owner)
Definition: resowner.c:688
ResourceArray bufferarr
Definition: resowner.c:121
ResourceArray snapshotarr
Definition: resowner.c:127
#define MAX_RESOWNER_LOCKS
Definition: resowner.c:108
void pfree(void *pointer)
Definition: mcxt.c:1056
ResourceArray planrefarr
Definition: resowner.c:125
static void ResourceArrayFree(ResourceArray *resarr)
Definition: resowner.c:402
ResourceArray tupdescarr
Definition: resowner.c:126
ResourceOwner firstchild
Definition: resowner.c:116
#define Assert(condition)
Definition: c.h:739
ResourceArray jitarr
Definition: resowner.c:130
void ResourceOwnerNewParent(ResourceOwner owner, ResourceOwner newparent)
Definition: resowner.c:748
ResourceArray catlistrefarr
Definition: resowner.c:123
ResourceArray dsmarr
Definition: resowner.c:129
uint32 nitems
Definition: resowner.c:68
ResourceArray filearr
Definition: resowner.c:128

◆ ResourceOwnerEnlargeBuffers()

void ResourceOwnerEnlargeBuffers ( ResourceOwner  owner)

Definition at line 893 of file resowner.c.

References Assert, ResourceOwnerData::bufferarr, and ResourceArrayEnlarge().

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

894 {
895  /* We used to allow pinning buffers without a resowner, but no more */
896  Assert(owner != NULL);
897  ResourceArrayEnlarge(&(owner->bufferarr));
898 }
static void ResourceArrayEnlarge(ResourceArray *resarr)
Definition: resowner.c:208
ResourceArray bufferarr
Definition: resowner.c:121
#define Assert(condition)
Definition: c.h:739

◆ ResourceOwnerEnlargeCatCacheListRefs()

void ResourceOwnerEnlargeCatCacheListRefs ( ResourceOwner  owner)

Definition at line 1017 of file resowner.c.

References ResourceOwnerData::catlistrefarr, and ResourceArrayEnlarge().

Referenced by SearchCatCacheList().

1018 {
1020 }
static void ResourceArrayEnlarge(ResourceArray *resarr)
Definition: resowner.c:208
ResourceArray catlistrefarr
Definition: resowner.c:123

◆ ResourceOwnerEnlargeCatCacheRefs()

void ResourceOwnerEnlargeCatCacheRefs ( ResourceOwner  owner)

Definition at line 982 of file resowner.c.

References ResourceOwnerData::catrefarr, and ResourceArrayEnlarge().

Referenced by SearchCatCacheInternal(), and SearchCatCacheMiss().

983 {
984  ResourceArrayEnlarge(&(owner->catrefarr));
985 }
static void ResourceArrayEnlarge(ResourceArray *resarr)
Definition: resowner.c:208
ResourceArray catrefarr
Definition: resowner.c:122

◆ ResourceOwnerEnlargeDSMs()

void ResourceOwnerEnlargeDSMs ( ResourceOwner  owner)

Definition at line 1278 of file resowner.c.

References ResourceOwnerData::dsmarr, and ResourceArrayEnlarge().

Referenced by dsm_create_descriptor(), and dsm_unpin_mapping().

1279 {
1280  ResourceArrayEnlarge(&(owner->dsmarr));
1281 }
static void ResourceArrayEnlarge(ResourceArray *resarr)
Definition: resowner.c:208
ResourceArray dsmarr
Definition: resowner.c:129

◆ ResourceOwnerEnlargeFiles()

void ResourceOwnerEnlargeFiles ( ResourceOwner  owner)

Definition at line 1233 of file resowner.c.

References ResourceOwnerData::filearr, and ResourceArrayEnlarge().

Referenced by OpenTemporaryFile(), PathNameCreateTemporaryFile(), and PathNameOpenTemporaryFile().

1234 {
1235  ResourceArrayEnlarge(&(owner->filearr));
1236 }
static void ResourceArrayEnlarge(ResourceArray *resarr)
Definition: resowner.c:208
ResourceArray filearr
Definition: resowner.c:128

◆ ResourceOwnerEnlargeJIT()

void ResourceOwnerEnlargeJIT ( ResourceOwner  owner)

Definition at line 1323 of file resowner.c.

References ResourceOwnerData::jitarr, and ResourceArrayEnlarge().

Referenced by llvm_create_context().

1324 {
1325  ResourceArrayEnlarge(&(owner->jitarr));
1326 }
static void ResourceArrayEnlarge(ResourceArray *resarr)
Definition: resowner.c:208
ResourceArray jitarr
Definition: resowner.c:130

◆ ResourceOwnerEnlargePlanCacheRefs()

void ResourceOwnerEnlargePlanCacheRefs ( ResourceOwner  owner)

Definition at line 1097 of file resowner.c.

References ResourceOwnerData::planrefarr, and ResourceArrayEnlarge().

Referenced by GetCachedPlan().

1098 {
1099  ResourceArrayEnlarge(&(owner->planrefarr));
1100 }
static void ResourceArrayEnlarge(ResourceArray *resarr)
Definition: resowner.c:208
ResourceArray planrefarr
Definition: resowner.c:125

◆ ResourceOwnerEnlargeRelationRefs()

void ResourceOwnerEnlargeRelationRefs ( ResourceOwner  owner)

Definition at line 1052 of file resowner.c.

References ResourceOwnerData::relrefarr, and ResourceArrayEnlarge().

Referenced by RelationIncrementReferenceCount().

1053 {
1054  ResourceArrayEnlarge(&(owner->relrefarr));
1055 }
static void ResourceArrayEnlarge(ResourceArray *resarr)
Definition: resowner.c:208
ResourceArray relrefarr
Definition: resowner.c:124

◆ ResourceOwnerEnlargeSnapshots()

void ResourceOwnerEnlargeSnapshots ( ResourceOwner  owner)

Definition at line 1187 of file resowner.c.

References ResourceArrayEnlarge(), and ResourceOwnerData::snapshotarr.

Referenced by RegisterSnapshotOnOwner().

1188 {
1189  ResourceArrayEnlarge(&(owner->snapshotarr));
1190 }
static void ResourceArrayEnlarge(ResourceArray *resarr)
Definition: resowner.c:208
ResourceArray snapshotarr
Definition: resowner.c:127

◆ ResourceOwnerEnlargeTupleDescs()

void ResourceOwnerEnlargeTupleDescs ( ResourceOwner  owner)

Definition at line 1141 of file resowner.c.

References ResourceArrayEnlarge(), and ResourceOwnerData::tupdescarr.

Referenced by IncrTupleDescRefCount().

1142 {
1143  ResourceArrayEnlarge(&(owner->tupdescarr));
1144 }
static void ResourceArrayEnlarge(ResourceArray *resarr)
Definition: resowner.c:208
ResourceArray tupdescarr
Definition: resowner.c:126

◆ ResourceOwnerForgetBuffer()

void ResourceOwnerForgetBuffer ( ResourceOwner  owner,
Buffer  buffer 
)

Definition at line 915 of file resowner.c.

References ResourceOwnerData::bufferarr, BufferGetDatum, elog, ERROR, ResourceOwnerData::name, and ResourceArrayRemove().

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

916 {
917  if (!ResourceArrayRemove(&(owner->bufferarr), BufferGetDatum(buffer)))
918  elog(ERROR, "buffer %d is not owned by resource owner %s",
919  buffer, owner->name);
920 }
ResourceArray bufferarr
Definition: resowner.c:121
const char * name
Definition: resowner.c:118
#define ERROR
Definition: elog.h:43
#define BufferGetDatum(buffer)
Definition: resowner.c:44
static bool ResourceArrayRemove(ResourceArray *resarr, Datum value)
Definition: resowner.c:301
#define elog(elevel,...)
Definition: elog.h:228

◆ ResourceOwnerForgetCatCacheListRef()

void ResourceOwnerForgetCatCacheListRef ( ResourceOwner  owner,
CatCList list 
)

Definition at line 1037 of file resowner.c.

References ResourceOwnerData::catlistrefarr, elog, ERROR, ResourceOwnerData::name, PointerGetDatum, and ResourceArrayRemove().

Referenced by ReleaseCatCacheList().

1038 {
1039  if (!ResourceArrayRemove(&(owner->catlistrefarr), PointerGetDatum(list)))
1040  elog(ERROR, "catcache list reference %p is not owned by resource owner %s",
1041  list, owner->name);
1042 }
#define PointerGetDatum(X)
Definition: postgres.h:556
const char * name
Definition: resowner.c:118
#define ERROR
Definition: elog.h:43
static bool ResourceArrayRemove(ResourceArray *resarr, Datum value)
Definition: resowner.c:301
#define elog(elevel,...)
Definition: elog.h:228
ResourceArray catlistrefarr
Definition: resowner.c:123

◆ ResourceOwnerForgetCatCacheRef()

void ResourceOwnerForgetCatCacheRef ( ResourceOwner  owner,
HeapTuple  tuple 
)

Definition at line 1002 of file resowner.c.

References ResourceOwnerData::catrefarr, elog, ERROR, ResourceOwnerData::name, PointerGetDatum, and ResourceArrayRemove().

Referenced by ReleaseCatCache().

1003 {
1004  if (!ResourceArrayRemove(&(owner->catrefarr), PointerGetDatum(tuple)))
1005  elog(ERROR, "catcache reference %p is not owned by resource owner %s",
1006  tuple, owner->name);
1007 }
ResourceArray catrefarr
Definition: resowner.c:122
#define PointerGetDatum(X)
Definition: postgres.h:556
const char * name
Definition: resowner.c:118
#define ERROR
Definition: elog.h:43
static bool ResourceArrayRemove(ResourceArray *resarr, Datum value)
Definition: resowner.c:301
#define elog(elevel,...)
Definition: elog.h:228

◆ ResourceOwnerForgetDSM()

void ResourceOwnerForgetDSM ( ResourceOwner  owner,
dsm_segment seg 
)

Definition at line 1298 of file resowner.c.

References dsm_segment_handle(), ResourceOwnerData::dsmarr, elog, ERROR, ResourceOwnerData::name, PointerGetDatum, and ResourceArrayRemove().

Referenced by dsm_create(), dsm_detach(), and dsm_pin_mapping().

1299 {
1300  if (!ResourceArrayRemove(&(owner->dsmarr), PointerGetDatum(seg)))
1301  elog(ERROR, "dynamic shared memory segment %u is not owned by resource owner %s",
1302  dsm_segment_handle(seg), owner->name);
1303 }
#define PointerGetDatum(X)
Definition: postgres.h:556
dsm_handle dsm_segment_handle(dsm_segment *seg)
Definition: dsm.c:966
const char * name
Definition: resowner.c:118
#define ERROR
Definition: elog.h:43
static bool ResourceArrayRemove(ResourceArray *resarr, Datum value)
Definition: resowner.c:301
#define elog(elevel,...)
Definition: elog.h:228
ResourceArray dsmarr
Definition: resowner.c:129

◆ ResourceOwnerForgetFile()

void ResourceOwnerForgetFile ( ResourceOwner  owner,
File  file 
)

Definition at line 1253 of file resowner.c.

References elog, ERROR, ResourceOwnerData::filearr, FileGetDatum, ResourceOwnerData::name, and ResourceArrayRemove().

Referenced by FileClose().

1254 {
1255  if (!ResourceArrayRemove(&(owner->filearr), FileGetDatum(file)))
1256  elog(ERROR, "temporary file %d is not owned by resource owner %s",
1257  file, owner->name);
1258 }
const char * name
Definition: resowner.c:118
#define ERROR
Definition: elog.h:43
#define FileGetDatum(file)
Definition: resowner.c:42
static bool ResourceArrayRemove(ResourceArray *resarr, Datum value)
Definition: resowner.c:301
#define elog(elevel,...)
Definition: elog.h:228
ResourceArray filearr
Definition: resowner.c:128

◆ ResourceOwnerForgetJIT()

void ResourceOwnerForgetJIT ( ResourceOwner  owner,
Datum  handle 
)

Definition at line 1343 of file resowner.c.

References DatumGetPointer, elog, ERROR, ResourceOwnerData::jitarr, ResourceOwnerData::name, and ResourceArrayRemove().

Referenced by jit_release_context().

1344 {
1345  if (!ResourceArrayRemove(&(owner->jitarr), handle))
1346  elog(ERROR, "JIT context %p is not owned by resource owner %s",
1347  DatumGetPointer(handle), owner->name);
1348 }
const char * name
Definition: resowner.c:118
#define ERROR
Definition: elog.h:43
ResourceArray jitarr
Definition: resowner.c:130
static bool ResourceArrayRemove(ResourceArray *resarr, Datum value)
Definition: resowner.c:301
#define DatumGetPointer(X)
Definition: postgres.h:549
#define elog(elevel,...)
Definition: elog.h:228

◆ ResourceOwnerForgetLock()

void ResourceOwnerForgetLock ( ResourceOwner  owner,
LOCALLOCK locallock 
)

Definition at line 953 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().

954 {
955  int i;
956 
957  if (owner->nlocks > MAX_RESOWNER_LOCKS)
958  return; /* we have overflowed */
959 
960  Assert(owner->nlocks > 0);
961  for (i = owner->nlocks - 1; i >= 0; i--)
962  {
963  if (locallock == owner->locks[i])
964  {
965  owner->locks[i] = owner->locks[owner->nlocks - 1];
966  owner->nlocks--;
967  return;
968  }
969  }
970  elog(ERROR, "lock reference %p is not owned by resource owner %s",
971  locallock, owner->name);
972 }
#define MAX_RESOWNER_LOCKS
Definition: resowner.c:108
const char * name
Definition: resowner.c:118
#define ERROR
Definition: elog.h:43
#define Assert(condition)
Definition: c.h:739
LOCALLOCK * locks[MAX_RESOWNER_LOCKS]
Definition: resowner.c:134
#define elog(elevel,...)
Definition: elog.h:228
int i

◆ ResourceOwnerForgetPlanCacheRef()

void ResourceOwnerForgetPlanCacheRef ( ResourceOwner  owner,
CachedPlan plan 
)

Definition at line 1117 of file resowner.c.

References elog, ERROR, ResourceOwnerData::name, ResourceOwnerData::planrefarr, PointerGetDatum, and ResourceArrayRemove().

Referenced by ReleaseCachedPlan().

1118 {
1119  if (!ResourceArrayRemove(&(owner->planrefarr), PointerGetDatum(plan)))
1120  elog(ERROR, "plancache reference %p is not owned by resource owner %s",
1121  plan, owner->name);
1122 }
#define PointerGetDatum(X)
Definition: postgres.h:556
const char * name
Definition: resowner.c:118
#define ERROR
Definition: elog.h:43
ResourceArray planrefarr
Definition: resowner.c:125
static bool ResourceArrayRemove(ResourceArray *resarr, Datum value)
Definition: resowner.c:301
#define elog(elevel,...)
Definition: elog.h:228

◆ ResourceOwnerForgetRelationRef()

void ResourceOwnerForgetRelationRef ( ResourceOwner  owner,
Relation  rel 
)

Definition at line 1072 of file resowner.c.

References elog, ERROR, ResourceOwnerData::name, PointerGetDatum, RelationGetRelationName, ResourceOwnerData::relrefarr, and ResourceArrayRemove().

Referenced by RelationDecrementReferenceCount().

1073 {
1074  if (!ResourceArrayRemove(&(owner->relrefarr), PointerGetDatum(rel)))
1075  elog(ERROR, "relcache reference %s is not owned by resource owner %s",
1076  RelationGetRelationName(rel), owner->name);
1077 }
ResourceArray relrefarr
Definition: resowner.c:124
#define PointerGetDatum(X)
Definition: postgres.h:556
const char * name
Definition: resowner.c:118
#define ERROR
Definition: elog.h:43
#define RelationGetRelationName(relation)
Definition: rel.h:456
static bool ResourceArrayRemove(ResourceArray *resarr, Datum value)
Definition: resowner.c:301
#define elog(elevel,...)
Definition: elog.h:228

◆ ResourceOwnerForgetSnapshot()

void ResourceOwnerForgetSnapshot ( ResourceOwner  owner,
Snapshot  snapshot 
)

Definition at line 1207 of file resowner.c.

References elog, ERROR, ResourceOwnerData::name, PointerGetDatum, ResourceArrayRemove(), and ResourceOwnerData::snapshotarr.

Referenced by UnregisterSnapshotFromOwner().

1208 {
1209  if (!ResourceArrayRemove(&(owner->snapshotarr), PointerGetDatum(snapshot)))
1210  elog(ERROR, "snapshot reference %p is not owned by resource owner %s",
1211  snapshot, owner->name);
1212 }
#define PointerGetDatum(X)
Definition: postgres.h:556
ResourceArray snapshotarr
Definition: resowner.c:127
const char * name
Definition: resowner.c:118
#define ERROR
Definition: elog.h:43
static bool ResourceArrayRemove(ResourceArray *resarr, Datum value)
Definition: resowner.c:301
#define elog(elevel,...)
Definition: elog.h:228

◆ ResourceOwnerForgetTupleDesc()

void ResourceOwnerForgetTupleDesc ( ResourceOwner  owner,
TupleDesc  tupdesc 
)

Definition at line 1161 of file resowner.c.

References elog, ERROR, ResourceOwnerData::name, PointerGetDatum, ResourceArrayRemove(), and ResourceOwnerData::tupdescarr.

Referenced by DecrTupleDescRefCount().

1162 {
1163  if (!ResourceArrayRemove(&(owner->tupdescarr), PointerGetDatum(tupdesc)))
1164  elog(ERROR, "tupdesc reference %p is not owned by resource owner %s",
1165  tupdesc, owner->name);
1166 }
#define PointerGetDatum(X)
Definition: postgres.h:556
const char * name
Definition: resowner.c:118
#define ERROR
Definition: elog.h:43
ResourceArray tupdescarr
Definition: resowner.c:126
static bool ResourceArrayRemove(ResourceArray *resarr, Datum value)
Definition: resowner.c:301
#define elog(elevel,...)
Definition: elog.h:228

◆ ResourceOwnerGetParent()

ResourceOwner ResourceOwnerGetParent ( ResourceOwner  owner)

Definition at line 739 of file resowner.c.

References ResourceOwnerData::parent.

Referenced by LockReassignCurrentOwner().

740 {
741  return owner->parent;
742 }
ResourceOwner parent
Definition: resowner.c:115

◆ ResourceOwnerNewParent()

void ResourceOwnerNewParent ( ResourceOwner  owner,
ResourceOwner  newparent 
)

Definition at line 748 of file resowner.c.

References Assert, ResourceOwnerData::firstchild, ResourceOwnerData::nextchild, and ResourceOwnerData::parent.

Referenced by AtSubAbort_Portals(), AtSubCommit_Portals(), and ResourceOwnerDelete().

750 {
751  ResourceOwner oldparent = owner->parent;
752 
753  if (oldparent)
754  {
755  if (owner == oldparent->firstchild)
756  oldparent->firstchild = owner->nextchild;
757  else
758  {
759  ResourceOwner child;
760 
761  for (child = oldparent->firstchild; child; child = child->nextchild)
762  {
763  if (owner == child->nextchild)
764  {
765  child->nextchild = owner->nextchild;
766  break;
767  }
768  }
769  }
770  }
771 
772  if (newparent)
773  {
774  Assert(owner != newparent);
775  owner->parent = newparent;
776  owner->nextchild = newparent->firstchild;
777  newparent->firstchild = owner;
778  }
779  else
780  {
781  owner->parent = NULL;
782  owner->nextchild = NULL;
783  }
784 }
ResourceOwner firstchild
Definition: resowner.c:116
#define Assert(condition)
Definition: c.h:739
ResourceOwner parent
Definition: resowner.c:115
ResourceOwner nextchild
Definition: resowner.c:117

◆ ResourceOwnerRelease()

void ResourceOwnerRelease ( ResourceOwner  owner,
ResourceReleasePhase  phase,
bool  isCommit,
bool  isTopLevel 
)

Definition at line 478 of file resowner.c.

References ResourceOwnerReleaseInternal().

Referenced by AbortSubTransaction(), AbortTransaction(), CommitSubTransaction(), CommitTransaction(), PortalDrop(), PrepareTransaction(), and ReleaseAuxProcessResources().

482 {
483  /* There's not currently any setup needed before recursing */
484  ResourceOwnerReleaseInternal(owner, phase, isCommit, isTopLevel);
485 }
static void ResourceOwnerReleaseInternal(ResourceOwner owner, ResourceReleasePhase phase, bool isCommit, bool isTopLevel)
Definition: resowner.c:488

◆ ResourceOwnerReleaseInternal()

static void ResourceOwnerReleaseInternal ( ResourceOwner  owner,
ResourceReleasePhase  phase,
bool  isCommit,
bool  isTopLevel 
)
static

Definition at line 488 of file resowner.c.

References ResourceReleaseCallbackItem::arg, Assert, ResourceOwnerData::bufferarr, ResourceReleaseCallbackItem::callback, ResourceOwnerData::catlistrefarr, ResourceOwnerData::catrefarr, CurrentResourceOwner, DatumGetBuffer, DatumGetFile, DatumGetPointer, DecrTupleDescRefCount(), dsm_detach(), ResourceOwnerData::dsmarr, ResourceOwnerData::filearr, FileClose(), ResourceOwnerData::firstchild, jit_release_context(), ResourceOwnerData::jitarr, LockReassignCurrentOwner(), LockReleaseCurrentOwner(), ResourceOwnerData::locks, MAX_RESOWNER_LOCKS, ResourceReleaseCallbackItem::next, ResourceOwnerData::nextchild, ResourceOwnerData::nlocks, ResourceOwnerData::parent, ResourceOwnerData::planrefarr, PointerGetDatum, PrintBufferLeakWarning(), PrintCatCacheLeakWarning(), PrintCatCacheListLeakWarning(), PrintDSMLeakWarning(), PrintFileLeakWarning(), PrintPlanCacheLeakWarning(), PrintRelCacheLeakWarning(), PrintSnapshotLeakWarning(), PrintTupleDescLeakWarning(), ProcReleaseLocks(), RelationClose(), ReleaseBuffer(), ReleaseCachedPlan(), ReleaseCatCache(), ReleaseCatCacheList(), ReleasePredicateLocks(), ResourceOwnerData::relrefarr, RESOURCE_RELEASE_AFTER_LOCKS, RESOURCE_RELEASE_BEFORE_LOCKS, RESOURCE_RELEASE_LOCKS, ResourceArrayGetAny(), ResourceOwnerData::snapshotarr, ResourceOwnerData::tupdescarr, and UnregisterSnapshot().

Referenced by ResourceOwnerRelease().

492 {
493  ResourceOwner child;
494  ResourceOwner save;
496  Datum foundres;
497 
498  /* Recurse to handle descendants */
499  for (child = owner->firstchild; child != NULL; child = child->nextchild)
500  ResourceOwnerReleaseInternal(child, phase, isCommit, isTopLevel);
501 
502  /*
503  * Make CurrentResourceOwner point to me, so that ReleaseBuffer etc don't
504  * get confused.
505  */
506  save = CurrentResourceOwner;
507  CurrentResourceOwner = owner;
508 
509  if (phase == RESOURCE_RELEASE_BEFORE_LOCKS)
510  {
511  /*
512  * Release buffer pins. Note that ReleaseBuffer will remove the
513  * buffer entry from our array, so we just have to iterate till there
514  * are none.
515  *
516  * During a commit, there shouldn't be any remaining pins --- that
517  * would indicate failure to clean up the executor correctly --- so
518  * issue warnings. In the abort case, just clean up quietly.
519  */
520  while (ResourceArrayGetAny(&(owner->bufferarr), &foundres))
521  {
522  Buffer res = DatumGetBuffer(foundres);
523 
524  if (isCommit)
526  ReleaseBuffer(res);
527  }
528 
529  /* Ditto for relcache references */
530  while (ResourceArrayGetAny(&(owner->relrefarr), &foundres))
531  {
532  Relation res = (Relation) DatumGetPointer(foundres);
533 
534  if (isCommit)
536  RelationClose(res);
537  }
538 
539  /* Ditto for dynamic shared memory segments */
540  while (ResourceArrayGetAny(&(owner->dsmarr), &foundres))
541  {
542  dsm_segment *res = (dsm_segment *) DatumGetPointer(foundres);
543 
544  if (isCommit)
545  PrintDSMLeakWarning(res);
546  dsm_detach(res);
547  }
548 
549  /* Ditto for JIT contexts */
550  while (ResourceArrayGetAny(&(owner->jitarr), &foundres))
551  {
552  JitContext *context = (JitContext *) PointerGetDatum(foundres);
553 
554  jit_release_context(context);
555  }
556  }
557  else if (phase == RESOURCE_RELEASE_LOCKS)
558  {
559  if (isTopLevel)
560  {
561  /*
562  * For a top-level xact we are going to release all locks (or at
563  * least all non-session locks), so just do a single lmgr call at
564  * the top of the recursion.
565  */
566  if (owner == TopTransactionResourceOwner)
567  {
568  ProcReleaseLocks(isCommit);
569  ReleasePredicateLocks(isCommit, false);
570  }
571  }
572  else
573  {
574  /*
575  * Release locks retail. Note that if we are committing a
576  * subtransaction, we do NOT release its locks yet, but transfer
577  * them to the parent.
578  */
579  LOCALLOCK **locks;
580  int nlocks;
581 
582  Assert(owner->parent != NULL);
583 
584  /*
585  * Pass the list of locks owned by this resource owner to the lock
586  * manager, unless it has overflowed.
587  */
588  if (owner->nlocks > MAX_RESOWNER_LOCKS)
589  {
590  locks = NULL;
591  nlocks = 0;
592  }
593  else
594  {
595  locks = owner->locks;
596  nlocks = owner->nlocks;
597  }
598 
599  if (isCommit)
600  LockReassignCurrentOwner(locks, nlocks);
601  else
602  LockReleaseCurrentOwner(locks, nlocks);
603  }
604  }
605  else if (phase == RESOURCE_RELEASE_AFTER_LOCKS)
606  {
607  /*
608  * Release catcache references. Note that ReleaseCatCache will remove
609  * the catref entry from our array, so we just have to iterate till
610  * there are none.
611  *
612  * As with buffer pins, warn if any are left at commit time.
613  */
614  while (ResourceArrayGetAny(&(owner->catrefarr), &foundres))
615  {
616  HeapTuple res = (HeapTuple) DatumGetPointer(foundres);
617 
618  if (isCommit)
620  ReleaseCatCache(res);
621  }
622 
623  /* Ditto for catcache lists */
624  while (ResourceArrayGetAny(&(owner->catlistrefarr), &foundres))
625  {
626  CatCList *res = (CatCList *) DatumGetPointer(foundres);
627 
628  if (isCommit)
630  ReleaseCatCacheList(res);
631  }
632 
633  /* Ditto for plancache references */
634  while (ResourceArrayGetAny(&(owner->planrefarr), &foundres))
635  {
636  CachedPlan *res = (CachedPlan *) DatumGetPointer(foundres);
637 
638  if (isCommit)
640  ReleaseCachedPlan(res, true);
641  }
642 
643  /* Ditto for tupdesc references */
644  while (ResourceArrayGetAny(&(owner->tupdescarr), &foundres))
645  {
646  TupleDesc res = (TupleDesc) DatumGetPointer(foundres);
647 
648  if (isCommit)
651  }
652 
653  /* Ditto for snapshot references */
654  while (ResourceArrayGetAny(&(owner->snapshotarr), &foundres))
655  {
656  Snapshot res = (Snapshot) DatumGetPointer(foundres);
657 
658  if (isCommit)
660  UnregisterSnapshot(res);
661  }
662 
663  /* Ditto for temporary files */
664  while (ResourceArrayGetAny(&(owner->filearr), &foundres))
665  {
666  File res = DatumGetFile(foundres);
667 
668  if (isCommit)
670  FileClose(res);
671  }
672  }
673 
674  /* Let add-on modules get a chance too */
675  for (item = ResourceRelease_callbacks; item; item = item->next)
676  item->callback(phase, isCommit, isTopLevel, item->arg);
677 
678  CurrentResourceOwner = save;
679 }
ResourceArray relrefarr
Definition: resowner.c:124
void PrintCatCacheListLeakWarning(CatCList *list)
Definition: catcache.c:2087
HeapTupleData * HeapTuple
Definition: htup.h:71
void PrintBufferLeakWarning(Buffer buffer)
Definition: bufmgr.c:2539
ResourceArray catrefarr
Definition: resowner.c:122
#define DatumGetFile(datum)
Definition: resowner.c:43
ResourceOwner TopTransactionResourceOwner
Definition: resowner.c:144
#define PointerGetDatum(X)
Definition: postgres.h:556
ResourceOwner CurrentResourceOwner
Definition: resowner.c:142
Definition: jit.h:54
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3365
ResourceArray bufferarr
Definition: resowner.c:121
static bool ResourceArrayGetAny(ResourceArray *resarr, Datum *value)
Definition: resowner.c:370
ResourceArray snapshotarr
Definition: resowner.c:127
void ReleasePredicateLocks(bool isCommit, bool isReadOnlySafe)
Definition: predicate.c:3267
struct SnapshotData * Snapshot
Definition: snapshot.h:121
static void ResourceOwnerReleaseInternal(ResourceOwner owner, ResourceReleasePhase phase, bool isCommit, bool isTopLevel)
Definition: resowner.c:488
static ResourceReleaseCallbackItem * ResourceRelease_callbacks
Definition: resowner.c:157
void ReleaseCatCacheList(CatCList *list)
Definition: catcache.c:1782
#define MAX_RESOWNER_LOCKS
Definition: resowner.c:108
void LockReleaseCurrentOwner(LOCALLOCK **locallocks, int nlocks)
Definition: lock.c:2393
struct RelationData * Relation
Definition: relcache.h:26
static void PrintSnapshotLeakWarning(Snapshot snapshot)
Definition: resowner.c:1218
ResourceArray planrefarr
Definition: resowner.c:125
void LockReassignCurrentOwner(LOCALLOCK **locallocks, int nlocks)
Definition: lock.c:2488
static void PrintPlanCacheLeakWarning(CachedPlan *plan)
Definition: resowner.c:1128
void ReleaseCachedPlan(CachedPlan *plan, bool useResOwner)
Definition: plancache.c:1259
ResourceArray tupdescarr
Definition: resowner.c:126
void ProcReleaseLocks(bool isCommit)
Definition: proc.c:787
void RelationClose(Relation relation)
Definition: relcache.c:2088
void UnregisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:907
static void PrintRelCacheLeakWarning(Relation rel)
Definition: resowner.c:1083
struct ResourceReleaseCallbackItem * next
Definition: resowner.c:152
uintptr_t Datum
Definition: postgres.h:367
ResourceReleaseCallback callback
Definition: resowner.c:153
ResourceOwner firstchild
Definition: resowner.c:116
void PrintCatCacheLeakWarning(HeapTuple tuple)
Definition: catcache.c:2071
static void PrintTupleDescLeakWarning(TupleDesc tupdesc)
Definition: resowner.c:1172
void ReleaseCatCache(HeapTuple tuple)
Definition: catcache.c:1440
void FileClose(File file)
Definition: fd.c:1748
#define Assert(condition)
Definition: c.h:739
void DecrTupleDescRefCount(TupleDesc tupdesc)
Definition: tupdesc.c:393
ResourceArray jitarr
Definition: resowner.c:130
static void PrintFileLeakWarning(File file)
Definition: resowner.c:1264
ResourceOwner parent
Definition: resowner.c:115
#define DatumGetPointer(X)
Definition: postgres.h:549
void dsm_detach(dsm_segment *seg)
Definition: dsm.c:664
#define DatumGetBuffer(datum)
Definition: resowner.c:45
struct TupleDescData * TupleDesc
Definition: tupdesc.h:89
void jit_release_context(JitContext *context)
Definition: jit.c:138
LOCALLOCK * locks[MAX_RESOWNER_LOCKS]
Definition: resowner.c:134
ResourceArray catlistrefarr
Definition: resowner.c:123
ResourceArray dsmarr
Definition: resowner.c:129
ResourceOwner nextchild
Definition: resowner.c:117
static void PrintDSMLeakWarning(dsm_segment *seg)
Definition: resowner.c:1309
int Buffer
Definition: buf.h:23
int File
Definition: fd.h:45
ResourceArray filearr
Definition: resowner.c:128

◆ ResourceOwnerRememberBuffer()

void ResourceOwnerRememberBuffer ( ResourceOwner  owner,
Buffer  buffer 
)

Definition at line 906 of file resowner.c.

References ResourceOwnerData::bufferarr, BufferGetDatum, and ResourceArrayAdd().

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

907 {
908  ResourceArrayAdd(&(owner->bufferarr), BufferGetDatum(buffer));
909 }
ResourceArray bufferarr
Definition: resowner.c:121
#define BufferGetDatum(buffer)
Definition: resowner.c:44
static void ResourceArrayAdd(ResourceArray *resarr, Datum value)
Definition: resowner.c:263

◆ ResourceOwnerRememberCatCacheListRef()

void ResourceOwnerRememberCatCacheListRef ( ResourceOwner  owner,
CatCList list 
)

Definition at line 1028 of file resowner.c.

References ResourceOwnerData::catlistrefarr, PointerGetDatum, and ResourceArrayAdd().

Referenced by SearchCatCacheList().

1029 {
1031 }
#define PointerGetDatum(X)
Definition: postgres.h:556
ResourceArray catlistrefarr
Definition: resowner.c:123
static void ResourceArrayAdd(ResourceArray *resarr, Datum value)
Definition: resowner.c:263

◆ ResourceOwnerRememberCatCacheRef()

void ResourceOwnerRememberCatCacheRef ( ResourceOwner  owner,
HeapTuple  tuple 
)

Definition at line 993 of file resowner.c.

References ResourceOwnerData::catrefarr, PointerGetDatum, and ResourceArrayAdd().

Referenced by SearchCatCacheInternal(), and SearchCatCacheMiss().

994 {
995  ResourceArrayAdd(&(owner->catrefarr), PointerGetDatum(tuple));
996 }
ResourceArray catrefarr
Definition: resowner.c:122
#define PointerGetDatum(X)
Definition: postgres.h:556
static void ResourceArrayAdd(ResourceArray *resarr, Datum value)
Definition: resowner.c:263

◆ ResourceOwnerRememberDSM()

void ResourceOwnerRememberDSM ( ResourceOwner  owner,
dsm_segment seg 
)

Definition at line 1289 of file resowner.c.

References ResourceOwnerData::dsmarr, PointerGetDatum, and ResourceArrayAdd().

Referenced by dsm_create_descriptor(), and dsm_unpin_mapping().

1290 {
1291  ResourceArrayAdd(&(owner->dsmarr), PointerGetDatum(seg));
1292 }
#define PointerGetDatum(X)
Definition: postgres.h:556
ResourceArray dsmarr
Definition: resowner.c:129
static void ResourceArrayAdd(ResourceArray *resarr, Datum value)
Definition: resowner.c:263

◆ ResourceOwnerRememberFile()

void ResourceOwnerRememberFile ( ResourceOwner  owner,
File  file 
)

Definition at line 1244 of file resowner.c.

References ResourceOwnerData::filearr, FileGetDatum, and ResourceArrayAdd().

Referenced by RegisterTemporaryFile().

1245 {
1246  ResourceArrayAdd(&(owner->filearr), FileGetDatum(file));
1247 }
#define FileGetDatum(file)
Definition: resowner.c:42
static void ResourceArrayAdd(ResourceArray *resarr, Datum value)
Definition: resowner.c:263
ResourceArray filearr
Definition: resowner.c:128

◆ ResourceOwnerRememberJIT()

void ResourceOwnerRememberJIT ( ResourceOwner  owner,
Datum  handle 
)

Definition at line 1334 of file resowner.c.

References ResourceOwnerData::jitarr, and ResourceArrayAdd().

Referenced by llvm_create_context().

1335 {
1336  ResourceArrayAdd(&(owner->jitarr), handle);
1337 }
ResourceArray jitarr
Definition: resowner.c:130
static void ResourceArrayAdd(ResourceArray *resarr, Datum value)
Definition: resowner.c:263

◆ ResourceOwnerRememberLock()

void ResourceOwnerRememberLock ( ResourceOwner  owner,
LOCALLOCK locallock 
)

Definition at line 933 of file resowner.c.

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

Referenced by GrantLockLocal(), and LockReassignOwner().

934 {
935  Assert(locallock != NULL);
936 
937  if (owner->nlocks > MAX_RESOWNER_LOCKS)
938  return; /* we have already overflowed */
939 
940  if (owner->nlocks < MAX_RESOWNER_LOCKS)
941  owner->locks[owner->nlocks] = locallock;
942  else
943  {
944  /* overflowed */
945  }
946  owner->nlocks++;
947 }
#define MAX_RESOWNER_LOCKS
Definition: resowner.c:108
#define Assert(condition)
Definition: c.h:739
LOCALLOCK * locks[MAX_RESOWNER_LOCKS]
Definition: resowner.c:134

◆ ResourceOwnerRememberPlanCacheRef()

void ResourceOwnerRememberPlanCacheRef ( ResourceOwner  owner,
CachedPlan plan 
)

Definition at line 1108 of file resowner.c.

References ResourceOwnerData::planrefarr, PointerGetDatum, and ResourceArrayAdd().

Referenced by GetCachedPlan().

1109 {
1110  ResourceArrayAdd(&(owner->planrefarr), PointerGetDatum(plan));
1111 }
#define PointerGetDatum(X)
Definition: postgres.h:556
ResourceArray planrefarr
Definition: resowner.c:125
static void ResourceArrayAdd(ResourceArray *resarr, Datum value)
Definition: resowner.c:263

◆ ResourceOwnerRememberRelationRef()

void ResourceOwnerRememberRelationRef ( ResourceOwner  owner,
Relation  rel 
)

Definition at line 1063 of file resowner.c.

References PointerGetDatum, ResourceOwnerData::relrefarr, and ResourceArrayAdd().

Referenced by RelationIncrementReferenceCount().

1064 {
1065  ResourceArrayAdd(&(owner->relrefarr), PointerGetDatum(rel));
1066 }
ResourceArray relrefarr
Definition: resowner.c:124
#define PointerGetDatum(X)
Definition: postgres.h:556
static void ResourceArrayAdd(ResourceArray *resarr, Datum value)
Definition: resowner.c:263

◆ ResourceOwnerRememberSnapshot()

void ResourceOwnerRememberSnapshot ( ResourceOwner  owner,
Snapshot  snapshot 
)

Definition at line 1198 of file resowner.c.

References PointerGetDatum, ResourceArrayAdd(), and ResourceOwnerData::snapshotarr.

Referenced by RegisterSnapshotOnOwner().

1199 {
1200  ResourceArrayAdd(&(owner->snapshotarr), PointerGetDatum(snapshot));
1201 }
#define PointerGetDatum(X)
Definition: postgres.h:556
ResourceArray snapshotarr
Definition: resowner.c:127
static void ResourceArrayAdd(ResourceArray *resarr, Datum value)
Definition: resowner.c:263

◆ ResourceOwnerRememberTupleDesc()

void ResourceOwnerRememberTupleDesc ( ResourceOwner  owner,
TupleDesc  tupdesc 
)

Definition at line 1152 of file resowner.c.

References PointerGetDatum, ResourceArrayAdd(), and ResourceOwnerData::tupdescarr.

Referenced by IncrTupleDescRefCount().

1153 {
1154  ResourceArrayAdd(&(owner->tupdescarr), PointerGetDatum(tupdesc));
1155 }
#define PointerGetDatum(X)
Definition: postgres.h:556
ResourceArray tupdescarr
Definition: resowner.c:126
static void ResourceArrayAdd(ResourceArray *resarr, Datum value)
Definition: resowner.c:263

◆ UnregisterResourceReleaseCallback()

void UnregisterResourceReleaseCallback ( ResourceReleaseCallback  callback,
void *  arg 
)

Definition at line 810 of file resowner.c.

References ResourceReleaseCallbackItem::next, and pfree().

811 {
814 
815  prev = NULL;
816  for (item = ResourceRelease_callbacks; item; prev = item, item = item->next)
817  {
818  if (item->callback == callback && item->arg == arg)
819  {
820  if (prev)
821  prev->next = item->next;
822  else
824  pfree(item);
825  break;
826  }
827  }
828 }
static ResourceReleaseCallbackItem * ResourceRelease_callbacks
Definition: resowner.c:157
void pfree(void *pointer)
Definition: mcxt.c:1056
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:48
struct ResourceReleaseCallbackItem * next
Definition: resowner.c:152
void * arg

Variable Documentation

◆ AuxProcessResourceOwner

ResourceOwner AuxProcessResourceOwner = NULL

◆ CurrentResourceOwner

ResourceOwner CurrentResourceOwner = NULL

Definition at line 142 of file resowner.c.

Referenced by AssignTransactionId(), AtAbort_ResourceOwner(), AtStart_ResourceOwner(), AtSubAbort_ResourceOwner(), AtSubStart_ResourceOwner(), BgBufferSync(), BufferSync(), cipher_free_callback(), CleanupSubTransaction(), CleanupTransaction(), close_lo_relation(), CommitSubTransaction(), CommitTransaction(), DecrTupleDescRefCount(), digest_free_callback(), dsm_create_descriptor(), dsm_unpin_mapping(), exec_init_tuple_store(), exec_stmt_block(), extendBufFile(), FlushDatabaseBuffers(), FlushRelationBuffers(), GetCachedPlan(), GetCurrentFDWTuplestore(), IncrBufferRefCount(), IncrTupleDescRefCount(), InitPostgres(), llvm_create_context(), LocalBufferAlloc(), lock_and_open_sequence(), LockAcquireExtended(), LockReassignCurrentOwner(), LockReassignOwner(), LockRelease(), makeBufFileCommon(), MakeTransitionCaptureState(), open_lo_relation(), OpenTemporaryFile(), PathNameCreateTemporaryFile(), PathNameOpenTemporaryFile(), PersistHoldablePortal(), pg_logical_replication_slot_advance(), pg_logical_slot_get_changes_guts(), PinBuffer(), PinBuffer_Locked(), plperl_spi_exec(), plperl_spi_exec_prepared(), plperl_spi_fetchrow(), plperl_spi_prepare(), plperl_spi_query(), plperl_spi_query_prepared(), plpgsql_estate_setup(), pltcl_func_handler(), pltcl_init_tuple_store(), pltcl_returnnext(), pltcl_SPI_execute(), pltcl_SPI_execute_plan(), pltcl_SPI_prepare(), pltcl_subtrans_abort(), pltcl_subtrans_commit(), pltcl_subtransaction(), PLy_abort_open_subtransactions(), PLy_cursor_fetch(), PLy_cursor_iternext(), PLy_cursor_plan(), PLy_cursor_query(), PLy_spi_execute_plan(), PLy_spi_execute_query(), PLy_spi_prepare(), PLy_spi_subtransaction_abort(), PLy_spi_subtransaction_commit(), PLy_subtransaction_enter(), PLy_subtransaction_exit(), PopTransaction(), PortalCleanup(), PortalRun(), PortalRunFetch(), PortalStart(), PrepareTransaction(), px_find_cipher(), px_find_digest(), ReadBuffer_common(), RegisterSnapshot(), RegisterTemporaryFile(), RelationDecrementReferenceCount(), RelationIncrementReferenceCount(), ReleaseAndReadBuffer(), ReleaseBuffer(), ReleaseCachedPlan(), ReleaseCatCache(), ReleaseCatCacheList(), ReleaseLockIfHeld(), ResourceOwnerReleaseInternal(), SearchCatCacheInternal(), SearchCatCacheList(), SearchCatCacheMiss(), ShutdownXLOG(), SnapBuildClearExportedSnapshot(), SnapBuildExportSnapshot(), StartupXLOG(), tuplestore_begin_common(), tuplestore_puttuple_common(), UnpinBuffer(), and UnregisterSnapshot().

◆ CurTransactionResourceOwner

◆ ResourceRelease_callbacks

ResourceReleaseCallbackItem* ResourceRelease_callbacks = NULL
static

Definition at line 157 of file resowner.c.

Referenced by RegisterResourceReleaseCallback().

◆ TopTransactionResourceOwner