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.

Typedefs

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

Enumerations

enum  ResourceReleasePhase { RESOURCE_RELEASE_BEFORE_LOCKS , 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 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)
 

Variables

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

Typedef Documentation

◆ ResourceOwner

Definition at line 27 of file resowner.h.

◆ ResourceReleaseCallback

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

Definition at line 57 of file resowner.h.

Enumeration Type Documentation

◆ ResourceReleasePhase

Enumerator
RESOURCE_RELEASE_BEFORE_LOCKS 
RESOURCE_RELEASE_LOCKS 
RESOURCE_RELEASE_AFTER_LOCKS 

Definition at line 46 of file resowner.h.

47 {
ResourceReleasePhase
Definition: resowner.h:47
@ RESOURCE_RELEASE_LOCKS
Definition: resowner.h:49
@ RESOURCE_RELEASE_BEFORE_LOCKS
Definition: resowner.h:48
@ RESOURCE_RELEASE_AFTER_LOCKS
Definition: resowner.h:50

Function Documentation

◆ CreateAuxProcessResourceOwner()

void CreateAuxProcessResourceOwner ( void  )

Definition at line 914 of file resowner.c.

915 {
917  Assert(CurrentResourceOwner == NULL);
918  AuxProcessResourceOwner = ResourceOwnerCreate(NULL, "AuxiliaryProcess");
920 
921  /*
922  * Register a shmem-exit callback for cleanup of aux-process resource
923  * owner. (This needs to run after, e.g., ShutdownXLOG.)
924  */
926 }
void on_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:361
Assert(fmt[strlen(fmt) - 1] !='\n')
static void ReleaseAuxProcessResourcesCallback(int code, Datum arg)
Definition: resowner.c:956
ResourceOwner ResourceOwnerCreate(ResourceOwner parent, const char *name)
Definition: resowner.c:429
ResourceOwner CurrentResourceOwner
Definition: resowner.c:147
ResourceOwner AuxProcessResourceOwner
Definition: resowner.c:150

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

Referenced by AuxiliaryProcessMain(), and InitPostgres().

◆ RegisterResourceReleaseCallback()

void RegisterResourceReleaseCallback ( ResourceReleaseCallback  callback,
void *  arg 
)

Definition at line 876 of file resowner.c.

877 {
879 
880  item = (ResourceReleaseCallbackItem *)
883  item->callback = callback;
884  item->arg = arg;
887 }
MemoryContext TopMemoryContext
Definition: mcxt.c:141
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:1021
void * arg
static ResourceReleaseCallbackItem * ResourceRelease_callbacks
Definition: resowner.c:162
struct ResourceReleaseCallbackItem * next
Definition: resowner.c:157
ResourceReleaseCallback callback
Definition: resowner.c:158
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.

Referenced by px_find_cipher(), and px_find_digest().

◆ ReleaseAuxProcessResources()

void ReleaseAuxProcessResources ( bool  isCommit)

Definition at line 934 of file resowner.c.

935 {
936  /*
937  * At this writing, the only thing that could actually get released is
938  * buffer pins; but we may as well do the full release protocol.
939  */
942  isCommit, true);
945  isCommit, true);
948  isCommit, true);
949 }
void ResourceOwnerRelease(ResourceOwner owner, ResourceReleasePhase phase, bool isCommit, bool isTopLevel)
Definition: resowner.c:488

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

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

◆ ResourceOwnerCreate()

ResourceOwner ResourceOwnerCreate ( ResourceOwner  parent,
const char *  name 
)

Definition at line 429 of file resowner.c.

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

References ResourceOwnerData::bufferarr, BufferGetDatum, ResourceOwnerData::bufferioarr, ResourceOwnerData::catlistrefarr, ResourceOwnerData::catrefarr, ResourceOwnerData::cryptohasharr, ResourceOwnerData::dsmarr, ResourceOwnerData::filearr, FileGetDatum, ResourceOwnerData::firstchild, ResourceOwnerData::hmacarr, InvalidBuffer, ResourceOwnerData::jitarr, MemoryContextAllocZero(), name, ResourceOwnerData::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().

