PostgreSQL Source Code  git master
resowner.c File Reference
#include "postgres.h"
#include "common/cryptohash.h"
#include "common/hashfn.h"
#include "common/hmac.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)
 
static void PrintHMACLeakWarning (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)
 
void ResourceOwnerEnlargeHMAC (ResourceOwner owner)
 
void ResourceOwnerRememberHMAC (ResourceOwner owner, Datum handle)
 
void ResourceOwnerForgetHMAC (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 47 of file resowner.c.

Referenced by ResourceOwnerReleaseInternal().

◆ DatumGetFile

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

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

Referenced by ResourceArrayEnlarge().

◆ RESARRAY_IS_ARRAY

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

Definition at line 85 of file resowner.c.

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

◆ RESARRAY_MAX_ARRAY

#define RESARRAY_MAX_ARRAY   64

Definition at line 84 of file resowner.c.

◆ RESARRAY_MAX_ITEMS

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

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

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

Referenced by AuxiliaryProcessMain(), and InitPostgres().

888 {
890  Assert(CurrentResourceOwner == NULL);
891  AuxProcessResourceOwner = ResourceOwnerCreate(NULL, "AuxiliaryProcess");
893 
894  /*
895  * Register a shmem-exit callback for cleanup of aux-process resource
896  * owner. (This needs to run after, e.g., ShutdownXLOG.)
897  */
899 
900 }
ResourceOwner CurrentResourceOwner
Definition: resowner.c:146
ResourceOwner AuxProcessResourceOwner
Definition: resowner.c:149
static void ReleaseAuxProcessResourcesCallback(int code, Datum arg)
Definition: resowner.c:930
void on_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:361
#define Assert(condition)
Definition: c.h:804
ResourceOwner ResourceOwnerCreate(ResourceOwner parent, const char *name)
Definition: resowner.c:428

◆ PrintCryptoHashLeakWarning()

static void PrintCryptoHashLeakWarning ( Datum  handle)
static

Definition at line 1442 of file resowner.c.

References DatumGetPointer, elog, and WARNING.

Referenced by ResourceOwnerReleaseInternal().

1443 {
1444  elog(WARNING, "cryptohash context reference leak: context %p still referenced",
1445  DatumGetPointer(handle));
1446 }
#define WARNING
Definition: elog.h:40
#define DatumGetPointer(X)
Definition: postgres.h:593
#define elog(elevel,...)
Definition: elog.h:232

◆ PrintDSMLeakWarning()

static void PrintDSMLeakWarning ( dsm_segment seg)
static

Definition at line 1362 of file resowner.c.

References dsm_segment_handle(), elog, and WARNING.

Referenced by ResourceOwnerReleaseInternal().

1363 {
1364  elog(WARNING, "dynamic shared memory leak: segment %u still referenced",
1365  dsm_segment_handle(seg));
1366 }
dsm_handle dsm_segment_handle(dsm_segment *seg)
Definition: dsm.c:1087
#define WARNING
Definition: elog.h:40
#define elog(elevel,...)
Definition: elog.h:232

◆ PrintFileLeakWarning()

static void PrintFileLeakWarning ( File  file)
static

Definition at line 1317 of file resowner.c.

References elog, and WARNING.

Referenced by ResourceOwnerReleaseInternal().

1318 {
1319  elog(WARNING, "temporary file leak: File %d still referenced",
1320  file);
1321 }
#define WARNING
Definition: elog.h:40
#define elog(elevel,...)
Definition: elog.h:232

◆ PrintHMACLeakWarning()

static void PrintHMACLeakWarning ( Datum  handle)
static

Definition at line 1487 of file resowner.c.

References DatumGetPointer, elog, and WARNING.

Referenced by ResourceOwnerReleaseInternal().

1488 {
1489  elog(WARNING, "HMAC context reference leak: context %p still referenced",
1490  DatumGetPointer(handle));
1491 }
#define WARNING
Definition: elog.h:40
#define DatumGetPointer(X)
Definition: postgres.h:593
#define elog(elevel,...)
Definition: elog.h:232

◆ PrintPlanCacheLeakWarning()

static void PrintPlanCacheLeakWarning ( CachedPlan plan)
static

Definition at line 1181 of file resowner.c.

References elog, and WARNING.

Referenced by ResourceOwnerReleaseInternal().

1182 {
1183  elog(WARNING, "plancache reference leak: plan %p not closed", plan);
1184 }
#define WARNING
Definition: elog.h:40
#define elog(elevel,...)
Definition: elog.h:232

◆ PrintRelCacheLeakWarning()

static void PrintRelCacheLeakWarning ( Relation  rel)
static

Definition at line 1136 of file resowner.c.

References elog, RelationGetRelationName, and WARNING.

Referenced by ResourceOwnerReleaseInternal().

1137 {
1138  elog(WARNING, "relcache reference leak: relation \"%s\" not closed",
1140 }
#define RelationGetRelationName(relation)
Definition: rel.h:511
#define WARNING
Definition: elog.h:40
#define elog(elevel,...)
Definition: elog.h:232

◆ PrintSnapshotLeakWarning()

static void PrintSnapshotLeakWarning ( Snapshot  snapshot)
static

Definition at line 1271 of file resowner.c.

References elog, and WARNING.

Referenced by ResourceOwnerReleaseInternal().

1272 {
1273  elog(WARNING, "Snapshot reference leak: Snapshot %p still referenced",
1274  snapshot);
1275 }
#define WARNING
Definition: elog.h:40
#define elog(elevel,...)
Definition: elog.h:232

◆ PrintTupleDescLeakWarning()

static void PrintTupleDescLeakWarning ( TupleDesc  tupdesc)
static

Definition at line 1225 of file resowner.c.

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

Referenced by ResourceOwnerReleaseInternal().

1226 {
1227  elog(WARNING,
1228  "TupleDesc reference leak: TupleDesc %p (%u,%d) still referenced",
1229  tupdesc, tupdesc->tdtypeid, tupdesc->tdtypmod);
1230 }
int32 tdtypmod
Definition: tupdesc.h:83
#define WARNING
Definition: elog.h:40
Oid tdtypeid
Definition: tupdesc.h:82
#define elog(elevel,...)
Definition: elog.h:232

◆ RegisterResourceReleaseCallback()

void RegisterResourceReleaseCallback ( ResourceReleaseCallback  callback,
void *  arg 
)

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

850 {
852 
853  item = (ResourceReleaseCallbackItem *)
856  item->callback = callback;
857  item->arg = arg;
860 }
static ResourceReleaseCallbackItem * ResourceRelease_callbacks
Definition: resowner.c:161
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:48
MemoryContext TopMemoryContext
Definition: mcxt.c:48
struct ResourceReleaseCallbackItem * next
Definition: resowner.c:156
ResourceReleaseCallback callback
Definition: resowner.c:157
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:863
void * arg

◆ ReleaseAuxProcessResources()

void ReleaseAuxProcessResources ( bool  isCommit)

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

909 {
910  /*
911  * At this writing, the only thing that could actually get released is
912  * buffer pins; but we may as well do the full release protocol.
913  */
916  isCommit, true);
919  isCommit, true);
922  isCommit, true);
923 }
ResourceOwner AuxProcessResourceOwner
Definition: resowner.c:149
void ResourceOwnerRelease(ResourceOwner owner, ResourceReleasePhase phase, bool isCommit, bool isTopLevel)
Definition: resowner.c:486

◆ ReleaseAuxProcessResourcesCallback()

static void ReleaseAuxProcessResourcesCallback ( int  code,
Datum  arg 
)
static

