diff options
Diffstat (limited to 'src/backend/utils/time/snapmgr.c')
-rw-r--r-- | src/backend/utils/time/snapmgr.c | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/src/backend/utils/time/snapmgr.c b/src/backend/utils/time/snapmgr.c index 4a3613d15fc..9198850ad25 100644 --- a/src/backend/utils/time/snapmgr.c +++ b/src/backend/utils/time/snapmgr.c @@ -57,6 +57,7 @@ #include "lib/pairingheap.h" #include "miscadmin.h" #include "port/pg_lfind.h" +#include "storage/fd.h" #include "storage/predicate.h" #include "storage/proc.h" #include "storage/procarray.h" @@ -66,7 +67,7 @@ #include "utils/builtins.h" #include "utils/memutils.h" #include "utils/rel.h" -#include "utils/resowner_private.h" +#include "utils/resowner.h" #include "utils/snapmgr.h" #include "utils/syscache.h" #include "utils/timestamp.h" @@ -162,9 +163,34 @@ static List *exportedSnapshots = NIL; /* Prototypes for local functions */ static Snapshot CopySnapshot(Snapshot snapshot); +static void UnregisterSnapshotNoOwner(Snapshot snapshot); static void FreeSnapshot(Snapshot snapshot); static void SnapshotResetXmin(void); +/* ResourceOwner callbacks to track snapshot references */ +static void ResOwnerReleaseSnapshot(Datum res); + +static const ResourceOwnerDesc snapshot_resowner_desc = +{ + .name = "snapshot reference", + .release_phase = RESOURCE_RELEASE_AFTER_LOCKS, + .release_priority = RELEASE_PRIO_SNAPSHOT_REFS, + .ReleaseResource = ResOwnerReleaseSnapshot, + .DebugPrint = NULL /* the default message is fine */ +}; + +/* Convenience wrappers over ResourceOwnerRemember/Forget */ +static inline void +ResourceOwnerRememberSnapshot(ResourceOwner owner, Snapshot snap) +{ + ResourceOwnerRemember(owner, PointerGetDatum(snap), &snapshot_resowner_desc); +} +static inline void +ResourceOwnerForgetSnapshot(ResourceOwner owner, Snapshot snap) +{ + ResourceOwnerForget(owner, PointerGetDatum(snap), &snapshot_resowner_desc); +} + /* * Snapshot fields to be serialized. * @@ -796,7 +822,7 @@ RegisterSnapshotOnOwner(Snapshot snapshot, ResourceOwner owner) snap = snapshot->copied ? snapshot : CopySnapshot(snapshot); /* and tell resowner.c about it */ - ResourceOwnerEnlargeSnapshots(owner); + ResourceOwnerEnlarge(owner); snap->regd_count++; ResourceOwnerRememberSnapshot(owner, snap); @@ -832,11 +858,16 @@ UnregisterSnapshotFromOwner(Snapshot snapshot, ResourceOwner owner) if (snapshot == NULL) return; + ResourceOwnerForgetSnapshot(owner, snapshot); + UnregisterSnapshotNoOwner(snapshot); +} + +static void +UnregisterSnapshotNoOwner(Snapshot snapshot) +{ Assert(snapshot->regd_count > 0); Assert(!pairingheap_is_empty(&RegisteredSnapshots)); - ResourceOwnerForgetSnapshot(owner, snapshot); - snapshot->regd_count--; if (snapshot->regd_count == 0) pairingheap_remove(&RegisteredSnapshots, &snapshot->ph_node); @@ -1923,3 +1954,11 @@ XidInMVCCSnapshot(TransactionId xid, Snapshot snapshot) return false; } + +/* ResourceOwner callbacks */ + +static void +ResOwnerReleaseSnapshot(Datum res) +{ + UnregisterSnapshotNoOwner((Snapshot) DatumGetPointer(res)); +} |