PostgreSQL Source Code  git master
resowner.c File Reference
#include "postgres.h"
#include "common/cryptohash.h"
#include "common/hashfn.h"
#include "jit/jit.h"
#include "storage/bufmgr.h"
#include "storage/ipc.h"
#include "storage/predicate.h"
#include "storage/proc.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)
 
static void PrintCryptoHashLeakWarning (Datum handle)
 
ResourceOwner ResourceOwnerCreate (ResourceOwner parent, const char *name)
 
void ResourceOwnerRelease (ResourceOwner owner, ResourceReleasePhase phase, bool isCommit, bool isTopLevel)
 
void ResourceOwnerReleaseAllPlanCacheRefs (ResourceOwner owner)
 
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)
 
void ResourceOwnerEnlargeCryptoHash (ResourceOwner owner)
 
void ResourceOwnerRememberCryptoHash (ResourceOwner owner, Datum handle)
 
void ResourceOwnerForgetCryptoHash (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 46 of file resowner.c.

Referenced by ResourceOwnerReleaseInternal().

◆ DatumGetFile

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

Definition at line 44 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 78 of file resowner.c.

Referenced by ResourceArrayEnlarge().

◆ RESARRAY_IS_ARRAY

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

Definition at line 84 of file resowner.c.

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

◆ RESARRAY_MAX_ARRAY

#define RESARRAY_MAX_ARRAY   64

Definition at line 83 of file resowner.c.

◆ RESARRAY_MAX_ITEMS

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

Definition at line 90 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 875 of file resowner.c.

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

Referenced by AuxiliaryProcessMain(), and InitPostgres().

876 {
878  Assert(CurrentResourceOwner == NULL);
879  AuxProcessResourceOwner = ResourceOwnerCreate(NULL, "AuxiliaryProcess");
881 
882  /*
883  * Register a shmem-exit callback for cleanup of aux-process resource
884  * owner. (This needs to run after, e.g., ShutdownXLOG.)
885  */
887 
888 }
ResourceOwner CurrentResourceOwner
Definition: resowner.c:144
ResourceOwner AuxProcessResourceOwner
Definition: resowner.c:147
static void ReleaseAuxProcessResourcesCallback(int code, Datum arg)
Definition: resowner.c:918
void on_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:361
#define Assert(condition)
Definition: c.h:792
ResourceOwner ResourceOwnerCreate(ResourceOwner parent, const char *name)
Definition: resowner.c:425

◆ PrintCryptoHashLeakWarning()

static void PrintCryptoHashLeakWarning ( Datum  handle)
static

Definition at line 1430 of file resowner.c.

References DatumGetPointer, elog, and WARNING.

Referenced by ResourceOwnerReleaseInternal().

1431 {
1432  elog(WARNING, "cryptohash context reference leak: context %p still referenced",
1433  DatumGetPointer(handle));
1434 }
#define WARNING
Definition: elog.h:40
#define DatumGetPointer(X)
Definition: postgres.h:549
#define elog(elevel,...)
Definition: elog.h:228

◆ PrintDSMLeakWarning()

static void PrintDSMLeakWarning ( dsm_segment seg)
static

Definition at line 1350 of file resowner.c.

References dsm_segment_handle(), elog, and WARNING.

Referenced by ResourceOwnerReleaseInternal().

1351 {
1352  elog(WARNING, "dynamic shared memory leak: segment %u still referenced",
1353  dsm_segment_handle(seg));
1354 }
dsm_handle dsm_segment_handle(dsm_segment *seg)
Definition: dsm.c:1082
#define WARNING
Definition: elog.h:40
#define elog(elevel,...)
Definition: elog.h:228

◆ PrintFileLeakWarning()

static void PrintFileLeakWarning ( File  file)
static

Definition at line 1305 of file resowner.c.

References elog, and WARNING.

Referenced by ResourceOwnerReleaseInternal().

1306 {
1307  elog(WARNING, "temporary file leak: File %d still referenced",
1308  file);
1309 }
#define WARNING
Definition: elog.h:40
#define elog(elevel,...)
Definition: elog.h:228

◆ PrintPlanCacheLeakWarning()

static void PrintPlanCacheLeakWarning ( CachedPlan plan)
static

Definition at line 1169 of file resowner.c.

References elog, and WARNING.

Referenced by ResourceOwnerReleaseInternal().

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

◆ PrintRelCacheLeakWarning()

static void PrintRelCacheLeakWarning ( Relation  rel)
static

Definition at line 1124 of file resowner.c.

References elog, RelationGetRelationName, and WARNING.

Referenced by ResourceOwnerReleaseInternal().

1125 {
1126  elog(WARNING, "relcache reference leak: relation \"%s\" not closed",
1128 }
#define RelationGetRelationName(relation)
Definition: rel.h:491
#define WARNING
Definition: elog.h:40
#define elog(elevel,...)
Definition: elog.h:228

◆ PrintSnapshotLeakWarning()

static void PrintSnapshotLeakWarning ( Snapshot  snapshot)
static

Definition at line 1259 of file resowner.c.

References elog, and WARNING.

Referenced by ResourceOwnerReleaseInternal().

1260 {
1261  elog(WARNING, "Snapshot reference leak: Snapshot %p still referenced",
1262  snapshot);
1263 }
#define WARNING
Definition: elog.h:40
#define elog(elevel,...)
Definition: elog.h:228

◆ PrintTupleDescLeakWarning()

static void PrintTupleDescLeakWarning ( TupleDesc  tupdesc)
static

Definition at line 1213 of file resowner.c.

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

Referenced by ResourceOwnerReleaseInternal().

1214 {
1215  elog(WARNING,
1216  "TupleDesc reference leak: TupleDesc %p (%u,%d) still referenced",
1217  tupdesc, tupdesc->tdtypeid, tupdesc->tdtypmod);
1218 }
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 837 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().

838 {
840 
841  item = (ResourceReleaseCallbackItem *)
844  item->callback = callback;
845  item->arg = arg;
848 }
static ResourceReleaseCallbackItem * ResourceRelease_callbacks
Definition: resowner.c:159
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:154
ResourceReleaseCallback callback
Definition: resowner.c:155
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:797
void * arg

◆ ReleaseAuxProcessResources()

void ReleaseAuxProcessResources ( bool  isCommit)

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

897 {
898  /*
899  * At this writing, the only thing that could actually get released is
900  * buffer pins; but we may as well do the full release protocol.
901  */
904  isCommit, true);
907  isCommit, true);
910  isCommit, true);
911 }
ResourceOwner AuxProcessResourceOwner
Definition: resowner.c:147
void ResourceOwnerRelease(ResourceOwner owner, ResourceReleasePhase phase, bool isCommit, bool isTopLevel)
Definition: resowner.c:482