Definition at line 930 of file resowner.c.

References ReleaseAuxProcessResources().

Referenced by CreateAuxProcessResourceOwner().

931 {
932  bool isCommit = (code == 0);
933 
934  ReleaseAuxProcessResources(isCommit);
935 }
void ReleaseAuxProcessResources(bool isCommit)
Definition: resowner.c:908

◆ ResourceArrayAdd()

static void ResourceArrayAdd ( ResourceArray resarr,
Datum  value 
)
static

Definition at line 269 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(), ResourceOwnerRememberHMAC(), ResourceOwnerRememberJIT(), ResourceOwnerRememberPlanCacheRef(), ResourceOwnerRememberRelationRef(), ResourceOwnerRememberSnapshot(), and ResourceOwnerRememberTupleDesc().

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

◆ ResourceArrayEnlarge()

static void ResourceArrayEnlarge ( ResourceArray resarr)
static

Definition at line 214 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(), ResourceOwnerEnlargeHMAC(), ResourceOwnerEnlargeJIT(), ResourceOwnerEnlargePlanCacheRefs(), ResourceOwnerEnlargeRelationRefs(), ResourceOwnerEnlargeSnapshots(), and ResourceOwnerEnlargeTupleDescs().

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

◆ ResourceArrayFree()

static void ResourceArrayFree ( ResourceArray resarr)
static

Definition at line 408 of file resowner.c.

References ResourceArray::itemsarr, and pfree().

Referenced by ResourceOwnerDelete().

409 {
410  if (resarr->itemsarr)
411  pfree(resarr->itemsarr);
412 }
void pfree(void *pointer)
Definition: mcxt.c:1169
Datum * itemsarr
Definition: resowner.c:67

◆ ResourceArrayGetAny()

static bool ResourceArrayGetAny ( ResourceArray resarr,
Datum value 
)
static

Definition at line 376 of file resowner.c.

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

Referenced by ResourceOwnerReleaseAllPlanCacheRefs(), and ResourceOwnerReleaseInternal().

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

◆ ResourceArrayInit()

static void ResourceArrayInit ( ResourceArray resarr,
Datum  invalidval 
)
static

Definition at line 195 of file resowner.c.

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

Referenced by ResourceOwnerCreate().

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

◆ ResourceArrayRemove()

static bool ResourceArrayRemove ( ResourceArray resarr,
Datum  value 
)
static

Definition at line 307 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(), ResourceOwnerForgetHMAC(), ResourceOwnerForgetJIT(), ResourceOwnerForgetPlanCacheRef(), ResourceOwnerForgetRelationRef(), ResourceOwnerForgetSnapshot(), and ResourceOwnerForgetTupleDesc().

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

◆ ResourceOwnerCreate()

ResourceOwner ResourceOwnerCreate ( ResourceOwner  parent,
const char *  name 
)

Definition at line 428 of file resowner.c.

References ResourceOwnerData::bufferarr, BufferGetDatum, ResourceOwnerData::catlistrefarr, ResourceOwnerData::catrefarr, ResourceOwnerData::cryptohasharr, ResourceOwnerData::dsmarr, ResourceOwnerData::filearr, FileGetDatum, ResourceOwnerData::firstchild, ResourceOwnerData::hmacarr, 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_call_handler(), plpgsql_create_econtext(), and plpgsql_inline_handler().

429 {
430  ResourceOwner owner;
431 
433  sizeof(ResourceOwnerData));
434  owner->name = name;
435 
436  if (parent)
437  {
438  owner->parent = parent;
439  owner->nextchild = parent->firstchild;
440  parent->firstchild = owner;
441  }
442 
444  ResourceArrayInit(&(owner->catrefarr), PointerGetDatum(NULL));
446  ResourceArrayInit(&(owner->relrefarr), PointerGetDatum(NULL));
447  ResourceArrayInit(&(owner->planrefarr), PointerGetDatum(NULL));
448  ResourceArrayInit(&(owner->tupdescarr), PointerGetDatum(NULL));
450  ResourceArrayInit(&(owner->filearr), FileGetDatum(-1));
451  ResourceArrayInit(&(owner->dsmarr), PointerGetDatum(NULL));
452  ResourceArrayInit(&(owner->jitarr), PointerGetDatum(NULL));
454  ResourceArrayInit(&(owner->hmacarr), PointerGetDatum(NULL));
455 
456  return owner;
457 }
ResourceArray relrefarr
Definition: resowner.c:126
ResourceArray catrefarr
Definition: resowner.c:124
#define PointerGetDatum(X)
Definition: postgres.h:600
#define InvalidBuffer
Definition: buf.h:25
ResourceArray bufferarr
Definition: resowner.c:123
ResourceArray snapshotarr
Definition: resowner.c:129
struct ResourceOwnerData * ResourceOwner
Definition: resowner.h:27
const char * name
Definition: resowner.c:120
ResourceArray planrefarr
Definition: resowner.c:127
ResourceArray tupdescarr
Definition: resowner.c:128
static void ResourceArrayInit(ResourceArray *resarr, Datum invalidval)
Definition: resowner.c:195
MemoryContext TopMemoryContext
Definition: mcxt.c:48
ResourceOwner firstchild
Definition: resowner.c:118
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition: mcxt.c:906
#define BufferGetDatum(buffer)
Definition: resowner.c:46
#define FileGetDatum(file)
Definition: resowner.c:44
ResourceArray jitarr
Definition: resowner.c:132
ResourceOwner parent
Definition: resowner.c:117
const char * name
Definition: encode.c:561
ResourceArray catlistrefarr
Definition: resowner.c:125
ResourceArray dsmarr
Definition: resowner.c:131
ResourceOwner nextchild
Definition: resowner.c:119
ResourceArray hmacarr
Definition: resowner.c:134
ResourceArray filearr
Definition: resowner.c:130
ResourceArray cryptohasharr
Definition: resowner.c:133

◆ ResourceOwnerDelete()

void ResourceOwnerDelete ( ResourceOwner  owner)

Definition at line 737 of file resowner.c.

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

