PostgreSQL Source Code  git master
resowner.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ResourceOwnerDesc
 

Macros

#define RELEASE_PRIO_BUFFER_IOS   100
 
#define RELEASE_PRIO_BUFFER_PINS   200
 
#define RELEASE_PRIO_RELCACHE_REFS   300
 
#define RELEASE_PRIO_DSMS   400
 
#define RELEASE_PRIO_JIT_CONTEXTS   500
 
#define RELEASE_PRIO_CRYPTOHASH_CONTEXTS   600
 
#define RELEASE_PRIO_HMAC_CONTEXTS   700
 
#define RELEASE_PRIO_CATCACHE_REFS   100
 
#define RELEASE_PRIO_CATCACHE_LIST_REFS   200
 
#define RELEASE_PRIO_PLANCACHE_REFS   300
 
#define RELEASE_PRIO_TUPDESC_REFS   400
 
#define RELEASE_PRIO_SNAPSHOT_REFS   500
 
#define RELEASE_PRIO_FILES   600
 
#define RELEASE_PRIO_WAITEVENTSETS   700
 
#define RELEASE_PRIO_FIRST   1
 
#define RELEASE_PRIO_LAST   UINT32_MAX
 

Typedefs

typedef struct ResourceOwnerDataResourceOwner
 
typedef uint32 ResourceReleasePriority
 
typedef struct ResourceOwnerDesc ResourceOwnerDesc
 
typedef void(* ResourceReleaseCallback) (ResourceReleasePhase phase, bool isCommit, bool isTopLevel, void *arg)
 

Enumerations

enum  ResourceReleasePhase { RESOURCE_RELEASE_BEFORE_LOCKS = 1 , RESOURCE_RELEASE_LOCKS , RESOURCE_RELEASE_AFTER_LOCKS }
 

Functions

ResourceOwner ResourceOwnerCreate (ResourceOwner parent, const char *name)
 
void ResourceOwnerRelease (ResourceOwner owner, ResourceReleasePhase phase, bool isCommit, bool isTopLevel)
 
void ResourceOwnerDelete (ResourceOwner owner)
 
ResourceOwner ResourceOwnerGetParent (ResourceOwner owner)
 
void ResourceOwnerNewParent (ResourceOwner owner, ResourceOwner newparent)
 
void ResourceOwnerEnlarge (ResourceOwner owner)
 
void ResourceOwnerRemember (ResourceOwner owner, Datum value, const ResourceOwnerDesc *kind)
 
void ResourceOwnerForget (ResourceOwner owner, Datum value, const ResourceOwnerDesc *kind)
 
void ResourceOwnerReleaseAllOfKind (ResourceOwner owner, const ResourceOwnerDesc *kind)
 
void RegisterResourceReleaseCallback (ResourceReleaseCallback callback, void *arg)
 
void UnregisterResourceReleaseCallback (ResourceReleaseCallback callback, void *arg)
 
void CreateAuxProcessResourceOwner (void)
 
void ReleaseAuxProcessResources (bool isCommit)
 
void ResourceOwnerRememberLock (ResourceOwner owner, struct LOCALLOCK *locallock)
 
void ResourceOwnerForgetLock (ResourceOwner owner, struct LOCALLOCK *locallock)
 

Variables

PGDLLIMPORT ResourceOwner CurrentResourceOwner
 
PGDLLIMPORT ResourceOwner CurTransactionResourceOwner
 
PGDLLIMPORT ResourceOwner TopTransactionResourceOwner
 
PGDLLIMPORT ResourceOwner AuxProcessResourceOwner
 

Macro Definition Documentation

◆ RELEASE_PRIO_BUFFER_IOS

#define RELEASE_PRIO_BUFFER_IOS   100

Definition at line 62 of file resowner.h.

◆ RELEASE_PRIO_BUFFER_PINS

#define RELEASE_PRIO_BUFFER_PINS   200

Definition at line 63 of file resowner.h.

◆ RELEASE_PRIO_CATCACHE_LIST_REFS

#define RELEASE_PRIO_CATCACHE_LIST_REFS   200

Definition at line 72 of file resowner.h.

◆ RELEASE_PRIO_CATCACHE_REFS

#define RELEASE_PRIO_CATCACHE_REFS   100

Definition at line 71 of file resowner.h.

◆ RELEASE_PRIO_CRYPTOHASH_CONTEXTS