◆ ReleaseAuxProcessResourcesCallback()

static void ReleaseAuxProcessResourcesCallback ( int  code,
Datum  arg 
)
static

Definition at line 918 of file resowner.c.

References ReleaseAuxProcessResources().

Referenced by CreateAuxProcessResourceOwner().

919 {
920  bool isCommit = (code == 0);
921 
922  ReleaseAuxProcessResources(isCommit);
923 }
void ReleaseAuxProcessResources(bool isCommit)
Definition: resowner.c:896

◆ ResourceArrayAdd()

static void ResourceArrayAdd ( ResourceArray resarr,
Datum  value 
)
static

Definition at line 266 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(), ResourceOwnerRememberCryptoHash(), ResourceOwnerRememberDSM(), ResourceOwnerRememberFile(), ResourceOwnerRememberJIT(), ResourceOwnerRememberPlanCacheRef(), ResourceOwnerRememberRelationRef(), ResourceOwnerRememberSnapshot(), and ResourceOwnerRememberTupleDesc().

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

◆ ResourceArrayEnlarge()

static void ResourceArrayEnlarge ( ResourceArray resarr)
static

Definition at line 211 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(), ResourceOwnerEnlargeCryptoHash(), ResourceOwnerEnlargeDSMs(), ResourceOwnerEnlargeFiles(), ResourceOwnerEnlargeJIT(), ResourceOwnerEnlargePlanCacheRefs(), ResourceOwnerEnlargeRelationRefs(), ResourceOwnerEnlargeSnapshots(), and ResourceOwnerEnlargeTupleDescs().

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

◆ ResourceArrayFree()

static void ResourceArrayFree ( ResourceArray resarr)
static

Definition at line 405 of file resowner.c.

References ResourceArray::itemsarr, and pfree().

Referenced by ResourceOwnerDelete().

406 {
407  if (resarr->itemsarr)
408  pfree(resarr->itemsarr);
409 }
void pfree(void *pointer)
Definition: mcxt.c:1057
Datum * itemsarr
Definition: resowner.c:66

◆ ResourceArrayGetAny()

static bool ResourceArrayGetAny ( ResourceArray resarr,
Datum value 
)
static

Definition at line 373 of file resowner.c.

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

Referenced by ResourceOwnerReleaseAllPlanCacheRefs(), and ResourceOwnerReleaseInternal().

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

◆ ResourceArrayInit()

static void ResourceArrayInit ( ResourceArray resarr,
Datum  invalidval 
)
static

Definition at line 192 of file resowner.c.

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

Referenced by ResourceOwnerCreate().

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

◆ ResourceArrayRemove()

static bool ResourceArrayRemove ( ResourceArray resarr,
Datum  value 
)
static

Definition at line 304 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(), ResourceOwnerForgetCryptoHash(), ResourceOwnerForgetDSM(), ResourceOwnerForgetFile(), ResourceOwnerForgetJIT(), ResourceOwnerForgetPlanCacheRef(), ResourceOwnerForgetRelationRef(), ResourceOwnerForgetSnapshot(), and ResourceOwnerForgetTupleDesc().

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

◆ ResourceOwnerCreate()

ResourceOwner ResourceOwnerCreate ( ResourceOwner  parent,
const char *  name 
)

Definition at line 425 of file resowner.c.

References ResourceOwnerData::bufferarr, BufferGetDatum, ResourceOwnerData::catlistrefarr, ResourceOwnerData::catrefarr, ResourceOwnerData::cryptohasharr, 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(), CreatePortal(), perform_base_backup(), plpgsql_create_econtext(), and plpgsql_inline_handler().

426 {
427  ResourceOwner owner;
428 
430  sizeof(ResourceOwnerData));
431  owner->name = name;
432 
433  if (parent)
434  {
435  owner->parent = parent;
436  owner->nextchild = parent->firstchild;
437  parent->firstchild = owner;
438  }
439 
441  ResourceArrayInit(&(owner->catrefarr), PointerGetDatum(NULL));
443  ResourceArrayInit(&(owner->relrefarr), PointerGetDatum(NULL));
444  ResourceArrayInit(&(owner->planrefarr), PointerGetDatum(NULL));
445  ResourceArrayInit(&(owner->tupdescarr), PointerGetDatum(NULL));
447  ResourceArrayInit(&(owner->filearr), FileGetDatum(-1));
448  ResourceArrayInit(&(owner->dsmarr), PointerGetDatum(NULL));
449  ResourceArrayInit(&(owner->jitarr), PointerGetDatum(NULL));
451 
452  return owner;
453 }
ResourceArray relrefarr
Definition: resowner.c:125
ResourceArray catrefarr
Definition: resowner.c:123
#define PointerGetDatum(X)
Definition: postgres.h:556
#define InvalidBuffer
Definition: buf.h:25
ResourceArray bufferarr
Definition: resowner.c:122
ResourceArray snapshotarr
Definition: resowner.c:128
struct ResourceOwnerData * ResourceOwner
Definition: resowner.h:27
const char * name
Definition: resowner.c:119
ResourceArray planrefarr
Definition: resowner.c:126
ResourceArray tupdescarr
Definition: resowner.c:127
static void ResourceArrayInit(ResourceArray *resarr, Datum invalidval)
Definition: resowner.c:192
MemoryContext TopMemoryContext
Definition: mcxt.c:44
ResourceOwner firstchild
Definition: resowner.c:117
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition: mcxt.c:840
#define BufferGetDatum(buffer)
Definition: resowner.c:45
#define FileGetDatum(file)
Definition: resowner.c:43
ResourceArray jitarr
Definition: resowner.c:131
ResourceOwner parent
Definition: resowner.c:116
const char * name
Definition: encode.c:515
ResourceArray catlistrefarr
Definition: resowner.c:124
ResourceArray dsmarr
Definition: resowner.c:130
ResourceOwner nextchild
Definition: resowner.c:118
ResourceArray filearr
Definition: resowner.c:129
ResourceArray cryptohasharr
Definition: resowner.c:132