738 {
739  /* We had better not be deleting CurrentResourceOwner ... */
740  Assert(owner != CurrentResourceOwner);
741 
742  /* And it better not own any resources, either */
743  Assert(owner->bufferarr.nitems == 0);
744  Assert(owner->catrefarr.nitems == 0);
745  Assert(owner->catlistrefarr.nitems == 0);
746  Assert(owner->relrefarr.nitems == 0);
747  Assert(owner->planrefarr.nitems == 0);
748  Assert(owner->tupdescarr.nitems == 0);
749  Assert(owner->snapshotarr.nitems == 0);
750  Assert(owner->filearr.nitems == 0);
751  Assert(owner->dsmarr.nitems == 0);
752  Assert(owner->jitarr.nitems == 0);
753  Assert(owner->cryptohasharr.nitems == 0);
754  Assert(owner->hmacarr.nitems == 0);
755  Assert(owner->nlocks == 0 || owner->nlocks == MAX_RESOWNER_LOCKS + 1);
756 
757  /*
758  * Delete children. The recursive call will delink the child from me, so
759  * just iterate as long as there is a child.
760  */
761  while (owner->firstchild != NULL)
763 
764  /*
765  * We delink the owner from its parent before deleting it, so that if
766  * there's an error we won't have deleted/busted owners still attached to
767  * the owner tree. Better a leak than a crash.
768  */
769  ResourceOwnerNewParent(owner, NULL);
770 
771  /* And free the object. */
772  ResourceArrayFree(&(owner->bufferarr));
773  ResourceArrayFree(&(owner->catrefarr));
774  ResourceArrayFree(&(owner->catlistrefarr));
775  ResourceArrayFree(&(owner->relrefarr));
776  ResourceArrayFree(&(owner->planrefarr));
777  ResourceArrayFree(&(owner->tupdescarr));
778  ResourceArrayFree(&(owner->snapshotarr));
779  ResourceArrayFree(&(owner->filearr));
780  ResourceArrayFree(&(owner->dsmarr));
781  ResourceArrayFree(&(owner->jitarr));
782  ResourceArrayFree(&(owner->cryptohasharr));
783  ResourceArrayFree(&(owner->hmacarr));
784 
785  pfree(owner);
786 }
ResourceArray relrefarr
Definition: resowner.c:126
ResourceArray catrefarr
Definition: resowner.c:124
ResourceOwner CurrentResourceOwner
Definition: resowner.c:146
void ResourceOwnerDelete(ResourceOwner owner)
Definition: resowner.c:737
ResourceArray bufferarr
Definition: resowner.c:123
ResourceArray snapshotarr
Definition: resowner.c:129
#define MAX_RESOWNER_LOCKS
Definition: resowner.c:110
void pfree(void *pointer)
Definition: mcxt.c:1169
ResourceArray planrefarr
Definition: resowner.c:127
static void ResourceArrayFree(ResourceArray *resarr)
Definition: resowner.c:408
ResourceArray tupdescarr
Definition: resowner.c:128
ResourceOwner firstchild
Definition: resowner.c:118
#define Assert(condition)
Definition: c.h:804
ResourceArray jitarr
Definition: resowner.c:132
void ResourceOwnerNewParent(ResourceOwner owner, ResourceOwner newparent)
Definition: resowner.c:801
ResourceArray catlistrefarr
Definition: resowner.c:125
ResourceArray dsmarr
Definition: resowner.c:131
uint32 nitems
Definition: resowner.c:70
ResourceArray hmacarr
Definition: resowner.c:134
ResourceArray filearr
Definition: resowner.c:130
ResourceArray cryptohasharr
Definition: resowner.c:133

◆ ResourceOwnerEnlargeBuffers()

void ResourceOwnerEnlargeBuffers ( ResourceOwner  owner)

Definition at line 946 of file resowner.c.

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

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

947 {
948  /* We used to allow pinning buffers without a resowner, but no more */
949  Assert(owner != NULL);
950  ResourceArrayEnlarge(&(owner->bufferarr));
951 }
static void ResourceArrayEnlarge(ResourceArray *resarr)
Definition: resowner.c:214
ResourceArray bufferarr
Definition: resowner.c:123
#define Assert(condition)
Definition: c.h:804

◆ ResourceOwnerEnlargeCatCacheListRefs()

void ResourceOwnerEnlargeCatCacheListRefs ( ResourceOwner  owner)

Definition at line 1070 of file resowner.c.

References ResourceOwnerData::catlistrefarr, and ResourceArrayEnlarge().

Referenced by SearchCatCacheList().

1071 {
1073 }
static void ResourceArrayEnlarge(ResourceArray *resarr)
Definition: resowner.c:214
ResourceArray catlistrefarr
Definition: resowner.c:125

◆ ResourceOwnerEnlargeCatCacheRefs()

void ResourceOwnerEnlargeCatCacheRefs ( ResourceOwner  owner)

Definition at line 1035 of file resowner.c.

References ResourceOwnerData::catrefarr, and ResourceArrayEnlarge().

Referenced by SearchCatCacheInternal(), and SearchCatCacheMiss().

1036 {
1037  ResourceArrayEnlarge(&(owner->catrefarr));
1038 }
static void ResourceArrayEnlarge(ResourceArray *resarr)
Definition: resowner.c:214
ResourceArray catrefarr
Definition: resowner.c:124

◆ ResourceOwnerEnlargeCryptoHash()

void ResourceOwnerEnlargeCryptoHash ( ResourceOwner  owner)

Definition at line 1411 of file resowner.c.

References ResourceOwnerData::cryptohasharr, and ResourceArrayEnlarge().

Referenced by pg_cryptohash_create().

1412 {
1414 }
static void ResourceArrayEnlarge(ResourceArray *resarr)
Definition: resowner.c:214
ResourceArray cryptohasharr
Definition: resowner.c:133

◆ ResourceOwnerEnlargeDSMs()

void ResourceOwnerEnlargeDSMs ( ResourceOwner  owner)

Definition at line 1331 of file resowner.c.

References ResourceOwnerData::dsmarr, and ResourceArrayEnlarge().

Referenced by dsm_create_descriptor(), and dsm_unpin_mapping().

1332 {
1333  ResourceArrayEnlarge(&(owner->dsmarr));
1334 }
static void ResourceArrayEnlarge(ResourceArray *resarr)
Definition: resowner.c:214
ResourceArray dsmarr
Definition: resowner.c:131

◆ ResourceOwnerEnlargeFiles()

void ResourceOwnerEnlargeFiles ( ResourceOwner  owner)

Definition at line 1286 of file resowner.c.

References ResourceOwnerData::filearr, and ResourceArrayEnlarge().

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

1287 {
1288  ResourceArrayEnlarge(&(owner->filearr));
1289 }
static void ResourceArrayEnlarge(ResourceArray *resarr)
Definition: resowner.c:214
ResourceArray filearr
Definition: resowner.c:130

◆ ResourceOwnerEnlargeHMAC()

void ResourceOwnerEnlargeHMAC ( ResourceOwner  owner)

Definition at line 1456 of file resowner.c.

References ResourceOwnerData::hmacarr, and ResourceArrayEnlarge().

Referenced by pg_hmac_create().

1457 {
1458  ResourceArrayEnlarge(&(owner->hmacarr));
1459 }
static void ResourceArrayEnlarge(ResourceArray *resarr)
Definition: resowner.c:214
ResourceArray hmacarr
Definition: resowner.c:134

◆ ResourceOwnerEnlargeJIT()

void ResourceOwnerEnlargeJIT ( ResourceOwner  owner)

Definition at line 1376 of file resowner.c.

References ResourceOwnerData::jitarr, and ResourceArrayEnlarge().

Referenced by llvm_create_context().

1377 {
1378  ResourceArrayEnlarge(&(owner->jitarr));
1379 }
static void ResourceArrayEnlarge(ResourceArray *resarr)
Definition: resowner.c:214
ResourceArray jitarr
Definition: resowner.c:132

◆ ResourceOwnerEnlargePlanCacheRefs()

void ResourceOwnerEnlargePlanCacheRefs ( ResourceOwner  owner)

Definition at line 1150 of file resowner.c.

References ResourceOwnerData::planrefarr, and ResourceArrayEnlarge().

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

1151 {
1152  ResourceArrayEnlarge(&(owner->planrefarr));
1153 }
static void ResourceArrayEnlarge(ResourceArray *resarr)
Definition: resowner.c:214
ResourceArray planrefarr
Definition: resowner.c:127

◆ ResourceOwnerEnlargeRelationRefs()

void ResourceOwnerEnlargeRelationRefs ( ResourceOwner  owner)

Definition at line 1105 of file resowner.c.

References ResourceOwnerData::relrefarr, and ResourceArrayEnlarge().

Referenced by RelationIncrementReferenceCount().

1106 {
1107  ResourceArrayEnlarge(&(owner->relrefarr));
1108 }
static void ResourceArrayEnlarge(ResourceArray *resarr)
Definition: resowner.c:214
ResourceArray relrefarr
Definition: resowner.c:126