◆ ResourceOwnerDelete()

void ResourceOwnerDelete ( ResourceOwner  owner)

Definition at line 762 of file resowner.c.

763 {
764  /* We had better not be deleting CurrentResourceOwner ... */
765  Assert(owner != CurrentResourceOwner);
766 
767  /* And it better not own any resources, either */
768  Assert(owner->bufferarr.nitems == 0);
769  Assert(owner->bufferioarr.nitems == 0);
770  Assert(owner->catrefarr.nitems == 0);
771  Assert(owner->catlistrefarr.nitems == 0);
772  Assert(owner->relrefarr.nitems == 0);
773  Assert(owner->planrefarr.nitems == 0);
774  Assert(owner->tupdescarr.nitems == 0);
775  Assert(owner->snapshotarr.nitems == 0);
776  Assert(owner->filearr.nitems == 0);
777  Assert(owner->dsmarr.nitems == 0);
778  Assert(owner->jitarr.nitems == 0);
779  Assert(owner->cryptohasharr.nitems == 0);
780  Assert(owner->hmacarr.nitems == 0);
781  Assert(owner->nlocks == 0 || owner->nlocks == MAX_RESOWNER_LOCKS + 1);
782 
783  /*
784  * Delete children. The recursive call will delink the child from me, so
785  * just iterate as long as there is a child.
786  */
787  while (owner->firstchild != NULL)
789 
790  /*
791  * We delink the owner from its parent before deleting it, so that if
792  * there's an error we won't have deleted/busted owners still attached to
793  * the owner tree. Better a leak than a crash.
794  */
795  ResourceOwnerNewParent(owner, NULL);
796 
797  /* And free the object. */
798  ResourceArrayFree(&(owner->bufferarr));
799  ResourceArrayFree(&(owner->bufferioarr));
800  ResourceArrayFree(&(owner->catrefarr));
801  ResourceArrayFree(&(owner->catlistrefarr));
802  ResourceArrayFree(&(owner->relrefarr));
803  ResourceArrayFree(&(owner->planrefarr));
804  ResourceArrayFree(&(owner->tupdescarr));
805  ResourceArrayFree(&(owner->snapshotarr));
806  ResourceArrayFree(&(owner->filearr));
807  ResourceArrayFree(&(owner->dsmarr));
808  ResourceArrayFree(&(owner->jitarr));
809  ResourceArrayFree(&(owner->cryptohasharr));
810  ResourceArrayFree(&(owner->hmacarr));
811 
812  pfree(owner);
813 }
void pfree(void *pointer)
Definition: mcxt.c:1456
void ResourceOwnerNewParent(ResourceOwner owner, ResourceOwner newparent)
Definition: resowner.c:828
#define MAX_RESOWNER_LOCKS
Definition: resowner.c:110
static void ResourceArrayFree(ResourceArray *resarr)
Definition: resowner.c:409
void ResourceOwnerDelete(ResourceOwner owner)
Definition: resowner.c:762
uint32 nitems
Definition: resowner.c:70

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

Referenced by CleanupSubTransaction(), CleanupTransaction(), CommitSubTransaction(), CommitTransaction(), plpgsql_call_handler(), plpgsql_inline_handler(), PortalDrop(), PrepareTransaction(), and WalSndResourceCleanup().

◆ ResourceOwnerGetParent()

ResourceOwner ResourceOwnerGetParent ( ResourceOwner  owner)

Definition at line 819 of file resowner.c.

820 {
821  return owner->parent;
822 }

References ResourceOwnerData::parent.

Referenced by LockReassignCurrentOwner().

◆ ResourceOwnerNewParent()

void ResourceOwnerNewParent ( ResourceOwner  owner,
ResourceOwner  newparent 
)

Definition at line 828 of file resowner.c.