◆ ResourceOwnerDelete()

void ResourceOwnerDelete ( ResourceOwner  owner)

Definition at line 727 of file resowner.c.

References Assert, ResourceOwnerData::bufferarr, ResourceOwnerData::catlistrefarr, ResourceOwnerData::catrefarr, ResourceOwnerData::cryptohasharr, 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(), plpgsql_inline_handler(), PortalDrop(), PrepareTransaction(), ResourceOwnerDelete(), and WalSndResourceCleanup().

728 {
729  /* We had better not be deleting CurrentResourceOwner ... */
730  Assert(owner != CurrentResourceOwner);
731 
732  /* And it better not own any resources, either */
733  Assert(owner->bufferarr.nitems == 0);
734  Assert(owner->catrefarr.nitems == 0);
735  Assert(owner->catlistrefarr.nitems == 0);
736  Assert(owner->relrefarr.nitems == 0);
737  Assert(owner->planrefarr.nitems == 0);
738  Assert(owner->tupdescarr.nitems == 0);
739  Assert(owner->snapshotarr.nitems == 0);
740  Assert(owner->filearr.nitems == 0);
741  Assert(owner->dsmarr.nitems == 0);
742  Assert(owner->jitarr.nitems == 0);
743  Assert(owner->cryptohasharr.nitems == 0);
744  Assert(owner->nlocks == 0 || owner->nlocks == MAX_RESOWNER_LOCKS + 1);
745 
746  /*
747  * Delete children. The recursive call will delink the child from me, so
748  * just iterate as long as there is a child.
749  */
750  while (owner->firstchild != NULL)
752 
753  /*
754  * We delink the owner from its parent before deleting it, so that if
755  * there's an error we won't have deleted/busted owners still attached to
756  * the owner tree. Better a leak than a crash.
757  */
758  ResourceOwnerNewParent(owner, NULL);
759 
760  /* And free the object. */
761  ResourceArrayFree(&(owner->bufferarr));
762  ResourceArrayFree(&(owner->catrefarr));
763  ResourceArrayFree(&(owner->catlistrefarr));
764  ResourceArrayFree(&(owner->relrefarr));
765  ResourceArrayFree(&(owner->planrefarr));
766  ResourceArrayFree(&(owner->tupdescarr));
767  ResourceArrayFree(&(owner->snapshotarr));
768  ResourceArrayFree(&(owner->filearr));
769  ResourceArrayFree(&(owner->dsmarr));
770  ResourceArrayFree(&(owner->jitarr));
771  ResourceArrayFree(&(owner->cryptohasharr));
772 
773  pfree(owner);
774 }
ResourceArray relrefarr
Definition: resowner.c:125
ResourceArray catrefarr
Definition: resowner.c:123
ResourceOwner CurrentResourceOwner
Definition: resowner.c:144
void ResourceOwnerDelete(ResourceOwner owner)
Definition: resowner.c:727
ResourceArray bufferarr
Definition: resowner.c:122
ResourceArray snapshotarr
Definition: resowner.c:128
#define MAX_RESOWNER_LOCKS
Definition: resowner.c:109
void pfree(void *pointer)
Definition: mcxt.c:1057
ResourceArray planrefarr
Definition: resowner.c:126
static void ResourceArrayFree(ResourceArray *resarr)
Definition: resowner.c:405
ResourceArray tupdescarr
Definition: resowner.c:127
ResourceOwner firstchild
Definition: resowner.c:117
#define Assert(condition)
Definition: c.h:792
ResourceArray jitarr
Definition: resowner.c:131
void ResourceOwnerNewParent(ResourceOwner owner, ResourceOwner newparent)
Definition: resowner.c:789
ResourceArray catlistrefarr
Definition: resowner.c:124
ResourceArray dsmarr
Definition: resowner.c:130
uint32 nitems
Definition: resowner.c:69
ResourceArray filearr
Definition: resowner.c:129
ResourceArray cryptohasharr
Definition: resowner.c:132

◆ ResourceOwnerEnlargeBuffers()

void ResourceOwnerEnlargeBuffers ( ResourceOwner  owner)

Definition at line 934 of file resowner.c.

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

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

935 {
936  /* We used to allow pinning buffers without a resowner, but no more */
937  Assert(owner != NULL);
938  ResourceArrayEnlarge(&(owner->bufferarr));
939 }
static void ResourceArrayEnlarge(ResourceArray *resarr)
Definition: resowner.c:211
ResourceArray bufferarr
Definition: resowner.c:122
#define Assert(condition)
Definition: c.h:792

◆ ResourceOwnerEnlargeCatCacheListRefs()

void ResourceOwnerEnlargeCatCacheListRefs ( ResourceOwner  owner)

Definition at line 1058 of file resowner.c.

References ResourceOwnerData::catlistrefarr, and ResourceArrayEnlarge().

Referenced by SearchCatCacheList().

1059 {
1061 }
static void ResourceArrayEnlarge(ResourceArray *resarr)
Definition: resowner.c:211
ResourceArray catlistrefarr
Definition: resowner.c:124

