if (cl->refcount != 0)
{
if (isCommit)
- elog(WARNING, "cache reference leak: cache %s (%d), list %p has count %d",
- ccp->cc_relname, ccp->id, cl, cl->refcount);
+ PrintCatCacheListLeakWarning(cl);
cl->refcount = 0;
}
if (ct->refcount != 0)
{
if (isCommit)
- elog(WARNING, "cache reference leak: cache %s (%d), tuple %u has count %d",
- ct->my_cache->cc_relname, ct->my_cache->id,
- HeapTupleGetOid(&ct->tuple),
- ct->refcount);
+ PrintCatCacheLeakWarning(&ct->tuple);
ct->refcount = 0;
}
ccp->cc_relisshared ? (Oid) 0 : MyDatabaseId);
}
}
+
+
+/*
+ * Subroutines for warning about reference leaks. These are exported so
+ * that resowner.c can call them.
+ */
+void
+PrintCatCacheLeakWarning(HeapTuple tuple)
+{
+ CatCTup *ct = (CatCTup *) (((char *) tuple) -
+ offsetof(CatCTup, tuple));
+
+ /* Safety check to ensure we were handed a cache entry */
+ Assert(ct->ct_magic == CT_MAGIC);
+
+ elog(WARNING, "cache reference leak: cache %s (%d), tuple %u/%u has count %d",
+ ct->my_cache->cc_relname, ct->my_cache->id,
+ ItemPointerGetBlockNumber(&(tuple->t_self)),
+ ItemPointerGetOffsetNumber(&(tuple->t_self)),
+ ct->refcount);
+}
+
+void
+PrintCatCacheListLeakWarning(CatCList *list)
+{
+ elog(WARNING, "cache reference leak: cache %s (%d), list %p has count %d",
+ list->my_cache->cc_relname, list->my_cache->id,
+ list, list->refcount);
+}
ResourceReleasePhase phase,
bool isCommit,
bool isTopLevel);
+static void PrintRelCacheLeakWarning(Relation rel);
/*****************************************************************************
* iterate till there are none.
*/
while (owner->nrelrefs > 0)
+ {
+ if (isCommit)
+ PrintRelCacheLeakWarning(owner->relrefs[owner->nrelrefs - 1]);
RelationClose(owner->relrefs[owner->nrelrefs - 1]);
+ }
}
}
else if (phase == RESOURCE_RELEASE_LOCKS)
* to iterate till there are none. Ditto for catcache lists.
*/
while (owner->ncatrefs > 0)
+ {
+ if (isCommit)
+ PrintCatCacheLeakWarning(owner->catrefs[owner->ncatrefs - 1]);
ReleaseCatCache(owner->catrefs[owner->ncatrefs - 1]);
+ }
while (owner->ncatlistrefs > 0)
+ {
+ if (isCommit)
+ PrintCatCacheListLeakWarning(owner->catlistrefs[owner->ncatlistrefs - 1]);
ReleaseCatCacheList(owner->catlistrefs[owner->ncatlistrefs - 1]);
+ }
}
/* Clean up index scans too */
ReleaseResources_gist();
elog(ERROR, "relcache reference %s is not owned by resource owner %s",
RelationGetRelationName(rel), owner->name);
}
+
+/*
+ * Debugging subroutine
+ */
+static void
+PrintRelCacheLeakWarning(Relation rel)
+{
+ elog(WARNING, "relcache reference leak: relation \"%s\" not closed",
+ RelationGetRelationName(rel));
+}