#define RELEASE_PRIO_CRYPTOHASH_CONTEXTS   600

Definition at line 67 of file resowner.h.

◆ RELEASE_PRIO_DSMS

#define RELEASE_PRIO_DSMS   400

Definition at line 65 of file resowner.h.

◆ RELEASE_PRIO_FILES

#define RELEASE_PRIO_FILES   600

Definition at line 76 of file resowner.h.

◆ RELEASE_PRIO_FIRST

#define RELEASE_PRIO_FIRST   1

Definition at line 80 of file resowner.h.

◆ RELEASE_PRIO_HMAC_CONTEXTS

#define RELEASE_PRIO_HMAC_CONTEXTS   700

Definition at line 68 of file resowner.h.

◆ RELEASE_PRIO_JIT_CONTEXTS

#define RELEASE_PRIO_JIT_CONTEXTS   500

Definition at line 66 of file resowner.h.

◆ RELEASE_PRIO_LAST

#define RELEASE_PRIO_LAST   UINT32_MAX

Definition at line 81 of file resowner.h.

◆ RELEASE_PRIO_PLANCACHE_REFS

#define RELEASE_PRIO_PLANCACHE_REFS   300

Definition at line 73 of file resowner.h.

◆ RELEASE_PRIO_RELCACHE_REFS

#define RELEASE_PRIO_RELCACHE_REFS   300

Definition at line 64 of file resowner.h.

◆ RELEASE_PRIO_SNAPSHOT_REFS

#define RELEASE_PRIO_SNAPSHOT_REFS   500

Definition at line 75 of file resowner.h.

◆ RELEASE_PRIO_TUPDESC_REFS

#define RELEASE_PRIO_TUPDESC_REFS   400

Definition at line 74 of file resowner.h.

◆ RELEASE_PRIO_WAITEVENTSETS

#define RELEASE_PRIO_WAITEVENTSETS   700

Definition at line 77 of file resowner.h.

Typedef Documentation

◆ ResourceOwner

Definition at line 27 of file resowner.h.

◆ ResourceOwnerDesc

◆ ResourceReleaseCallback

typedef void(* ResourceReleaseCallback) (ResourceReleasePhase phase, bool isCommit, bool isTopLevel, void *arg)

Definition at line 126 of file resowner.h.

◆ ResourceReleasePriority

Definition at line 59 of file resowner.h.

Enumeration Type Documentation

◆ ResourceReleasePhase

Enumerator
RESOURCE_RELEASE_BEFORE_LOCKS 
RESOURCE_RELEASE_LOCKS 
RESOURCE_RELEASE_AFTER_LOCKS 

Definition at line 52 of file resowner.h.

53 {
ResourceReleasePhase
Definition: resowner.h:53
@ RESOURCE_RELEASE_LOCKS
Definition: resowner.h:55
@ RESOURCE_RELEASE_BEFORE_LOCKS
Definition: resowner.h:54
@ RESOURCE_RELEASE_AFTER_LOCKS
Definition: resowner.h:56

Function Documentation

◆ CreateAuxProcessResourceOwner()

void CreateAuxProcessResourceOwner ( void  )

Definition at line 982 of file resowner.c.

983 {
985  Assert(CurrentResourceOwner == NULL);
986  AuxProcessResourceOwner = ResourceOwnerCreate(NULL, "AuxiliaryProcess");
988 
989  /*
990  * Register a shmem-exit callback for cleanup of aux-process resource
991  * owner. (This needs to run after, e.g., ShutdownXLOG.)
992  */
994 }
#define Assert(condition)
Definition: c.h:861
void on_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:365
static void ReleaseAuxProcessResourcesCallback(int code, Datum arg)
Definition: resowner.c:1027
ResourceOwner ResourceOwnerCreate(ResourceOwner parent, const char *name)
Definition: resowner.c:413
ResourceOwner CurrentResourceOwner
Definition: resowner.c:165
ResourceOwner AuxProcessResourceOwner
Definition: resowner.c:168

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

Referenced by AuxiliaryProcessMainCommon(), and InitPostgres().

◆ RegisterResourceReleaseCallback()

void RegisterResourceReleaseCallback ( ResourceReleaseCallback  callback,
void *  arg 
)

Definition at line 944 of file resowner.c.

945 {
947 
948  item = (ResourceReleaseCallbackItem *)
951  item->callback = callback;
952  item->arg = arg;
955 }
MemoryContext TopMemoryContext
Definition: mcxt.c:149
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:1181
void * arg
static ResourceReleaseCallbackItem * ResourceRelease_callbacks
Definition: resowner.c:187
struct ResourceReleaseCallbackItem * next
Definition: resowner.c:182
ResourceReleaseCallback callback
Definition: resowner.c:183
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:46

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

◆ ReleaseAuxProcessResources()

void ReleaseAuxProcessResources ( bool  isCommit)

Definition at line 1002 of file resowner.c.

1003 {
1004  /*
1005  * At this writing, the only thing that could actually get released is
1006  * buffer pins; but we may as well do the full release protocol.
1007  */
1010  isCommit, true);
1013  isCommit, true);
1016  isCommit, true);
1017  /* allow it to be reused */
1020 }
void ResourceOwnerRelease(ResourceOwner owner, ResourceReleasePhase phase, bool isCommit, bool isTopLevel)
Definition: resowner.c:648

