try_relation_open and relation_open behave different.

Поиск
Список
Период
Сортировка
От Xing GUO
Тема try_relation_open and relation_open behave different.
Дата
Msg-id CACpMh+C00FnGkW=qPX7UQxSWh0Xhz-Nx5tJr+SpMjcmsUXDnJQ@mail.gmail.com
обсуждение исходный текст
Ответы Re: try_relation_open and relation_open behave different.  (Michael Paquier <michael@paquier.xyz>)
Список pgsql-hackers
Hi hackers,

I'm writing an extension that employs `object_access_hook`. I want to monitor the table creation event and record the mapping between `reloid` and `relfilenode` during a transaction. Here's my code snippet,

```
static void
my_object_access_hook(ObjectAccessType access,
                      Oid classId,
                      Oid objectId,
                      int subId, void *arg)
{
    do_some_checks(access, classId, ...);
    // open the relation using relation_open
    rel = relation_open(objectId, AccessShareLock);

    // record the reloid and relfilenode.
    record(objectId, rel->rd_node);
    relation_close(rel, AccessShareLock);
}
```

However, when I replace the relation_open with try_relation_open, the relation cannot be opened. I've checked the source code, it looks that try_relation_open has an additional checker which causes the relation_open and try_relation_open behavior different:

```
Relation
try_relation_open(Oid relationId, LOCKMODE lockmode)
{
    ...
    /*
     * Now that we have the lock, probe to see if the relation really exists
     * or not.
     */
    if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(relationId)))
    {
        /* Release useless lock */
        if (lockmode != NoLock)
           UnlockRelationOid(relationId, lockmode);

        return NULL;
    }
    ...
}
```


My question is, is it a deliberate design that makes try_relation_open and relation_open different? Shall we mention it in the comment of try_relation_open OR adding the checker to relation_open?

Best Regards,
Xing






В списке pgsql-hackers по дате отправления:

Предыдущее
От: Bharath Rupireddy
Дата:
Сообщение: Re: can we add subscription TAP test option "vcregress subscriptioncheck" for MSVC builds?
Следующее
От: Amit Kapila
Дата:
Сообщение: Re: Data is copied twice when specifying both child and parent table in publication