◆ ResourceOwnerEnlargeSnapshots()

void ResourceOwnerEnlargeSnapshots ( ResourceOwner  owner)

Definition at line 1240 of file resowner.c.

References ResourceArrayEnlarge(), and ResourceOwnerData::snapshotarr.

Referenced by RegisterSnapshotOnOwner().

1241 {
1242  ResourceArrayEnlarge(&(owner->snapshotarr));
1243 }
static void ResourceArrayEnlarge(ResourceArray *resarr)
Definition: resowner.c:214
ResourceArray snapshotarr
Definition: resowner.c:129

◆ ResourceOwnerEnlargeTupleDescs()

void ResourceOwnerEnlargeTupleDescs ( ResourceOwner  owner)

Definition at line 1194 of file resowner.c.

References ResourceArrayEnlarge(), and ResourceOwnerData::tupdescarr.

Referenced by IncrTupleDescRefCount().

1195 {
1196  ResourceArrayEnlarge(&(owner->tupdescarr));
1197 }
static void ResourceArrayEnlarge(ResourceArray *resarr)
Definition: resowner.c:214
ResourceArray tupdescarr
Definition: resowner.c:128

◆ ResourceOwnerForgetBuffer()

void ResourceOwnerForgetBuffer ( ResourceOwner  owner,
Buffer  buffer 
)

Definition at line 968 of file resowner.c.

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

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

969 {
970  if (!ResourceArrayRemove(&(owner->bufferarr), BufferGetDatum(buffer)))
971  elog(ERROR, "buffer %d is not owned by resource owner %s",
972  buffer, owner->name);
973 }
ResourceArray bufferarr
Definition: resowner.c:123
const char * name
Definition: resowner.c:120
#define ERROR
Definition: elog.h:46
#define BufferGetDatum(buffer)
Definition: resowner.c:46
static bool ResourceArrayRemove(ResourceArray *resarr, Datum value)
Definition: resowner.c:307
#define elog(elevel,...)
Definition: elog.h:232

◆ ResourceOwnerForgetCatCacheListRef()

void ResourceOwnerForgetCatCacheListRef ( ResourceOwner  owner,
CatCList list 
)

Definition at line 1090 of file resowner.c.

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

Referenced by ReleaseCatCacheList().

1091 {
1092  if (!ResourceArrayRemove(&(owner->catlistrefarr), PointerGetDatum(list)))
1093  elog(ERROR, "catcache list reference %p is not owned by resource owner %s",
1094  list, owner->name);
1095 }
#define PointerGetDatum(X)
Definition: postgres.h:600
const char * name
Definition: resowner.c:120
#define ERROR
Definition: elog.h:46
static bool ResourceArrayRemove(ResourceArray *resarr, Datum value)
Definition: resowner.c:307
#define elog(elevel,...)
Definition: elog.h:232
ResourceArray catlistrefarr
Definition: resowner.c:125

◆ ResourceOwnerForgetCatCacheRef()

void ResourceOwnerForgetCatCacheRef ( ResourceOwner  owner,
HeapTuple  tuple 
)

Definition at line 1055 of file resowner.c.

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

Referenced by ReleaseCatCache().

1056 {
1057  if (!ResourceArrayRemove(&(owner->catrefarr), PointerGetDatum(tuple)))
1058  elog(ERROR, "catcache reference %p is not owned by resource owner %s",
1059  tuple, owner->name);
1060 }
ResourceArray catrefarr
Definition: resowner.c:124
#define PointerGetDatum(X)
Definition: postgres.h:600
const char * name
Definition: resowner.c:120
#define ERROR
Definition: elog.h:46
static bool ResourceArrayRemove(ResourceArray *resarr, Datum value)
Definition: resowner.c:307
#define elog(elevel,...)
Definition: elog.h:232

◆ ResourceOwnerForgetCryptoHash()

void ResourceOwnerForgetCryptoHash ( ResourceOwner  owner,
Datum  handle 
)

Definition at line 1431 of file resowner.c.

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

Referenced by pg_cryptohash_free().

1432 {
1433  if (!ResourceArrayRemove(&(owner->cryptohasharr), handle))
1434  elog(ERROR, "cryptohash context %p is not owned by resource owner %s",
1435  DatumGetPointer(handle), owner->name);
1436 }
const char * name
Definition: resowner.c:120
#define ERROR
Definition: elog.h:46
static bool ResourceArrayRemove(ResourceArray *resarr, Datum value)
Definition: resowner.c:307
#define DatumGetPointer(X)
Definition: postgres.h:593
#define elog(elevel,...)
Definition: elog.h:232
ResourceArray cryptohasharr
Definition: resowner.c:133

◆ ResourceOwnerForgetDSM()

void ResourceOwnerForgetDSM ( ResourceOwner  owner,
dsm_segment seg 
)

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

1352 {
1353  if (!ResourceArrayRemove(&(owner->dsmarr), PointerGetDatum(seg)))
1354  elog(ERROR, "dynamic shared memory segment %u is not owned by resource owner %s",
1355  dsm_segment_handle(seg), owner->name);
1356 }
#define PointerGetDatum(X)
Definition: postgres.h:600
dsm_handle dsm_segment_handle(dsm_segment *seg)
Definition: dsm.c:1087
const char * name
Definition: resowner.c:120
#define ERROR
Definition: elog.h:46
static bool ResourceArrayRemove(ResourceArray *resarr, Datum value)
Definition: resowner.c:307
#define elog(elevel,...)
Definition: elog.h:232
ResourceArray dsmarr
Definition: resowner.c:131

◆ ResourceOwnerForgetFile()

void ResourceOwnerForgetFile ( ResourceOwner  owner,
File  file 
)

Definition at line 1306 of file resowner.c.

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

Referenced by FileClose().

1307 {
1308  if (!ResourceArrayRemove(&(owner->filearr), FileGetDatum(file)))
1309  elog(ERROR, "temporary file %d is not owned by resource owner %s",
1310  file, owner->name);
1311 }
const char * name
Definition: resowner.c:120
#define ERROR
Definition: elog.h:46
#define FileGetDatum(file)
Definition: resowner.c:44
static bool ResourceArrayRemove(ResourceArray *resarr, Datum value)
Definition: resowner.c:307
#define elog(elevel,...)
Definition: elog.h:232
ResourceArray filearr
Definition: resowner.c:130

◆ ResourceOwnerForgetHMAC()

void ResourceOwnerForgetHMAC ( ResourceOwner  owner,
Datum  handle 
)

Definition at line 1476 of file resowner.c.

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

Referenced by pg_hmac_free().

1477 {
1478  if (!ResourceArrayRemove(&(owner->hmacarr), handle))
1479  elog(ERROR, "HMAC context %p is not owned by resource owner %s",
1480  DatumGetPointer(handle), owner->name);
1481 }
const char * name
Definition: resowner.c:120
#define ERROR
Definition: elog.h:46
static bool ResourceArrayRemove(ResourceArray *resarr, Datum value)
Definition: resowner.c:307
#define DatumGetPointer(X)
Definition: postgres.h:593
#define elog(elevel,...)
Definition: elog.h:232
ResourceArray hmacarr
Definition: resowner.c:134

◆ ResourceOwnerForgetJIT()

void ResourceOwnerForgetJIT ( ResourceOwner  owner,
Datum  handle 
)

Definition at line 1396 of file resowner.c.

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

Referenced by jit_release_context().