References AuxProcessResourceOwner, ResourceOwnerData::releasing, RESOURCE_RELEASE_AFTER_LOCKS, RESOURCE_RELEASE_BEFORE_LOCKS, RESOURCE_RELEASE_LOCKS, ResourceOwnerRelease(), and ResourceOwnerData::sorted.

Referenced by BackgroundWriterMain(), CheckpointerMain(), InitPostgres(), perform_base_backup(), pgarch_archiveXlog(), ReleaseAuxProcessResourcesCallback(), UploadManifest(), WalSndErrorCleanup(), WalSummarizerMain(), and WalWriterMain().

◆ ResourceOwnerCreate()

ResourceOwner ResourceOwnerCreate ( ResourceOwner  parent,
const char *  name 
)

Definition at line 413 of file resowner.c.

414 {
415  ResourceOwner owner;
416 
418  sizeof(struct ResourceOwnerData));
419  owner->name = name;
420 
421  if (parent)
422  {
423  owner->parent = parent;
424  owner->nextchild = parent->firstchild;
425  parent->firstchild = owner;
426  }
427 
428  return owner;
429 }
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition: mcxt.c:1215
struct ResourceOwnerData * ResourceOwner
Definition: resowner.h:27
ResourceOwner parent
Definition: resowner.c:112
const char * name
Definition: resowner.c:115
ResourceOwner nextchild
Definition: resowner.c:114
ResourceOwner firstchild
Definition: resowner.c:113
const char * name

References ResourceOwnerData::firstchild, MemoryContextAllocZero(), name, ResourceOwnerData::name, ResourceOwnerData::nextchild, ResourceOwnerData::parent, and TopMemoryContext.

Referenced by AtStart_ResourceOwner(), AtSubStart_ResourceOwner(), CreateAuxProcessResourceOwner(), CreatePortal(), plpgsql_call_handler(), plpgsql_create_econtext(), plpgsql_inline_handler(), test_dsa_resowners(), test_resowner_forget_between_phases(), test_resowner_leak(), test_resowner_many(), test_resowner_priorities(), and test_resowner_remember_between_phases().

◆ ResourceOwnerDelete()

void ResourceOwnerDelete ( ResourceOwner  owner)

Definition at line 854 of file resowner.c.

855 {
856  /* We had better not be deleting CurrentResourceOwner ... */
857  Assert(owner != CurrentResourceOwner);
858 
859  /* And it better not own any resources, either */
860  Assert(owner->narr == 0);
861  Assert(owner->nhash == 0);
862  Assert(owner->nlocks == 0 || owner->nlocks == MAX_RESOWNER_LOCKS + 1);
863 
864  /*
865  * Delete children. The recursive call will delink the child from me, so
866  * just iterate as long as there is a child.
867  */
868  while (owner->firstchild != NULL)
870 
871  /*
872  * We delink the owner from its parent before deleting it, so that if
873  * there's an error we won't have deleted/busted owners still attached to
874  * the owner tree. Better a leak than a crash.
875  */
876  ResourceOwnerNewParent(owner, NULL);
877 
878  /* And free the object. */
879  if (owner->hash)
880  pfree(owner->hash);
881  pfree(owner);
882 }
void pfree(void *pointer)
Definition: mcxt.c:1521
void ResourceOwnerNewParent(ResourceOwner owner, ResourceOwner newparent)
Definition: resowner.c:897
#define MAX_RESOWNER_LOCKS
Definition: resowner.c:105
void ResourceOwnerDelete(ResourceOwner owner)
Definition: resowner.c:854
ResourceElem * hash
Definition: resowner.c:152

