Our code contains about 200 copies of the following code:

tuple = SearchSysCache[Copy](FOOOID, ObjectIdGetDatum(fooid), 0, 0, 0);
if (!HeapTupleIsValid(tuple))
    elog(ERROR, "cache lookup failed for foo %u", fooid);

This only counts elog() calls, not user-facing error messages constructed with ereport().

Shouldn't we try to refactor this, maybe like this:

HeapTuple
SearchSysCache[Copy]Oid(int cacheId, Oid key)
{
    HeapTuple tuple;

    tuple = SearchSysCache[Copy](cacheId, ObjectIdGetDatum(key),
                                 0, 0, 0);
    if (!HeapTupleIsValid(tuple))
elog(ERROR, "cache lookup failed in cache %d (relation %u) for OID %u",
             cacheId, cacheinfo[cacheId].reloid, key);

    return tuple;
}

Maybe some other verb than "Search" could be used to make it clearer that this function has its own error handler.

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to