◆ ResourceOwnerEnlargeCatCacheRefs()

void ResourceOwnerEnlargeCatCacheRefs ( ResourceOwner  owner)

Definition at line 1023 of file resowner.c.

References ResourceOwnerData::catrefarr, and ResourceArrayEnlarge().

Referenced by SearchCatCacheInternal(), and SearchCatCacheMiss().

1024 {
1025  ResourceArrayEnlarge(&(owner->catrefarr));
1026 }
static void ResourceArrayEnlarge(ResourceArray *resarr)
Definition: resowner.c:211
ResourceArray catrefarr
Definition: resowner.c:123

◆ ResourceOwnerEnlargeCryptoHash()

void ResourceOwnerEnlargeCryptoHash ( ResourceOwner  owner)

Definition at line 1399 of file resowner.c.

References ResourceOwnerData::cryptohasharr, and ResourceArrayEnlarge().

Referenced by pg_cryptohash_create().

1400 {
1402 }
static void ResourceArrayEnlarge(ResourceArray *resarr)
Definition: resowner.c:211
ResourceArray cryptohasharr
Definition: resowner.c:132

◆ ResourceOwnerEnlargeDSMs()

void ResourceOwnerEnlargeDSMs ( ResourceOwner  owner)

Definition at line 1319 of file resowner.c.

References ResourceOwnerData::dsmarr, and ResourceArrayEnlarge().

Referenced by dsm_create_descriptor(), and dsm_unpin_mapping().

1320 {
1321  ResourceArrayEnlarge(&(owner->dsmarr));
1322 }
static void ResourceArrayEnlarge(ResourceArray *resarr)
Definition: resowner.c:211
ResourceArray dsmarr
Definition: resowner.c:130

◆ ResourceOwnerEnlargeFiles()

void ResourceOwnerEnlargeFiles ( ResourceOwner  owner)

Definition at line 1274 of file resowner.c.

References ResourceOwnerData::filearr, and ResourceArrayEnlarge().

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

1275 {
1276  ResourceArrayEnlarge(&(owner->filearr));
1277 }
static void ResourceArrayEnlarge(ResourceArray *resarr)
Definition: resowner.c:211
ResourceArray filearr
Definition: resowner.c:129

◆ ResourceOwnerEnlargeJIT()

void ResourceOwnerEnlargeJIT ( ResourceOwner  owner)

Definition at line 1364 of file resowner.c.

References ResourceOwnerData::jitarr, and ResourceArrayEnlarge().

Referenced by llvm_create_context().

1365 {
1366  ResourceArrayEnlarge(&(owner->jitarr));
1367 }
static void ResourceArrayEnlarge(ResourceArray *resarr)
Definition: resowner.c:211
ResourceArray jitarr
Definition: resowner.c:131

◆ ResourceOwnerEnlargePlanCacheRefs()

void ResourceOwnerEnlargePlanCacheRefs ( ResourceOwner  owner)

Definition at line 1138 of file resowner.c.

References ResourceOwnerData::planrefarr, and ResourceArrayEnlarge().

Referenced by CachedPlanAllowsSimpleValidityCheck(), CachedPlanIsSimplyValid(), and GetCachedPlan().

1139 {
1140  ResourceArrayEnlarge(&(owner->planrefarr));
1141 }
static void ResourceArrayEnlarge(ResourceArray *resarr)
Definition: resowner.c:211
ResourceArray planrefarr
Definition: resowner.c:126

◆ ResourceOwnerEnlargeRelationRefs()

void ResourceOwnerEnlargeRelationRefs ( ResourceOwner  owner)

Definition at line 1093 of file resowner.c.

References ResourceOwnerData::relrefarr, and ResourceArrayEnlarge().

Referenced by RelationIncrementReferenceCount().

1094 {
1095  ResourceArrayEnlarge(&(owner->relrefarr));
1096 }
static void ResourceArrayEnlarge(ResourceArray *resarr)
Definition: resowner.c:211
ResourceArray relrefarr
Definition: resowner.c:125

◆ ResourceOwnerEnlargeSnapshots()

void ResourceOwnerEnlargeSnapshots ( ResourceOwner  owner)

Definition at line 1228 of file resowner.c.

References ResourceArrayEnlarge(), and ResourceOwnerData::snapshotarr.

Referenced by RegisterSnapshotOnOwner().

1229 {
1230  ResourceArrayEnlarge(&(owner->snapshotarr));
1231 }
static void ResourceArrayEnlarge(ResourceArray *resarr)
Definition: resowner.c:211
ResourceArray snapshotarr
Definition: resowner.c:128

◆ ResourceOwnerEnlargeTupleDescs()

void ResourceOwnerEnlargeTupleDescs ( ResourceOwner  owner)

Definition at line 1182 of file resowner.c.

References ResourceArrayEnlarge(), and ResourceOwnerData::tupdescarr.

Referenced by IncrTupleDescRefCount().

1183 {
1184  ResourceArrayEnlarge(&(owner->tupdescarr));
1185 }
static void ResourceArrayEnlarge(ResourceArray *resarr)
Definition: resowner.c:211
ResourceArray tupdescarr
Definition: resowner.c:127

◆ ResourceOwnerForgetBuffer()

void ResourceOwnerForgetBuffer ( ResourceOwner  owner,
Buffer  buffer 
)

Definition at line 956 of file resowner.c.

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

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

957 {
958  if (!ResourceArrayRemove(&(owner->bufferarr), BufferGetDatum(buffer)))
959  elog(ERROR, "buffer %d is not owned by resource owner %s",
960  buffer, owner->name);
961 }
ResourceArray bufferarr
Definition: resowner.c:122
const char * name
Definition: resowner.c:119
#define ERROR
Definition: elog.h:45
#define BufferGetDatum(buffer)
Definition: resowner.c:45
static bool ResourceArrayRemove(ResourceArray *resarr, Datum value)
Definition: resowner.c:304
#define elog(elevel,...)
Definition: elog.h:228