References Assert, CurrentResourceOwner, ResourceOwnerData::firstchild, ResourceOwnerData::hash, MAX_RESOWNER_LOCKS, ResourceOwnerData::narr, ResourceOwnerData::nhash, ResourceOwnerData::nlocks, pfree(), and ResourceOwnerNewParent().

Referenced by CleanupSubTransaction(), CleanupTransaction(), CommitSubTransaction(), CommitTransaction(), plpgsql_call_handler(), plpgsql_inline_handler(), PortalDrop(), PrepareTransaction(), test_dsa_resowners(), test_resowner_leak(), test_resowner_many(), and test_resowner_priorities().

◆ ResourceOwnerEnlarge()

void ResourceOwnerEnlarge ( ResourceOwner  owner)

Definition at line 442 of file resowner.c.

443 {
444  /*
445  * Mustn't try to remember more resources after we have already started
446  * releasing
447  */
448  if (owner->releasing)
449  elog(ERROR, "ResourceOwnerEnlarge called after release started");
450 
451  if (owner->narr < RESOWNER_ARRAY_SIZE)
452  return; /* no work needed */
453 
454  /*
455  * Is there space in the hash? If not, enlarge it.
456  */
457  if (owner->narr + owner->nhash >= owner->grow_at)
458  {
459  uint32 i,
460  oldcap,
461  newcap;
462  ResourceElem *oldhash;
463  ResourceElem *newhash;
464 
465  oldhash = owner->hash;
466  oldcap = owner->capacity;
467 
468  /* Double the capacity (it must stay a power of 2!) */
469  newcap = (oldcap > 0) ? oldcap * 2 : RESOWNER_HASH_INIT_SIZE;
471  newcap * sizeof(ResourceElem));
472 
473  /*
474  * We assume we can't fail below this point, so OK to scribble on the
475  * owner
476  */
477  owner->hash = newhash;
478  owner->capacity = newcap;
479  owner->grow_at = RESOWNER_HASH_MAX_ITEMS(newcap);
480  owner->nhash = 0;
481 
482  if (oldhash != NULL)
483  {
484  /*
485  * Transfer any pre-existing entries into the new hash table; they
486  * don't necessarily go where they were before, so this simple
487  * logic is the best way.
488  */
489  for (i = 0; i < oldcap; i++)
490  {
491  if (oldhash[i].kind != NULL)
492  ResourceOwnerAddToHash(owner, oldhash[i].item, oldhash[i].kind);
493  }
494 
495  /* And release old hash table. */
496  pfree(oldhash);
497  }
498  }
499 
500  /* Move items from the array to the hash */
501  for (int i = 0; i < owner->narr; i++)
502  ResourceOwnerAddToHash(owner, owner->arr[i].item, owner->arr[i].kind);
503  owner->narr = 0;
504 
505  Assert(owner->nhash <= owner->grow_at);
506 }
unsigned int uint32
Definition: c.h:518
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:225
int i
Definition: isn.c:72
#define RESOWNER_HASH_INIT_SIZE
Definition: resowner.c:77
#define RESOWNER_HASH_MAX_ITEMS(capacity)
Definition: resowner.c:89
static void ResourceOwnerAddToHash(ResourceOwner owner, Datum value, const ResourceOwnerDesc *kind)
Definition: resowner.c:237
#define RESOWNER_ARRAY_SIZE
Definition: resowner.c:71
Datum item
Definition: resowner.c:64
const ResourceOwnerDesc * kind
Definition: resowner.c:65
ResourceElem arr[RESOWNER_ARRAY_SIZE]
Definition: resowner.c:140

References ResourceOwnerData::arr, Assert, ResourceOwnerData::capacity, elog, ERROR, ResourceOwnerData::grow_at, ResourceOwnerData::hash, i, ResourceElem::item, ResourceElem::kind, MemoryContextAllocZero(), ResourceOwnerData::narr, ResourceOwnerData::nhash, pfree(), ResourceOwnerData::releasing, ResourceOwnerAddToHash(), RESOWNER_ARRAY_SIZE, RESOWNER_HASH_INIT_SIZE, RESOWNER_HASH_MAX_ITEMS, and TopMemoryContext.

