I believe it would be particularly useful to add an assertion in dsm_unpin_mapping().
This function relies on CurrentResourceOwner being non-NULL and not releasing to
successfully unpin a mapping.
In this context, resowner not being set means that the dsm segment
would remain attached until the session ends or until it is explicitly
detached. IIUC, the key difference is that a segment will stay mapped
for longer than expected in cases where the mapping was created
when a transaction was aborting.
Thank you for the review comments, it makes sense to include this
check in the callers of the DSA API.
Wrapping the dsa_create/dsa_attach call in the following snippet helps
resolve the issue in case of ProcessGetMemoryContextInterrupt.
+ ResourceOwner current_owner;
+ bool res_releasing = false;
++ if (CurrentResourceOwner && IsResourceOwnerReleasing(CurrentResourceOwner))
+ {
+ current_owner = CurrentResourceOwner;
+ CurrentResourceOwner = NULL;
+ res_releasing = true;
+ }
+
MemoryStatsDsaArea = dsa_create(memCxtArea->lw_lock.tranche);
+ if (res_releasing)
+ CurrentResourceOwner = current_owner;
Kindly let me know your views.
Thank you,
Rahila Syed