◆ ResourceOwnerForgetCatCacheListRef()

void ResourceOwnerForgetCatCacheListRef ( ResourceOwner  owner,
CatCList list 
)

Definition at line 1078 of file resowner.c.

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

Referenced by ReleaseCatCacheList().

1079 {
1080  if (!ResourceArrayRemove(&(owner->catlistrefarr), PointerGetDatum(list)))
1081  elog(ERROR, "catcache list reference %p is not owned by resource owner %s",
1082  list, owner->name);
1083 }
#define PointerGetDatum(X)
Definition: postgres.h:556
const char * name
Definition: resowner.c:119
#define ERROR
Definition: elog.h:45
static bool ResourceArrayRemove(ResourceArray *resarr, Datum value)
Definition: resowner.c:304
#define elog(elevel,...)
Definition: elog.h:228
ResourceArray catlistrefarr
Definition: resowner.c:124

◆ ResourceOwnerForgetCatCacheRef()

void ResourceOwnerForgetCatCacheRef ( ResourceOwner  owner,
HeapTuple  tuple 
)

Definition at line 1043 of file resowner.c.

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

Referenced by ReleaseCatCache().

1044 {
1045  if (!ResourceArrayRemove(&(owner->catrefarr), PointerGetDatum(tuple)))
1046  elog(ERROR, "catcache reference %p is not owned by resource owner %s",
1047  tuple, owner->name);
1048 }
ResourceArray catrefarr
Definition: resowner.c:123
#define PointerGetDatum(X)
Definition: postgres.h:556
const char * name
Definition: resowner.c:119
#define ERROR
Definition: elog.h:45
static bool ResourceArrayRemove(ResourceArray *resarr, Datum value)
Definition: resowner.c:304
#define elog(elevel,...)
Definition: elog.h:228

◆ ResourceOwnerForgetCryptoHash()

void ResourceOwnerForgetCryptoHash ( ResourceOwner  owner,
Datum  handle 
)

Definition at line 1419 of file resowner.c.

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

Referenced by pg_cryptohash_free().

1420 {
1421  if (!ResourceArrayRemove(&(owner->cryptohasharr), handle))
1422  elog(ERROR, "cryptohash context %p is not owned by resource owner %s",
1423  DatumGetPointer(handle), owner->name);
1424 }
const char * name
Definition: resowner.c:119
#define ERROR
Definition: elog.h:45
static bool ResourceArrayRemove(ResourceArray *resarr, Datum value)
Definition: resowner.c:304
#define DatumGetPointer(X)
Definition: postgres.h:549
#define elog(elevel,...)
Definition: elog.h:228
ResourceArray cryptohasharr
Definition: resowner.c:132

◆ ResourceOwnerForgetDSM()

void ResourceOwnerForgetDSM ( ResourceOwner  owner,
dsm_segment seg 
)

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

1340 {
1341  if (!ResourceArrayRemove(&(owner->dsmarr), PointerGetDatum(seg)))
1342  elog(ERROR, "dynamic shared memory segment %u is not owned by resource owner %s",
1343  dsm_segment_handle(seg), owner->name);
1344 }
#define PointerGetDatum(X)
Definition: postgres.h:556
dsm_handle dsm_segment_handle(dsm_segment *seg)
Definition: dsm.c:1082
const char * name
Definition: resowner.c:119
#define ERROR
Definition: elog.h:45
static bool ResourceArrayRemove(ResourceArray *resarr, Datum value)
Definition: resowner.c:304
#define elog(elevel,...)
Definition: elog.h:228
ResourceArray dsmarr
Definition: resowner.c:130

◆ ResourceOwnerForgetFile()

void ResourceOwnerForgetFile ( ResourceOwner  owner,
File  file 
)

Definition at line 1294 of file resowner.c.

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

Referenced by FileClose().

1295 {
1296  if (!ResourceArrayRemove(&(owner->filearr), FileGetDatum(file)))
1297  elog(ERROR, "temporary file %d is not owned by resource owner %s",
1298  file, owner->name);
1299 }
const char * name
Definition: resowner.c:119
#define ERROR
Definition: elog.h:45
#define FileGetDatum(file)
Definition: resowner.c:43
static bool ResourceArrayRemove(ResourceArray *resarr, Datum value)
Definition: resowner.c:304
#define elog(elevel,...)
Definition: elog.h:228
ResourceArray filearr
Definition: resowner.c:129

◆ ResourceOwnerForgetJIT()

void ResourceOwnerForgetJIT ( ResourceOwner  owner,
Datum  handle 
)

Definition at line 1384 of file resowner.c.

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

Referenced by jit_release_context().

1385 {
1386  if (!ResourceArrayRemove(&(owner->jitarr), handle))
1387  elog(ERROR, "JIT context %p is not owned by resource owner %s",
1388  DatumGetPointer(handle), owner->name);
1389 }
const char * name
Definition: resowner.c:119
#define ERROR
Definition: elog.h:45
ResourceArray jitarr
Definition: resowner.c:131
static bool ResourceArrayRemove(ResourceArray *resarr, Datum value)
Definition: resowner.c:304
#define DatumGetPointer(X)
Definition: postgres.h:549
#define elog(elevel,...)
Definition: elog.h:228

◆ ResourceOwnerForgetLock()

void ResourceOwnerForgetLock ( ResourceOwner  owner,
LOCALLOCK locallock 
)

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