1397 {
1398  if (!ResourceArrayRemove(&(owner->jitarr), handle))
1399  elog(ERROR, "JIT context %p is not owned by resource owner %s",
1400  DatumGetPointer(handle), owner->name);
1401 }
const char * name
Definition: resowner.c:120
#define ERROR
Definition: elog.h:46
ResourceArray jitarr
Definition: resowner.c:132
static bool ResourceArrayRemove(ResourceArray *resarr, Datum value)
Definition: resowner.c:307
#define DatumGetPointer(X)
Definition: postgres.h:593
#define elog(elevel,...)
Definition: elog.h:232

◆ ResourceOwnerForgetLock()

void ResourceOwnerForgetLock ( ResourceOwner  owner,
LOCALLOCK locallock 
)

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

1007 {
1008  int i;
1009 
1010  if (owner->nlocks > MAX_RESOWNER_LOCKS)
1011  return; /* we have overflowed */
1012 
1013  Assert(owner->nlocks > 0);
1014  for (i = owner->nlocks - 1; i >= 0; i--)
1015  {
1016  if (locallock == owner->locks[i])
1017  {
1018  owner->locks[i] = owner->locks[owner->nlocks - 1];
1019  owner->nlocks--;
1020  return;
1021  }
1022  }
1023  elog(ERROR, "lock reference %p is not owned by resource owner %s",
1024  locallock, owner->name);
1025 }
#define MAX_RESOWNER_LOCKS
Definition: resowner.c:110
const char * name
Definition: resowner.c:120
#define ERROR
Definition: elog.h:46
#define Assert(condition)
Definition: c.h:804
LOCALLOCK * locks[MAX_RESOWNER_LOCKS]
Definition: resowner.c:138
#define elog(elevel,...)
Definition: elog.h:232
int i

◆ ResourceOwnerForgetPlanCacheRef()

void ResourceOwnerForgetPlanCacheRef ( ResourceOwner  owner,
CachedPlan plan 
)

Definition at line 1170 of file resowner.c.

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

Referenced by ReleaseCachedPlan().

1171 {
1172  if (!ResourceArrayRemove(&(owner->planrefarr), PointerGetDatum(plan)))
1173  elog(ERROR, "plancache reference %p is not owned by resource owner %s",
1174  plan, owner->name);
1175 }
#define PointerGetDatum(X)
Definition: postgres.h:600
const char * name
Definition: resowner.c:120
#define ERROR
Definition: elog.h:46
ResourceArray planrefarr
Definition: resowner.c:127
static bool ResourceArrayRemove(ResourceArray *resarr, Datum value)
Definition: resowner.c:307
#define elog(elevel,...)
Definition: elog.h:232

◆ ResourceOwnerForgetRelationRef()

void ResourceOwnerForgetRelationRef ( ResourceOwner  owner,
Relation  rel 
)

Definition at line 1125 of file resowner.c.

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

Referenced by RelationDecrementReferenceCount().

1126 {
1127  if (!ResourceArrayRemove(&(owner->relrefarr), PointerGetDatum(rel)))
1128  elog(ERROR, "relcache reference %s is not owned by resource owner %s",
1129  RelationGetRelationName(rel), owner->name);
1130 }
ResourceArray relrefarr
Definition: resowner.c:126
#define PointerGetDatum(X)
Definition: postgres.h:600
const char * name
Definition: resowner.c:120
#define ERROR
Definition: elog.h:46
#define RelationGetRelationName(relation)
Definition: rel.h:511
static bool ResourceArrayRemove(ResourceArray *resarr, Datum value)
Definition: resowner.c:307
#define elog(elevel,...)
Definition: elog.h:232

◆ ResourceOwnerForgetSnapshot()

void ResourceOwnerForgetSnapshot ( ResourceOwner  owner,
Snapshot  snapshot 
)

Definition at line 1260 of file resowner.c.

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

Referenced by UnregisterSnapshotFromOwner().

1261 {
1262  if (!ResourceArrayRemove(&(owner->snapshotarr), PointerGetDatum(snapshot)))
1263  elog(ERROR, "snapshot reference %p is not owned by resource owner %s",
1264  snapshot, owner->name);
1265 }
#define PointerGetDatum(X)
Definition: postgres.h:600
ResourceArray snapshotarr
Definition: resowner.c:129
const char * name
Definition: resowner.c:120
#define ERROR
Definition: elog.h:46
static bool ResourceArrayRemove(ResourceArray *resarr, Datum value)
Definition: resowner.c:307
#define elog(elevel,...)
Definition: elog.h:232

◆ ResourceOwnerForgetTupleDesc()

void ResourceOwnerForgetTupleDesc ( ResourceOwner  owner,
TupleDesc  tupdesc 
)

Definition at line 1214 of file resowner.c.

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

Referenced by DecrTupleDescRefCount().

1215 {
1216  if (!ResourceArrayRemove(&(owner->tupdescarr), PointerGetDatum(tupdesc)))
1217  elog(ERROR, "tupdesc reference %p is not owned by resource owner %s",
1218  tupdesc, owner->name);
1219 }
#define PointerGetDatum(X)
Definition: postgres.h:600
const char * name
Definition: resowner.c:120
#define ERROR
Definition: elog.h:46
ResourceArray tupdescarr
Definition: resowner.c:128
static bool ResourceArrayRemove(ResourceArray *resarr, Datum value)
Definition: resowner.c:307
#define elog(elevel,...)
Definition: elog.h:232

◆ ResourceOwnerGetParent()

ResourceOwner ResourceOwnerGetParent ( ResourceOwner  owner)

Definition at line 792 of file resowner.c.

References ResourceOwnerData::parent.

Referenced by LockReassignCurrentOwner().

793 {
794  return owner->parent;
795 }
ResourceOwner parent
Definition: resowner.c:117

◆ ResourceOwnerNewParent()

void ResourceOwnerNewParent ( ResourceOwner  owner,
ResourceOwner  newparent 
)

Definition at line 801 of file resowner.c.

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

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

803 {
804  ResourceOwner oldparent = owner->parent;
805 
806  if (oldparent)
807  {
808  if (owner == oldparent->firstchild)
809  oldparent->firstchild = owner->nextchild;
810  else
811  {
812  ResourceOwner child;
813 
814  for (child = oldparent->firstchild; child; child = child->nextchild)
815  {
816  if (owner == child->nextchild)
817  {
818  child->nextchild = owner->nextchild;
819  break;
820  }
821  }
822  }
823  }
824 
825  if (newparent)
826  {
827  Assert(owner != newparent);
828  owner->parent = newparent;
829  owner->nextchild = newparent->firstchild;
830  newparent->firstchild = owner;
831  }
832  else
833  {
834  owner->parent = NULL;
835  owner->nextchild = NULL;
836  }
837 }
ResourceOwner firstchild
Definition: resowner.c:118
#define Assert(condition)
Definition: c.h:804
ResourceOwner parent
Definition: resowner.c:117
ResourceOwner nextchild
Definition: resowner.c:119

◆ ResourceOwnerRelease()

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

Definition at line 486 of file resowner.c.

References ResourceOwnerReleaseInternal().

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

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

◆ ResourceOwnerReleaseAllPlanCacheRefs()

void ResourceOwnerReleaseAllPlanCacheRefs ( ResourceOwner  owner)

Definition at line 718 of file resowner.c.

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

Referenced by plpgsql_call_handler(), plpgsql_inline_handler(), and plpgsql_xact_cb().