Referenced by BufferAlloc(), CachedPlanAllowsSimpleValidityCheck(), CachedPlanIsSimplyValid(), CreateWaitEventSet(), dsm_create_descriptor(), dsm_unpin_mapping(), EvictUnpinnedBuffer(), ExtendBufferedRelLocal(), ExtendBufferedRelShared(), FlushDatabaseBuffers(), FlushRelationBuffers(), FlushRelationsAllBuffers(), GetCachedPlan(), GetLocalVictimBuffer(), GetVictimBuffer(), IncrBufferRefCount(), IncrTupleDescRefCount(), llvm_create_context(), LocalBufferAlloc(), OpenTemporaryFile(), PathNameCreateTemporaryFile(), PathNameOpenTemporaryFile(), pg_cryptohash_create(), pg_hmac_create(), px_find_cipher(), px_find_digest(), ReadRecentBuffer(), RegisterSnapshotOnOwner(), RelationIncrementReferenceCount(), RememberManyTestResources(), SearchCatCacheInternal(), SearchCatCacheList(), SearchCatCacheMiss(), StartBufferIO(), SyncOneBuffer(), test_resowner_forget_between_phases(), test_resowner_leak(), test_resowner_priorities(), and test_resowner_remember_between_phases().

◆ ResourceOwnerForget()

void ResourceOwnerForget ( ResourceOwner  owner,
Datum  value,
const ResourceOwnerDesc kind 
)

Definition at line 554 of file resowner.c.

555 {
556  /*
557  * Mustn't call this after we have already started releasing resources.
558  * (Release callback functions are not allowed to release additional
559  * resources.)
560  */
561  if (owner->releasing)
562  elog(ERROR, "ResourceOwnerForget called for %s after release started", kind->name);
563  Assert(!owner->sorted);
564 
565  /* Search through all items in the array first. */
566  for (int i = owner->narr - 1; i >= 0; i--)
567  {
568  if (owner->arr[i].item == value &&
569  owner->arr[i].kind == kind)
570  {
571  owner->arr[i] = owner->arr[owner->narr - 1];
572  owner->narr--;
573 
574 #ifdef RESOWNER_STATS
575  narray_lookups++;
576 #endif
577  return;
578  }
579  }
580 
581  /* Search hash */
582  if (owner->nhash > 0)
583  {
584  uint32 mask = owner->capacity - 1;
585  uint32 idx;
586 
587  idx = hash_resource_elem(value, kind) & mask;
588  for (uint32 i = 0; i < owner->capacity; i++)
589  {
590  if (owner->hash[idx].item == value &&
591  owner->hash[idx].kind == kind)
592  {
593  owner->hash[idx].item = (Datum) 0;
594  owner->hash[idx].kind = NULL;
595  owner->nhash--;
596 
597 #ifdef RESOWNER_STATS
598  nhash_lookups++;
599 #endif
600  return;
601  }
602  idx = (idx + 1) & mask;
603  }
604  }
605 
606  /*
607  * Use %p to print the reference, since most objects tracked by a resource
608  * owner are pointers. It's a bit misleading if it's not a pointer, but
609  * this is a programmer error, anyway.
610  */
611  elog(ERROR, "%s %p is not owned by resource owner %s",
612  kind->name, DatumGetPointer(value), owner->name);
613 }
Datum idx(PG_FUNCTION_ARGS)
Definition: _int_op.c:259
static struct @160 value
uintptr_t Datum
Definition: postgres.h:64
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:312
static uint32 hash_resource_elem(Datum value, const ResourceOwnerDesc *kind)
Definition: resowner.c:214
const char * name
Definition: resowner.h:93

References ResourceOwnerData::arr, Assert, ResourceOwnerData::capacity, DatumGetPointer(), elog, ERROR, ResourceOwnerData::hash, hash_resource_elem(), i, idx(), ResourceElem::item, ResourceElem::kind, ResourceOwnerData::name, ResourceOwnerDesc::name, ResourceOwnerData::narr, ResourceOwnerData::nhash, ResourceOwnerData::releasing, ResourceOwnerData::sorted, and value.