995 {
996  int i;
997 
998  if (owner->nlocks > MAX_RESOWNER_LOCKS)
999  return; /* we have overflowed */
1000 
1001  Assert(owner->nlocks > 0);
1002  for (i = owner->nlocks - 1; i >= 0; i--)
1003  {
1004  if (locallock == owner->locks[i])
1005  {
1006  owner->locks[i] = owner->locks[owner->nlocks - 1];
1007  owner->nlocks--;
1008  return;
1009  }
1010  }
1011  elog(ERROR, "lock reference %p is not owned by resource owner %s",
1012  locallock, owner->name);
1013 }
#define MAX_RESOWNER_LOCKS
Definition: resowner.c:109
const char * name
Definition: resowner.c:119
#define ERROR
Definition: elog.h:45
#define Assert(condition)
Definition: c.h:792
LOCALLOCK * locks[MAX_RESOWNER_LOCKS]
Definition: resowner.c:136
#define elog(elevel,...)
Definition: elog.h:228
int i

◆ ResourceOwnerForgetPlanCacheRef()

void ResourceOwnerForgetPlanCacheRef ( ResourceOwner  owner,
CachedPlan plan 
)

Definition at line 1158 of file resowner.c.

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

Referenced by ReleaseCachedPlan().

1159 {
1160  if (!ResourceArrayRemove(&(owner->planrefarr), PointerGetDatum(plan)))
1161  elog(ERROR, "plancache reference %p is not owned by resource owner %s",
1162  plan, owner->name);
1163 }
#define PointerGetDatum(X)
Definition: postgres.h:556
const char * name
Definition: resowner.c:119
#define ERROR
Definition: elog.h:45
ResourceArray planrefarr
Definition: resowner.c:126
static bool ResourceArrayRemove(ResourceArray *resarr, Datum value)
Definition: resowner.c:304
#define elog(elevel,...)
Definition: elog.h:228

◆ ResourceOwnerForgetRelationRef()

void ResourceOwnerForgetRelationRef ( ResourceOwner  owner,
Relation  rel 
)

Definition at line 1113 of file resowner.c.

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

Referenced by RelationDecrementReferenceCount().

1114 {
1115  if (!ResourceArrayRemove(&(owner->relrefarr), PointerGetDatum(rel)))
1116  elog(ERROR, "relcache reference %s is not owned by resource owner %s",
1117  RelationGetRelationName(rel), owner->name);
1118 }
ResourceArray relrefarr
Definition: resowner.c:125
#define PointerGetDatum(X)
Definition: postgres.h:556
const char * name
Definition: resowner.c:119
#define ERROR
Definition: elog.h:45
#define RelationGetRelationName(relation)
Definition: rel.h:491
static bool ResourceArrayRemove(ResourceArray *resarr, Datum value)
Definition: resowner.c:304
#define elog(elevel,...)
Definition: elog.h:228

◆ ResourceOwnerForgetSnapshot()

void ResourceOwnerForgetSnapshot ( ResourceOwner  owner,
Snapshot  snapshot 
)

Definition at line 1248 of file resowner.c.

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

Referenced by UnregisterSnapshotFromOwner().

1249 {
1250  if (!ResourceArrayRemove(&(owner->snapshotarr), PointerGetDatum(snapshot)))
1251  elog(ERROR, "snapshot reference %p is not owned by resource owner %s",
1252  snapshot, owner->name);
1253 }
#define PointerGetDatum(X)
Definition: postgres.h:556
ResourceArray snapshotarr
Definition: resowner.c:128
const char * name
Definition: resowner.c:119
#define ERROR
Definition: elog.h:45
static bool ResourceArrayRemove(ResourceArray *resarr, Datum value)
Definition: resowner.c:304
#define elog(elevel,...)
Definition: elog.h:228

◆ ResourceOwnerForgetTupleDesc()

void ResourceOwnerForgetTupleDesc ( ResourceOwner  owner,
TupleDesc  tupdesc 
)

Definition at line 1202 of file resowner.c.

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

Referenced by DecrTupleDescRefCount().

1203 {
1204  if (!ResourceArrayRemove(&(owner->tupdescarr), PointerGetDatum(tupdesc)))
1205  elog(ERROR, "tupdesc reference %p is not owned by resource owner %s",
1206  tupdesc, owner->name);
1207 }
#define PointerGetDatum(X)
Definition: postgres.h:556
const char * name
Definition: resowner.c:119
#define ERROR
Definition: elog.h:45
ResourceArray tupdescarr
Definition: resowner.c:127
static bool ResourceArrayRemove(ResourceArray *resarr, Datum value)
Definition: resowner.c:304
#define elog(elevel,...)
Definition: elog.h:228

◆ ResourceOwnerGetParent()

ResourceOwner ResourceOwnerGetParent ( ResourceOwner  owner)

Definition at line 780 of file resowner.c.

References ResourceOwnerData::parent.

Referenced by LockReassignCurrentOwner().

781 {
782  return owner->parent;
783 }
ResourceOwner parent
Definition: resowner.c:116

◆ ResourceOwnerNewParent()

void ResourceOwnerNewParent ( ResourceOwner  owner,
ResourceOwner  newparent 
)

Definition at line 789 of file resowner.c.

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

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

791 {
792  ResourceOwner oldparent = owner->parent;
793 
794  if (oldparent)
795  {
796  if (owner == oldparent->firstchild)
797  oldparent->firstchild = owner->nextchild;
798  else
799  {
800  ResourceOwner child;
801 
802  for (child = oldparent->firstchild; child; child = child->nextchild)
803  {
804  if (owner == child->nextchild)
805  {
806  child->nextchild = owner->nextchild;
807  break;
808  }
809  }
810  }
811  }
812 
813  if (newparent)
814  {
815  Assert(owner != newparent);
816  owner->parent = newparent;
817  owner->nextchild = newparent->firstchild;
818  newparent->firstchild = owner;
819  }
820  else
821  {
822  owner->parent = NULL;
823  owner->nextchild = NULL;
824  }
825 }
ResourceOwner firstchild
Definition: resowner.c:117
#define Assert(condition)
Definition: c.h:792
ResourceOwner parent
Definition: resowner.c:116
ResourceOwner nextchild
Definition: resowner.c:118

◆ ResourceOwnerRelease()

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

Definition at line 482 of file resowner.c.