719 {
720  Datum foundres;
721 
722  while (ResourceArrayGetAny(&(owner->planrefarr), &foundres))
723  {
724  CachedPlan *res = (CachedPlan *) DatumGetPointer(foundres);
725 
726  ReleaseCachedPlan(res, owner);
727  }
728 }
void ReleaseCachedPlan(CachedPlan *plan, ResourceOwner owner)
Definition: plancache.c:1264
static bool ResourceArrayGetAny(ResourceArray *resarr, Datum *value)
Definition: resowner.c:376
ResourceArray planrefarr
Definition: resowner.c:127
uintptr_t Datum
Definition: postgres.h:411
#define DatumGetPointer(X)
Definition: postgres.h:593

◆ ResourceOwnerReleaseInternal()

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

Definition at line 496 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, ResourceOwnerData::hmacarr, jit_release_context(), ResourceOwnerData::jitarr, LockReassignCurrentOwner(), LockReleaseCurrentOwner(), ResourceOwnerData::locks, MAX_RESOWNER_LOCKS, ResourceReleaseCallbackItem::next, ResourceOwnerData::nextchild, ResourceOwnerData::nlocks, ResourceOwnerData::parent, pg_cryptohash_free(), pg_hmac_free(), ResourceOwnerData::planrefarr, PointerGetDatum, PrintBufferLeakWarning(), PrintCatCacheLeakWarning(), PrintCatCacheListLeakWarning(), PrintCryptoHashLeakWarning(), PrintDSMLeakWarning(), PrintFileLeakWarning(), PrintHMACLeakWarning(), 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().

500 {
501  ResourceOwner child;
502  ResourceOwner save;
504  Datum foundres;
505 
506  /* Recurse to handle descendants */
507  for (child = owner->firstchild; child != NULL; child = child->nextchild)
508  ResourceOwnerReleaseInternal(child, phase, isCommit, isTopLevel);
509 
510  /*
511  * Make CurrentResourceOwner point to me, so that ReleaseBuffer etc don't
512  * get confused.
513  */
514  save = CurrentResourceOwner;
515  CurrentResourceOwner = owner;
516 
517  if (phase == RESOURCE_RELEASE_BEFORE_LOCKS)
518  {
519  /*
520  * Release buffer pins. Note that ReleaseBuffer will remove the
521  * buffer entry from our array, so we just have to iterate till there
522  * are none.
523  *
524  * During a commit, there shouldn't be any remaining pins --- that
525  * would indicate failure to clean up the executor correctly --- so
526  * issue warnings. In the abort case, just clean up quietly.
527  */
528  while (ResourceArrayGetAny(&(owner->bufferarr), &foundres))
529  {
530  Buffer res = DatumGetBuffer(foundres);
531 
532  if (isCommit)
534  ReleaseBuffer(res);
535  }
536 
537  /* Ditto for relcache references */
538  while (ResourceArrayGetAny(&(owner->relrefarr), &foundres))
539  {
540  Relation res = (Relation) DatumGetPointer(foundres);
541 
542  if (isCommit)
544  RelationClose(res);
545  }
546 
547  /* Ditto for dynamic shared memory segments */
548  while (ResourceArrayGetAny(&(owner->dsmarr), &foundres))
549  {
550  dsm_segment *res = (dsm_segment *) DatumGetPointer(foundres);
551 
552  if (isCommit)
553  PrintDSMLeakWarning(res);
554  dsm_detach(res);
555  }
556 
557  /* Ditto for JIT contexts */
558  while (ResourceArrayGetAny(&(owner->jitarr), &foundres))
559  {
560  JitContext *context = (JitContext *) PointerGetDatum(foundres);
561 
562  jit_release_context(context);
563  }
564 
565  /* Ditto for cryptohash contexts */
566  while (ResourceArrayGetAny(&(owner->cryptohasharr), &foundres))
567  {
568  pg_cryptohash_ctx *context =
569  (pg_cryptohash_ctx *) PointerGetDatum(foundres);
570 
571  if (isCommit)
572  PrintCryptoHashLeakWarning(foundres);
573  pg_cryptohash_free(context);
574  }
575 
576  /* Ditto for HMAC contexts */
577  while (ResourceArrayGetAny(&(owner->hmacarr), &foundres))
578  {
579  pg_hmac_ctx *context = (pg_hmac_ctx *) PointerGetDatum(foundres);
580 
581  if (isCommit)
582  PrintHMACLeakWarning(foundres);
583  pg_hmac_free(context);
584  }
585  }
586  else if (phase == RESOURCE_RELEASE_LOCKS)
587  {
588  if (isTopLevel)
589  {
590  /*
591  * For a top-level xact we are going to release all locks (or at
592  * least all non-session locks), so just do a single lmgr call at
593  * the top of the recursion.
594  */
595  if (owner == TopTransactionResourceOwner)
596  {
597  ProcReleaseLocks(isCommit);
598  ReleasePredicateLocks(isCommit, false);
599  }
600  }
601  else
602  {
603  /*
604  * Release locks retail. Note that if we are committing a
605  * subtransaction, we do NOT release its locks yet, but transfer
606  * them to the parent.
607  */
608  LOCALLOCK **locks;
609  int nlocks;
610 
611  Assert(owner->parent != NULL);
612 
613  /*
614  * Pass the list of locks owned by this resource owner to the lock
615  * manager, unless it has overflowed.
616  */
617  if (owner->nlocks > MAX_RESOWNER_LOCKS)
618  {
619  locks = NULL;
620  nlocks = 0;
621  }
622  else
623  {
624  locks = owner->locks;
625  nlocks = owner->nlocks;
626  }
627 
628  if (isCommit)
629  LockReassignCurrentOwner(locks, nlocks);
630  else
631  LockReleaseCurrentOwner(locks, nlocks);
632  }
633  }
634  else if (phase == RESOURCE_RELEASE_AFTER_LOCKS)
635  {
636  /*
637  * Release catcache references. Note that ReleaseCatCache will remove
638  * the catref entry from our array, so we just have to iterate till
639  * there are none.
640  *
641  * As with buffer pins, warn if any are left at commit time.
642  */
643  while (ResourceArrayGetAny(&(owner->catrefarr), &foundres))
644  {
645  HeapTuple res = (HeapTuple) DatumGetPointer(foundres);
646 
647  if (isCommit)
649  ReleaseCatCache(res);
650  }
651 
652  /* Ditto for catcache lists */
653  while (ResourceArrayGetAny(&(owner->catlistrefarr), &foundres))
654  {
655  CatCList *res = (CatCList *) DatumGetPointer(foundres);
656 
657  if (isCommit)
659  ReleaseCatCacheList(res);
660  }
661 
662  /* Ditto for plancache references */
663  while (ResourceArrayGetAny(&(owner->planrefarr), &foundres))
664  {
665  CachedPlan *res = (CachedPlan *) DatumGetPointer(foundres);
666 
667  if (isCommit)
669  ReleaseCachedPlan(res, owner);
670  }
671 
672  /* Ditto for tupdesc references */
673  while (ResourceArrayGetAny(&(owner->tupdescarr), &foundres))
674  {
675  TupleDesc res = (TupleDesc) DatumGetPointer(foundres);
676 
677  if (isCommit)
680  }
681 
682  /* Ditto for snapshot references */
683  while (ResourceArrayGetAny(&(owner->snapshotarr), &foundres))
684  {
685  Snapshot res = (Snapshot) DatumGetPointer(foundres);
686 
687  if (isCommit)
689  UnregisterSnapshot(res);
690  }
691 
692  /* Ditto for temporary files */
693  while (ResourceArrayGetAny(&(owner->filearr), &foundres))
694  {
695  File res = DatumGetFile(foundres);
696 
697  if (isCommit)
699  FileClose(res);
700  }
701  }
702 
703  /* Let add-on modules get a chance too */
704  for (item = ResourceRelease_callbacks; item; item = item->next)
705  item->callback(phase, isCommit, isTopLevel, item->arg);
706 
707  CurrentResourceOwner = save;
708 }
ResourceArray relrefarr
Definition: resowner.c:126
void PrintCatCacheListLeakWarning(CatCList *list)
Definition: catcache.c:2089
HeapTupleData * HeapTuple
Definition: htup.h:71
void PrintBufferLeakWarning(Buffer buffer)
Definition: bufmgr.c:2681
ResourceArray catrefarr
Definition: resowner.c:124
#define DatumGetFile(datum)
Definition: resowner.c:45
ResourceOwner TopTransactionResourceOwner
Definition: resowner.c:148
#define PointerGetDatum(X)
Definition: postgres.h:600
ResourceOwner CurrentResourceOwner
Definition: resowner.c:146
Definition: jit.h:54
void ReleaseCachedPlan(CachedPlan *plan, ResourceOwner owner)
Definition: plancache.c:1264
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3768
ResourceArray bufferarr
Definition: resowner.c:123
static bool ResourceArrayGetAny(ResourceArray *resarr, Datum *value)
Definition: resowner.c:376
ResourceArray snapshotarr
Definition: resowner.c:129
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:496
static ResourceReleaseCallbackItem * ResourceRelease_callbacks
Definition: resowner.c:161
void ReleaseCatCacheList(CatCList *list)
Definition: catcache.c:1784
#define MAX_RESOWNER_LOCKS
Definition: resowner.c:110
void LockReleaseCurrentOwner(LOCALLOCK **locallocks, int nlocks)
Definition: lock.c:2484
struct RelationData * Relation
Definition: relcache.h:26
static void PrintSnapshotLeakWarning(Snapshot snapshot)
Definition: resowner.c:1271
ResourceArray planrefarr
Definition: resowner.c:127
void LockReassignCurrentOwner(LOCALLOCK **locallocks, int nlocks)
Definition: lock.c:2579
static void PrintPlanCacheLeakWarning(CachedPlan *plan)
Definition: resowner.c:1181
ResourceArray tupdescarr
Definition: resowner.c:128
void ProcReleaseLocks(bool isCommit)
Definition: proc.c:792
void RelationClose(Relation relation)
Definition: relcache.c:2152
static void PrintHMACLeakWarning(Datum handle)
Definition: resowner.c:1487
void UnregisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:867
static void PrintRelCacheLeakWarning(Relation rel)
Definition: resowner.c:1136
void pg_hmac_free(pg_hmac_ctx *ctx)
Definition: hmac.c:260
struct ResourceReleaseCallbackItem * next
Definition: resowner.c:156
uintptr_t Datum
Definition: postgres.h:411
ResourceReleaseCallback callback
Definition: resowner.c:157
ResourceOwner firstchild
Definition: resowner.c:118
void PrintCatCacheLeakWarning(HeapTuple tuple)
Definition: catcache.c:2073
static void PrintTupleDescLeakWarning(TupleDesc tupdesc)
Definition: resowner.c:1225
void ReleaseCatCache(HeapTuple tuple)
Definition: catcache.c:1442
void FileClose(File file)
Definition: fd.c:1960
#define Assert(condition)
Definition: c.h:804
void DecrTupleDescRefCount(TupleDesc tupdesc)
Definition: tupdesc.c:384
ResourceArray jitarr
Definition: resowner.c:132
static void PrintFileLeakWarning(File file)
Definition: resowner.c:1317
ResourceOwner parent
Definition: resowner.c:117
#define DatumGetPointer(X)
Definition: postgres.h:593
void dsm_detach(dsm_segment *seg)
Definition: dsm.c:769
#define DatumGetBuffer(datum)
Definition: resowner.c:47
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:138
ResourceArray catlistrefarr
Definition: resowner.c:125
ResourceArray dsmarr
Definition: resowner.c:131
ResourceOwner nextchild
Definition: resowner.c:119
static void PrintDSMLeakWarning(dsm_segment *seg)
Definition: resowner.c:1362
void pg_cryptohash_free(pg_cryptohash_ctx *ctx)
Definition: cryptohash.c:216
int Buffer
Definition: buf.h:23
int File
Definition: fd.h:54
ResourceArray hmacarr
Definition: resowner.c:134
static void PrintCryptoHashLeakWarning(Datum handle)
Definition: resowner.c:1442
ResourceArray filearr
Definition: resowner.c:130
ResourceArray cryptohasharr
Definition: resowner.c:133

