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 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.

Function Documentation

◆ CreateAuxProcessResourceOwner()

void CreateAuxProcessResourceOwner ( void  )

Definition at line 834 of file resowner.c.

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

Referenced by AuxiliaryProcessMain(), and InitPostgres().

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

◆ RegisterResourceReleaseCallback()

void RegisterResourceReleaseCallback ( ResourceReleaseCallback  callback,
void *  arg 
)

Definition at line 796 of file resowner.c.

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

Referenced by px_find_cipher(), and px_find_digest().

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

◆ ReleaseAuxProcessResources()

void ReleaseAuxProcessResources ( bool  isCommit)

Definition at line 855 of file resowner.c.

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

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

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

◆ ResourceOwnerCreate()

ResourceOwner ResourceOwnerCreate ( ResourceOwner  parent,
const char *  name 
)

Definition at line 422 of file resowner.c.

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

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

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

◆ ResourceOwnerDelete()

void ResourceOwnerDelete ( ResourceOwner  owner)

Definition at line 688 of file resowner.c.

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

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

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

◆ ResourceOwnerGetParent()

ResourceOwner ResourceOwnerGetParent ( ResourceOwner  owner)

Definition at line 739 of file resowner.c.

References ResourceOwnerData::parent.

Referenced by LockReassignCurrentOwner().

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

◆ ResourceOwnerNewParent()

void ResourceOwnerNewParent ( ResourceOwner  owner,
ResourceOwner  newparent 
)

Definition at line 748 of file resowner.c.

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

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

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

◆ ResourceOwnerRelease()

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

Definition at line 478 of file resowner.c.

References ResourceOwnerReleaseInternal().

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

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

◆ UnregisterResourceReleaseCallback()

void UnregisterResourceReleaseCallback ( ResourceReleaseCallback  callback,
void *  arg 
)

Definition at line 810 of file resowner.c.

References ResourceReleaseCallbackItem::next, and pfree().

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

Variable Documentation

◆ AuxProcessResourceOwner

PGDLLIMPORT ResourceOwner AuxProcessResourceOwner

◆ CurrentResourceOwner

PGDLLIMPORT ResourceOwner CurrentResourceOwner

Definition at line 142 of file resowner.c.

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

◆ CurTransactionResourceOwner

◆ TopTransactionResourceOwner