Referenced by ForgetManyTestResources(), ResourceOwnerForgetBuffer(), ResourceOwnerForgetBufferIO(), ResourceOwnerForgetCatCacheListRef(), ResourceOwnerForgetCatCacheRef(), ResourceOwnerForgetCryptoHash(), ResourceOwnerForgetDSM(), ResourceOwnerForgetFile(), ResourceOwnerForgetHMAC(), ResourceOwnerForgetJIT(), ResourceOwnerForgetOSSLCipher(), ResourceOwnerForgetOSSLDigest(), ResourceOwnerForgetPlanCacheRef(), ResourceOwnerForgetRelationRef(), ResourceOwnerForgetSnapshot(), ResourceOwnerForgetTupleDesc(), ResourceOwnerForgetWaitEventSet(), and test_resowner_forget_between_phases().

◆ ResourceOwnerForgetLock()

void ResourceOwnerForgetLock ( ResourceOwner  owner,
struct LOCALLOCK locallock 
)

Definition at line 1065 of file resowner.c.

1066 {
1067  int i;
1068 
1069  if (owner->nlocks > MAX_RESOWNER_LOCKS)
1070  return; /* we have overflowed */
1071 
1072  Assert(owner->nlocks > 0);
1073  for (i = owner->nlocks - 1; i >= 0; i--)
1074  {
1075  if (locallock == owner->locks[i])
1076  {
1077  owner->locks[i] = owner->locks[owner->nlocks - 1];
1078  owner->nlocks--;
1079  return;
1080  }
1081  }
1082  elog(ERROR, "lock reference %p is not owned by resource owner %s",
1083  locallock, owner->name);
1084 }
LOCALLOCK * locks[MAX_RESOWNER_LOCKS]
Definition: resowner.c:157

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

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

◆ ResourceOwnerGetParent()

ResourceOwner ResourceOwnerGetParent ( ResourceOwner  owner)

Definition at line 888 of file resowner.c.

889 {
890  return owner->parent;
891 }

References ResourceOwnerData::parent.

Referenced by LockReassignCurrentOwner().

◆ ResourceOwnerNewParent()

void ResourceOwnerNewParent ( ResourceOwner  owner,
ResourceOwner  newparent 
)

Definition at line 897 of file resowner.c.

899 {
900  ResourceOwner oldparent = owner->parent;
901 
902  if (oldparent)
903  {
904  if (owner == oldparent->firstchild)
905  oldparent->firstchild = owner->nextchild;
906  else
907  {
908  ResourceOwner child;
909 
910  for (child = oldparent->firstchild; child; child = child->nextchild)
911  {
912  if (owner == child->nextchild)
913  {
914  child->nextchild = owner->nextchild;
915  break;
916  }
917  }
918  }
919  }
920 
921  if (newparent)
922  {
923  Assert(owner != newparent);
924  owner->parent = newparent;
925  owner->nextchild = newparent->firstchild;
926  newparent->firstchild = owner;
927  }
928  else
929  {
930  owner->parent = NULL;
931  owner->nextchild = NULL;
932  }
933 }

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

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

◆ ResourceOwnerRelease()

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

Definition at line 648 of file resowner.c.

652 {
653  /* There's not currently any setup needed before recursing */
654  ResourceOwnerReleaseInternal(owner, phase, isCommit, isTopLevel);
655 
656 #ifdef RESOWNER_STATS
657  if (isTopLevel)
658  {
659  elog(LOG, "RESOWNER STATS: lookups: array %d, hash %d",
660  narray_lookups, nhash_lookups);
661  narray_lookups = 0;
662  nhash_lookups = 0;
663  }
664 #endif
665 }
#define LOG
Definition: elog.h:31
static void ResourceOwnerReleaseInternal(ResourceOwner owner, ResourceReleasePhase phase, bool isCommit, bool isTopLevel)
Definition: resowner.c:668

References elog, LOG, and ResourceOwnerReleaseInternal().

Referenced by AbortSubTransaction(), AbortTransaction(), CommitSubTransaction(), CommitTransaction(), PortalDrop(), PrepareTransaction(), ReleaseAuxProcessResources(), test_dsa_resowners(), test_resowner_forget_between_phases(), test_resowner_leak(), test_resowner_many(), test_resowner_priorities(), and test_resowner_remember_between_phases().

◆ ResourceOwnerReleaseAllOfKind()

void ResourceOwnerReleaseAllOfKind ( ResourceOwner  owner,
const ResourceOwnerDesc kind 
)

Definition at line 801 of file resowner.c.