◆ ResourceOwnerRememberBuffer()

void ResourceOwnerRememberBuffer ( ResourceOwner  owner,
Buffer  buffer 
)

Definition at line 959 of file resowner.c.

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

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

960 {
961  ResourceArrayAdd(&(owner->bufferarr), BufferGetDatum(buffer));
962 }
ResourceArray bufferarr
Definition: resowner.c:123
#define BufferGetDatum(buffer)
Definition: resowner.c:46
static void ResourceArrayAdd(ResourceArray *resarr, Datum value)
Definition: resowner.c:269

◆ ResourceOwnerRememberCatCacheListRef()

void ResourceOwnerRememberCatCacheListRef ( ResourceOwner  owner,
CatCList list 
)

Definition at line 1081 of file resowner.c.

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

Referenced by SearchCatCacheList().

1082 {
1084 }
#define PointerGetDatum(X)
Definition: postgres.h:600
ResourceArray catlistrefarr
Definition: resowner.c:125
static void ResourceArrayAdd(ResourceArray *resarr, Datum value)
Definition: resowner.c:269

◆ ResourceOwnerRememberCatCacheRef()

void ResourceOwnerRememberCatCacheRef ( ResourceOwner  owner,
HeapTuple  tuple 
)

Definition at line 1046 of file resowner.c.

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

Referenced by SearchCatCacheInternal(), and SearchCatCacheMiss().

1047 {
1048  ResourceArrayAdd(&(owner->catrefarr), PointerGetDatum(tuple));
1049 }
ResourceArray catrefarr
Definition: resowner.c:124
#define PointerGetDatum(X)
Definition: postgres.h:600
static void ResourceArrayAdd(ResourceArray *resarr, Datum value)
Definition: resowner.c:269

◆ ResourceOwnerRememberCryptoHash()

void ResourceOwnerRememberCryptoHash ( ResourceOwner  owner,
Datum  handle 
)

Definition at line 1422 of file resowner.c.

References ResourceOwnerData::cryptohasharr, and ResourceArrayAdd().

Referenced by pg_cryptohash_create().

1423 {
1424  ResourceArrayAdd(&(owner->cryptohasharr), handle);
1425 }
static void ResourceArrayAdd(ResourceArray *resarr, Datum value)
Definition: resowner.c:269
ResourceArray cryptohasharr
Definition: resowner.c:133

◆ ResourceOwnerRememberDSM()

void ResourceOwnerRememberDSM ( ResourceOwner  owner,
dsm_segment seg 
)

Definition at line 1342 of file resowner.c.

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

Referenced by dsm_create_descriptor(), and dsm_unpin_mapping().

1343 {
1344  ResourceArrayAdd(&(owner->dsmarr), PointerGetDatum(seg));
1345 }
#define PointerGetDatum(X)
Definition: postgres.h:600
ResourceArray dsmarr
Definition: resowner.c:131
static void ResourceArrayAdd(ResourceArray *resarr, Datum value)
Definition: resowner.c:269