References ResourceOwnerReleaseInternal().

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

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

◆ ResourceOwnerReleaseAllPlanCacheRefs()

void ResourceOwnerReleaseAllPlanCacheRefs ( ResourceOwner  owner)

Definition at line 704 of file resowner.c.

References CurrentResourceOwner, DatumGetPointer, ResourceOwnerData::planrefarr, ReleaseCachedPlan(), and ResourceArrayGetAny().

Referenced by plpgsql_inline_handler(), and plpgsql_xact_cb().

705 {
706  ResourceOwner save;
707  Datum foundres;
708 
709  save = CurrentResourceOwner;
710  CurrentResourceOwner = owner;
711  while (ResourceArrayGetAny(&(owner->planrefarr), &foundres))
712  {
713  CachedPlan *res = (CachedPlan *) DatumGetPointer(foundres);
714 
715  ReleaseCachedPlan(res, true);
716  }
717  CurrentResourceOwner = save;
718 }
ResourceOwner CurrentResourceOwner
Definition: resowner.c:144
static bool ResourceArrayGetAny(ResourceArray *resarr, Datum *value)
Definition: resowner.c:373
ResourceArray planrefarr
Definition: resowner.c:126
void ReleaseCachedPlan(CachedPlan *plan, bool useResOwner)
Definition: plancache.c:1264
uintptr_t Datum
Definition: postgres.h:367
#define DatumGetPointer(X)
Definition: postgres.h:549

◆ ResourceOwnerReleaseInternal()

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

Definition at line 492 of file resowner.c.

References ResourceReleaseCallbackItem::arg, Assert, ResourceOwnerData::bufferarr, ResourceReleaseCallbackItem::callback, ResourceOwnerData::catlistrefarr, ResourceOwnerData::catrefarr, ResourceOwnerData::cryptohasharr, 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, pg_cryptohash_free(), ResourceOwnerData::planrefarr, PointerGetDatum, PrintBufferLeakWarning(), PrintCatCacheLeakWarning(), PrintCatCacheListLeakWarning(), PrintCryptoHashLeakWarning(), 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().

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

◆ ResourceOwnerRememberBuffer()

void ResourceOwnerRememberBuffer ( ResourceOwner  owner,
Buffer  buffer 
)

Definition at line 947 of file resowner.c.

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

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

948 {
949  ResourceArrayAdd(&(owner->bufferarr), BufferGetDatum(buffer));
950 }
ResourceArray bufferarr
Definition: resowner.c:122
#define BufferGetDatum(buffer)
Definition: resowner.c:45
static void ResourceArrayAdd(ResourceArray *resarr, Datum value)
Definition: resowner.c:266

◆ ResourceOwnerRememberCatCacheListRef()

void ResourceOwnerRememberCatCacheListRef ( ResourceOwner  owner,
CatCList list 
)

Definition at line 1069 of file resowner.c.

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

Referenced by SearchCatCacheList().

1070 {
1072 }
#define PointerGetDatum(X)
Definition: postgres.h:556
ResourceArray catlistrefarr
Definition: resowner.c:124
static void ResourceArrayAdd(ResourceArray *resarr, Datum value)
Definition: resowner.c:266

◆ ResourceOwnerRememberCatCacheRef()

void ResourceOwnerRememberCatCacheRef ( ResourceOwner  owner,
HeapTuple  tuple 
)

Definition at line 1034 of file resowner.c.

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

Referenced by SearchCatCacheInternal(), and SearchCatCacheMiss().

1035 {
1036  ResourceArrayAdd(&(owner->catrefarr), PointerGetDatum(tuple));
1037 }
ResourceArray catrefarr
Definition: resowner.c:123
#define PointerGetDatum(X)
Definition: postgres.h:556
static void ResourceArrayAdd(ResourceArray *resarr, Datum value)
Definition: resowner.c:266

◆ ResourceOwnerRememberCryptoHash()

void ResourceOwnerRememberCryptoHash ( ResourceOwner  owner,
Datum  handle 
)

Definition at line 1410 of file resowner.c.

References ResourceOwnerData::cryptohasharr, and ResourceArrayAdd().

Referenced by pg_cryptohash_create().

1411 {
1412  ResourceArrayAdd(&(owner->cryptohasharr), handle);
1413 }
static void ResourceArrayAdd(ResourceArray *resarr, Datum value)
Definition: resowner.c:266
ResourceArray cryptohasharr
Definition: resowner.c:132

◆ ResourceOwnerRememberDSM()

void ResourceOwnerRememberDSM ( ResourceOwner  owner,
dsm_segment seg 
)

Definition at line 1330 of file resowner.c.

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

Referenced by dsm_create_descriptor(), and dsm_unpin_mapping().

1331 {
1332  ResourceArrayAdd(&(owner->dsmarr), PointerGetDatum(seg));
1333 }
#define PointerGetDatum(X)
Definition: postgres.h:556
ResourceArray dsmarr
Definition: resowner.c:130
static void ResourceArrayAdd(ResourceArray *resarr, Datum value)
Definition: resowner.c:266

◆ ResourceOwnerRememberFile()

void ResourceOwnerRememberFile ( ResourceOwner  owner,
File  file 
)

Definition at line 1285 of file resowner.c.

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

Referenced by RegisterTemporaryFile().

1286 {
1287  ResourceArrayAdd(&(owner->filearr), FileGetDatum(file));
1288 }
#define FileGetDatum(file)
Definition: resowner.c:43
static void ResourceArrayAdd(ResourceArray *resarr, Datum value)
Definition: resowner.c:266
ResourceArray filearr
Definition: resowner.c:129

◆ ResourceOwnerRememberJIT()

void ResourceOwnerRememberJIT ( ResourceOwner  owner,
Datum  handle 
)

Definition at line 1375 of file resowner.c.

References ResourceOwnerData::jitarr, and ResourceArrayAdd().

Referenced by llvm_create_context().