830 {
831  ResourceOwner oldparent = owner->parent;
832 
833  if (oldparent)
834  {
835  if (owner == oldparent->firstchild)
836  oldparent->firstchild = owner->nextchild;
837  else
838  {
839  ResourceOwner child;
840 
841  for (child = oldparent->firstchild; child; child = child->nextchild)
842  {
843  if (owner == child->nextchild)
844  {
845  child->nextchild = owner->nextchild;
846  break;
847  }
848  }
849  }
850  }
851 
852  if (newparent)
853  {
854  Assert(owner != newparent);
855  owner->parent = newparent;
856  owner->nextchild = newparent->firstchild;
857  newparent->firstchild = owner;
858  }
859  else
860  {
861  owner->parent = NULL;
862  owner->nextchild = NULL;
863  }
864 }

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 488 of file resowner.c.

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

References ResourceOwnerReleaseInternal().

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

◆ ResourceOwnerReleaseAllPlanCacheRefs()

void ResourceOwnerReleaseAllPlanCacheRefs ( ResourceOwner  owner)

Definition at line 743 of file resowner.c.

744 {
745  Datum foundres;
746 
747  while (ResourceArrayGetAny(&(owner->planrefarr), &foundres))
748  {
749  CachedPlan *res = (CachedPlan *) DatumGetPointer(foundres);
750 
751  ReleaseCachedPlan(res, owner);
752  }
753 }
void ReleaseCachedPlan(CachedPlan *plan, ResourceOwner owner)
Definition: plancache.c:1268
uintptr_t Datum
Definition: postgres.h:64
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:312
static bool ResourceArrayGetAny(ResourceArray *resarr, Datum *value)
Definition: resowner.c:377

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

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

◆ UnregisterResourceReleaseCallback()

void UnregisterResourceReleaseCallback ( ResourceReleaseCallback  callback,
void *  arg 
)

Definition at line 890 of file resowner.c.

891 {
894 
895  prev = NULL;
896  for (item = ResourceRelease_callbacks; item; prev = item, item = item->next)
897  {
898  if (item->callback == callback && item->arg == arg)
899  {
900  if (prev)
901  prev->next = item->next;
902  else
904  pfree(item);
905  break;
906  }
907  }
908 }

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

Variable Documentation

◆ AuxProcessResourceOwner

◆ CurrentResourceOwner

PGDLLIMPORT ResourceOwner CurrentResourceOwner
extern

Definition at line 147 of file resowner.c.

Referenced by _SPI_execute_plan(), apply_spooled_messages(), AssignTransactionId(), AtAbort_ResourceOwner(), AtStart_ResourceOwner(), AtSubAbort_ResourceOwner(), AtSubStart_ResourceOwner(), BgBufferSync(), BufferSync(), cipher_free_callback(), CleanupSubTransaction(), CleanupTransaction(), close_lo_relation(), CommitSubTransaction(), CommitTransaction(), CreateAuxProcessResourceOwner(), 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(), ExtendBufferedRelShared(), extendBufFile(), FlushDatabaseBuffers(), FlushRelationBuffers(), FlushRelationsAllBuffers(), GetCurrentFDWTuplestore(), GetLocalVictimBuffer(), GetVictimBuffer(), IncrBufferRefCount(), IncrTupleDescRefCount(), InitPostgres(), llvm_create_context(), 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(), 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(), ReadBuffer_common(), ReadRecentBuffer(), RegisterSnapshot(), RegisterTemporaryFile(), RelationDecrementReferenceCount(), RelationIncrementReferenceCount(), ReleaseCatCache(), ReleaseCatCacheList(), ReleaseLockIfHeld(), ResourceOwnerDelete(), ResourceOwnerReleaseInternal(), SearchCatCacheInternal(), SearchCatCacheList(), SearchCatCacheMiss(), ShutdownXLOG(), SnapBuildClearExportedSnapshot(), SnapBuildExportSnapshot(), SPI_plan_get_cached_plan(), StartBufferIO(), StartupXLOG(), TerminateBufferIO(), tuplestore_begin_common(), tuplestore_puttuple_common(), UnpinBuffer(), UnpinLocalBuffer(), UnregisterSnapshot(), and WalSndResourceCleanup().

◆ CurTransactionResourceOwner

◆ TopTransactionResourceOwner