802 {
803  /* Mustn't call this after we have already started releasing resources. */
804  if (owner->releasing)
805  elog(ERROR, "ResourceOwnerForget called for %s after release started", kind->name);
806  Assert(!owner->sorted);
807 
808  /*
809  * Temporarily set 'releasing', to prevent calls to ResourceOwnerRemember
810  * while we're scanning the owner. Enlarging the hash would cause us to
811  * lose track of the point we're scanning.
812  */
813  owner->releasing = true;
814 
815  /* Array first */
816  for (int i = 0; i < owner->narr; i++)
817  {
818  if (owner->arr[i].kind == kind)
819  {
820  Datum value = owner->arr[i].item;
821 
822  owner->arr[i] = owner->arr[owner->narr - 1];
823  owner->narr--;
824  i--;
825 
826  kind->ReleaseResource(value);
827  }
828  }
829 
830  /* Then hash */
831  for (int i = 0; i < owner->capacity; i++)
832  {
833  if (owner->hash[i].kind == kind)
834  {
835  Datum value = owner->hash[i].item;
836 
837  owner->hash[i].item = (Datum) 0;
838  owner->hash[i].kind = NULL;
839  owner->nhash--;
840 
841  kind->ReleaseResource(value);
842  }
843  }
844  owner->releasing = false;
845 }
void(* ReleaseResource)(Datum res)
Definition: resowner.h:108

References ResourceOwnerData::arr, Assert, ResourceOwnerData::capacity, elog, ERROR, ResourceOwnerData::hash, i, ResourceElem::item, ResourceElem::kind, ResourceOwnerDesc::name, ResourceOwnerData::narr, ResourceOwnerData::nhash, ResourceOwnerDesc::ReleaseResource, ResourceOwnerData::releasing, ResourceOwnerData::sorted, and value.

Referenced by ReleaseAllPlanCacheRefsInOwner().

◆ ResourceOwnerRemember()

void ResourceOwnerRemember ( ResourceOwner  owner,
Datum  value,
const ResourceOwnerDesc kind 
)

Definition at line 514 of file resowner.c.

515 {
516  uint32 idx;
517 
518  /* sanity check the ResourceOwnerDesc */
519  Assert(kind->release_phase != 0);
520  Assert(kind->release_priority != 0);
521 
522  /*
523  * Mustn't try to remember more resources after we have already started
524  * releasing. We already checked this in ResourceOwnerEnlarge.
525  */
526  Assert(!owner->releasing);
527  Assert(!owner->sorted);
528 
529  if (owner->narr >= RESOWNER_ARRAY_SIZE)
530  {
531  /* forgot to call ResourceOwnerEnlarge? */
532  elog(ERROR, "ResourceOwnerRemember called but array was full");
533  }
534 
535  /* Append to the array. */
536  idx = owner->narr;
537  owner->arr[idx].item = value;
538  owner->arr[idx].kind = kind;
539  owner->narr++;
540 }
ResourceReleasePhase release_phase
Definition: resowner.h:96
ResourceReleasePriority release_priority
Definition: resowner.h:97

References ResourceOwnerData::arr, Assert, elog, ERROR, idx(), ResourceElem::item, ResourceElem::kind, ResourceOwnerData::narr, ResourceOwnerDesc::release_phase, ResourceOwnerDesc::release_priority, ResourceOwnerData::releasing, RESOWNER_ARRAY_SIZE, ResourceOwnerData::sorted, and value.

Referenced by RememberManyTestResources(), ResourceOwnerRememberBuffer(), ResourceOwnerRememberBufferIO(), ResourceOwnerRememberCatCacheListRef(), ResourceOwnerRememberCatCacheRef(), ResourceOwnerRememberCryptoHash(), ResourceOwnerRememberDSM(), ResourceOwnerRememberFile(), ResourceOwnerRememberHMAC(), ResourceOwnerRememberJIT(), ResourceOwnerRememberOSSLCipher(), ResourceOwnerRememberOSSLDigest(), ResourceOwnerRememberPlanCacheRef(), ResourceOwnerRememberRelationRef(), ResourceOwnerRememberSnapshot(), ResourceOwnerRememberTupleDesc(), ResourceOwnerRememberWaitEventSet(), test_resowner_forget_between_phases(), test_resowner_leak(), test_resowner_priorities(), and test_resowner_remember_between_phases().

◆ ResourceOwnerRememberLock()

void ResourceOwnerRememberLock ( ResourceOwner  owner,
struct LOCALLOCK locallock 
)

Definition at line 1045 of file resowner.c.