1376 {
1377  ResourceArrayAdd(&(owner->jitarr), handle);
1378 }
ResourceArray jitarr
Definition: resowner.c:131
static void ResourceArrayAdd(ResourceArray *resarr, Datum value)
Definition: resowner.c:266

◆ ResourceOwnerRememberLock()

void ResourceOwnerRememberLock ( ResourceOwner  owner,
LOCALLOCK locallock 
)

Definition at line 974 of file resowner.c.

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

Referenced by GrantLockLocal(), and LockReassignOwner().

975 {
976  Assert(locallock != NULL);
977 
978  if (owner->nlocks > MAX_RESOWNER_LOCKS)
979  return; /* we have already overflowed */
980 
981  if (owner->nlocks < MAX_RESOWNER_LOCKS)
982  owner->locks[owner->nlocks] = locallock;
983  else
984  {
985  /* overflowed */
986  }
987  owner->nlocks++;
988 }
#define MAX_RESOWNER_LOCKS
Definition: resowner.c:109
#define Assert(condition)
Definition: c.h:792
LOCALLOCK * locks[MAX_RESOWNER_LOCKS]
Definition: resowner.c:136

◆ ResourceOwnerRememberPlanCacheRef()

void ResourceOwnerRememberPlanCacheRef ( ResourceOwner  owner,
CachedPlan plan 
)

Definition at line 1149 of file resowner.c.

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

Referenced by CachedPlanAllowsSimpleValidityCheck(), CachedPlanIsSimplyValid(), and GetCachedPlan().

1150 {
1151  ResourceArrayAdd(&(owner->planrefarr), PointerGetDatum(plan));
1152 }
#define PointerGetDatum(X)
Definition: postgres.h:556
ResourceArray planrefarr
Definition: resowner.c:126
static void ResourceArrayAdd(ResourceArray *resarr, Datum value)
Definition: resowner.c:266

◆ ResourceOwnerRememberRelationRef()

void ResourceOwnerRememberRelationRef ( ResourceOwner  owner,
Relation  rel 
)

Definition at line 1104 of file resowner.c.

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

Referenced by RelationIncrementReferenceCount().

1105 {
1106  ResourceArrayAdd(&(owner->relrefarr), PointerGetDatum(rel));
1107 }
ResourceArray relrefarr
Definition: resowner.c:125
#define PointerGetDatum(X)
Definition: postgres.h:556
static void ResourceArrayAdd(ResourceArray *resarr, Datum value)
Definition: resowner.c:266

◆ ResourceOwnerRememberSnapshot()

void ResourceOwnerRememberSnapshot ( ResourceOwner  owner,
Snapshot  snapshot 
)

Definition at line 1239 of file resowner.c.

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

Referenced by RegisterSnapshotOnOwner().

1240 {
1241  ResourceArrayAdd(&(owner->snapshotarr), PointerGetDatum(snapshot));
1242 }
#define PointerGetDatum(X)
Definition: postgres.h:556
ResourceArray snapshotarr
Definition: resowner.c:128
static void ResourceArrayAdd(ResourceArray *resarr, Datum value)
Definition: resowner.c:266

◆ ResourceOwnerRememberTupleDesc()

void ResourceOwnerRememberTupleDesc ( ResourceOwner  owner,
TupleDesc  tupdesc 
)

Definition at line 1193 of file resowner.c.

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

Referenced by IncrTupleDescRefCount().

1194 {
1195  ResourceArrayAdd(&(owner->tupdescarr), PointerGetDatum(tupdesc));
1196 }
#define PointerGetDatum(X)
Definition: postgres.h:556
ResourceArray tupdescarr
Definition: resowner.c:127
static void ResourceArrayAdd(ResourceArray *resarr, Datum value)
Definition: resowner.c:266

◆ UnregisterResourceReleaseCallback()

void UnregisterResourceReleaseCallback ( ResourceReleaseCallback  callback,
void *  arg 
)

Definition at line 851 of file resowner.c.

References ResourceReleaseCallbackItem::next, and pfree().

852 {
855 
856  prev = NULL;
857  for (item = ResourceRelease_callbacks; item; prev = item, item = item->next)
858  {
859  if (item->callback == callback && item->arg == arg)
860  {
861  if (prev)
862  prev->next = item->next;
863  else
865  pfree(item);
866  break;
867  }
868  }
869 }
static ResourceReleaseCallbackItem * ResourceRelease_callbacks
Definition: resowner.c:159
void pfree(void *pointer)
Definition: mcxt.c:1057
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:48
struct ResourceReleaseCallbackItem * next
Definition: resowner.c:154
void * arg

Variable Documentation

◆ AuxProcessResourceOwner

ResourceOwner AuxProcessResourceOwner = NULL

◆ CurrentResourceOwner

ResourceOwner CurrentResourceOwner = NULL

Definition at line 144 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_eval_simple_expr(), exec_init_tuple_store(), exec_stmt_block(), extendBufFile(), FlushDatabaseBuffers(), FlushRelationBuffers(), FlushRelationsAllBuffers(), 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(), perform_base_backup(), PersistHoldablePortal(), pg_cryptohash_create(), 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(), ResourceOwnerReleaseAllPlanCacheRefs(), ResourceOwnerReleaseInternal(), SearchCatCacheInternal(), SearchCatCacheList(), SearchCatCacheMiss(), ShutdownXLOG(), SnapBuildClearExportedSnapshot(), SnapBuildExportSnapshot(), StartupXLOG(), tuplestore_begin_common(), tuplestore_puttuple_common(), UnpinBuffer(), UnregisterSnapshot(), and WalSndResourceCleanup().

◆ CurTransactionResourceOwner

◆ ResourceRelease_callbacks

ResourceReleaseCallbackItem* ResourceRelease_callbacks = NULL
static

Definition at line 159 of file resowner.c.

Referenced by RegisterResourceReleaseCallback().

◆ TopTransactionResourceOwner