Refactoring SearchSysCache + HeapTupleIsValid - Mailing list pgsql-hackers

From Peter Eisentraut
Subject Refactoring SearchSysCache + HeapTupleIsValid
Date
Msg-id 4940FB80.90303@gmx.net
Whole thread Raw
Responses Re: Refactoring SearchSysCache + HeapTupleIsValid  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
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.


pgsql-hackers by date:

Previous
From: Zdenek Kotala
Date:
Subject: Re: visibility maps
Next
From: "Sreejesh O S"
Date:
Subject: Re: COCOMO & Indians