◆ ResourceOwnerRememberFile()

void ResourceOwnerRememberFile ( ResourceOwner  owner,
File  file 
)

Definition at line 1297 of file resowner.c.

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

Referenced by RegisterTemporaryFile().

1298 {
1299  ResourceArrayAdd(&(owner->filearr), FileGetDatum(file));
1300 }
#define FileGetDatum(file)
Definition: resowner.c:44
static void ResourceArrayAdd(ResourceArray *resarr, Datum value)
Definition: resowner.c:269
ResourceArray filearr
Definition: resowner.c:130

◆ ResourceOwnerRememberHMAC()

void ResourceOwnerRememberHMAC ( ResourceOwner  owner,
Datum  handle 
)

Definition at line 1467 of file resowner.c.

References ResourceOwnerData::hmacarr, and ResourceArrayAdd().

Referenced by pg_hmac_create().

1468 {
1469  ResourceArrayAdd(&(owner->hmacarr), handle);
1470 }
static void ResourceArrayAdd(ResourceArray *resarr, Datum value)
Definition: resowner.c:269
ResourceArray hmacarr
Definition: resowner.c:134

◆ ResourceOwnerRememberJIT()

void ResourceOwnerRememberJIT ( ResourceOwner  owner,
Datum  handle 
)

Definition at line 1387 of file resowner.c.

References ResourceOwnerData::jitarr, and ResourceArrayAdd().

Referenced by llvm_create_context().

1388 {
1389  ResourceArrayAdd(&(owner->jitarr), handle);
1390 }
ResourceArray jitarr
Definition: resowner.c:132
static void ResourceArrayAdd(ResourceArray *resarr, Datum value)
Definition: resowner.c:269

◆ ResourceOwnerRememberLock()

void ResourceOwnerRememberLock ( ResourceOwner  owner,
LOCALLOCK locallock 
)

Definition at line 986 of file resowner.c.

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

Referenced by GrantLockLocal(), and LockReassignOwner().

987 {
988  Assert(locallock != NULL);
989 
990  if (owner->nlocks > MAX_RESOWNER_LOCKS)
991  return; /* we have already overflowed */
992 
993  if (owner->nlocks < MAX_RESOWNER_LOCKS)
994  owner->locks[owner->nlocks] = locallock;
995  else
996  {
997  /* overflowed */
998  }
999  owner->nlocks++;
1000 }
#define MAX_RESOWNER_LOCKS
Definition: resowner.c:110
#define Assert(condition)
Definition: c.h:804
LOCALLOCK * locks[MAX_RESOWNER_LOCKS]
Definition: resowner.c:138

◆ ResourceOwnerRememberPlanCacheRef()

void ResourceOwnerRememberPlanCacheRef ( ResourceOwner  owner,
CachedPlan plan 
)

Definition at line 1161 of file resowner.c.

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

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

1162 {
1163  ResourceArrayAdd(&(owner->planrefarr), PointerGetDatum(plan));
1164 }
#define PointerGetDatum(X)
Definition: postgres.h:600
ResourceArray planrefarr
Definition: resowner.c:127
static void ResourceArrayAdd(ResourceArray *resarr, Datum value)
Definition: resowner.c:269

◆ ResourceOwnerRememberRelationRef()

void ResourceOwnerRememberRelationRef ( ResourceOwner  owner,
Relation  rel 
)

Definition at line 1116 of file resowner.c.

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

Referenced by RelationIncrementReferenceCount().

1117 {
1118  ResourceArrayAdd(&(owner->relrefarr), PointerGetDatum(rel));
1119 }
ResourceArray relrefarr
Definition: resowner.c:126
#define PointerGetDatum(X)
Definition: postgres.h:600
static void ResourceArrayAdd(ResourceArray *resarr, Datum value)
Definition: resowner.c:269

◆ ResourceOwnerRememberSnapshot()

void ResourceOwnerRememberSnapshot ( ResourceOwner  owner,
Snapshot  snapshot 
)

Definition at line 1251 of file resowner.c.

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

Referenced by RegisterSnapshotOnOwner().

1252 {
1253  ResourceArrayAdd(&(owner->snapshotarr), PointerGetDatum(snapshot));
1254 }
#define PointerGetDatum(X)
Definition: postgres.h:600
ResourceArray snapshotarr
Definition: resowner.c:129
static void ResourceArrayAdd(ResourceArray *resarr, Datum value)
Definition: resowner.c:269

◆ ResourceOwnerRememberTupleDesc()

void ResourceOwnerRememberTupleDesc ( ResourceOwner  owner,
TupleDesc  tupdesc 
)

Definition at line 1205 of file resowner.c.

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

Referenced by IncrTupleDescRefCount().

1206 {
1207  ResourceArrayAdd(&(owner->tupdescarr), PointerGetDatum(tupdesc));
1208 }
#define PointerGetDatum(X)
Definition: postgres.h:600
ResourceArray tupdescarr
Definition: resowner.c:128
static void ResourceArrayAdd(ResourceArray *resarr, Datum value)
Definition: resowner.c:269

◆ UnregisterResourceReleaseCallback()

void UnregisterResourceReleaseCallback ( ResourceReleaseCallback  callback,
void *  arg 
)

Definition at line 863 of file resowner.c.

References ResourceReleaseCallbackItem::next, and pfree().

864 {
867 
868  prev = NULL;
869  for (item = ResourceRelease_callbacks; item; prev = item, item = item->next)
870  {
871  if (item->callback == callback && item->arg == arg)
872  {
873  if (prev)
874  prev->next = item->next;
875  else
877  pfree(item);
878  break;
879  }
880  }
881 }
static ResourceReleaseCallbackItem * ResourceRelease_callbacks
Definition: resowner.c:161
void pfree(void *pointer)
Definition: mcxt.c:1169
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:48
struct ResourceReleaseCallbackItem * next
Definition: resowner.c:156
void * arg

Variable Documentation

◆ AuxProcessResourceOwner

ResourceOwner AuxProcessResourceOwner = NULL

◆ CurrentResourceOwner

ResourceOwner CurrentResourceOwner = NULL

Definition at line 146 of file resowner.c.

Referenced by _SPI_execute_plan(), 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_simple_check_plan(), exec_stmt_block(), ExplainExecuteQuery(), extendBufFile(), FlushDatabaseBuffers(), FlushRelationBuffers(), FlushRelationsAllBuffers(), 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_hmac_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(), ReadRecentBuffer(), RegisterSnapshot(), RegisterTemporaryFile(), RelationDecrementReferenceCount(), RelationIncrementReferenceCount(), ReleaseAndReadBuffer(), ReleaseBuffer(), ReleaseCatCache(), ReleaseCatCacheList(), ReleaseLockIfHeld(), ResourceOwnerReleaseInternal(), SearchCatCacheInternal(), SearchCatCacheList(), SearchCatCacheMiss(), ShutdownXLOG(), SnapBuildClearExportedSnapshot(), SnapBuildExportSnapshot(), SPI_plan_get_cached_plan(), StartupXLOG(), tuplestore_begin_common(), tuplestore_puttuple_common(), UnpinBuffer(), UnregisterSnapshot(), and WalSndResourceCleanup().

◆ CurTransactionResourceOwner

◆ ResourceRelease_callbacks

ResourceReleaseCallbackItem* ResourceRelease_callbacks = NULL
static

Definition at line 161 of file resowner.c.

Referenced by RegisterResourceReleaseCallback().

◆ TopTransactionResourceOwner