1046 {
1047  Assert(locallock != NULL);
1048 
1049  if (owner->nlocks > MAX_RESOWNER_LOCKS)
1050  return; /* we have already overflowed */
1051 
1052  if (owner->nlocks < MAX_RESOWNER_LOCKS)
1053  owner->locks[owner->nlocks] = locallock;
1054  else
1055  {
1056  /* overflowed */
1057  }
1058  owner->nlocks++;
1059 }

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

Referenced by GrantLockLocal(), and LockReassignOwner().

◆ UnregisterResourceReleaseCallback()

void UnregisterResourceReleaseCallback ( ResourceReleaseCallback  callback,
void *  arg 
)

Definition at line 958 of file resowner.c.

959 {
962 
963  prev = NULL;
964  for (item = ResourceRelease_callbacks; item; prev = item, item = item->next)
965  {
966  if (item->callback == callback && item->arg == arg)
967  {
968  if (prev)
969  prev->next = item->next;
970  else
972  pfree(item);
973  break;
974  }
975  }
976 }

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

Variable Documentation

◆ AuxProcessResourceOwner

◆ CurrentResourceOwner

PGDLLIMPORT ResourceOwner CurrentResourceOwner
extern

Definition at line 165 of file resowner.c.

Referenced by _SPI_execute_plan(), apply_spooled_messages(), AssignTransactionId(), AtAbort_ResourceOwner(), AtStart_ResourceOwner(), AtSubAbort_ResourceOwner(), AtSubStart_ResourceOwner(), attach_internal(), BufferAlloc(), CleanupSubTransaction(), CleanupTransaction(), close_lo_relation(), CommitSubTransaction(), CommitTransaction(), create_internal(), CreateAuxProcessResourceOwner(), DecrTupleDescRefCount(), dsm_create_descriptor(), dsm_unpin_mapping(), EvictUnpinnedBuffer(), exec_eval_simple_expr(), exec_init_tuple_store(), exec_simple_check_plan(), exec_stmt_block(), ExecAppendAsyncEventWait(), ExplainExecuteQuery(), ExtendBufferedRelLocal(), ExtendBufferedRelShared(), extendBufFile(), FlushDatabaseBuffers(), FlushRelationBuffers(), FlushRelationsAllBuffers(), get_segment_by_index(), GetCurrentFDWTuplestore(), GetLocalVictimBuffer(), GetVictimBuffer(), IncrBufferRefCount(), IncrTupleDescRefCount(), InitPostgres(), llvm_create_context(), LocalBufferAlloc(), lock_and_open_sequence(), LockAcquireExtended(), LockReassignCurrentOwner(), LockReassignOwner(), LockRelease(), LogicalSlotAdvanceAndCheckSnapState(), make_callstmt_target(), make_new_segment(), makeBufFileCommon(), MakeTransitionCaptureState(), open_lo_relation(), OpenTemporaryFile(), PathNameCreateTemporaryFile(), PathNameOpenTemporaryFile(), perform_base_backup(), PersistHoldablePortal(), pg_cryptohash_create(), pg_hmac_create(), pg_logical_slot_get_changes_guts(), PinBuffer(), PinBuffer_Locked(), PinLocalBuffer(), 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(), ReadRecentBuffer(), RegisterSnapshot(), RegisterTemporaryFile(), RelationDecrementReferenceCount(), RelationIncrementReferenceCount(), ReleaseCatCache(), ReleaseCatCacheList(), ReleaseCatCacheListWithOwner(), ReleaseCatCacheWithOwner(), ReleaseLockIfHeld(), ResourceOwnerDelete(), ResourceOwnerReleaseInternal(), SearchCatCacheInternal(), SearchCatCacheList(), SearchCatCacheMiss(), ShutdownXLOG(), SnapBuildClearExportedSnapshot(), SnapBuildExportSnapshot(), SPI_plan_get_cached_plan(), StartBufferIO(), StartupXLOG(), SyncOneBuffer(), TerminateBufferIO(), test_dsa_resowners(), test_resowner_forget_between_phases(), test_resowner_leak(), test_resowner_many(), test_resowner_priorities(), test_resowner_remember_between_phases(), tuplestore_begin_common(), tuplestore_puttuple_common(), UnpinBuffer(), UnpinLocalBuffer(), UnregisterSnapshot(), UploadManifest(), and WaitLatchOrSocket().

◆ CurTransactionResourceOwner

◆ TopTransactionResourceOwner