From: Fujii Masao <masao.fujii@oss.nttdata.com>
To: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Cc: Alexey Kondratov <a.kondratov@postgrespro.ru>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Re: [PATCH] postgres_fdw connection caching - cause remote sessions linger till the local session exit
Date: Sat, 12 Dec 2020 02:30:57 +0900
Message-ID: <fe4fe2b9-9de6-1aa0-c7a9-5b5eadae241f@oss.nttdata.com> (raw)
In-Reply-To: <CALj2ACX8FgUEJBuzS2bB8+vLENQdEkjLQZ89jk1cqK0y2aDJZA@mail.gmail.com>
References: <CALj2ACVvrp5=AVp2PupEm+nAC8S4buqR3fJMmaCoc7ftT0aD2A@mail.gmail.com>
<CALj2ACX4B9sBTKPg70TzKfPfPJ=ndocU6hY5jii5wDvzW2X2DQ@mail.gmail.com>
<c22ad9fcdba6ab768ec2ea86d33d0c18@postgrespro.ru>
<CALj2ACW+PzzuqE6YOueNUi5Zek9XTv9P3FXdT4XF3-1JDk4RuA@mail.gmail.com>
<CALj2ACU0gf_Xf2sAtrCRhvLc-G42UqLGthDfVC9G1jzUpBcQ1w@mail.gmail.com>
<1f29ad3f1d8b969dfde6d500bbd9d82d@postgrespro.ru>
<CALj2ACVq99r+s04tWrD8TBG6QOfa=r1j0JXvKbO6JFmrMgdWpg@mail.gmail.com>
<be224d0520df0594b0693c95bd19fe0a@postgrespro.ru>
<CALj2ACXBgRBxGvyPA=kWF=96h9rdTAcUqBGbkRgwOx_-vyN3+g@mail.gmail.com>
<2d5cb0b3-a6e8-9bbb-953f-879f47128faa@oss.nttdata.com>
<CALj2ACX3SiYXodW1vka2RdHMqok9kLvwJ4vNUMO358yL5BeNJA@mail.gmail.com>
<CALj2ACW2cgfNARmgwK-+_vMpv73F7=uq2vEoRokkEj=6+oRCJQ@mail.gmail.com>
<fdc8af8f-fc3f-a072-8db6-8fc17ac87e20@oss.nttdata.com>
<CALj2ACUYS7zgLZgG8qELvK8YRNQ4Fmi0bfvRisUjyj07LtBYPA@mail.gmail.com>
<CALj2ACX8FgUEJBuzS2bB8+vLENQdEkjLQZ89jk1cqK0y2aDJZA@mail.gmail.com>
On 2020/12/11 19:16, Bharath Rupireddy wrote:
> On Thu, Dec 10, 2020 at 7:14 AM Bharath Rupireddy
> <bharath.rupireddyforpostgres@gmail.com> wrote:
>>> + /* We only look for active and open remote connections. */
>>> + if (entry->invalidated || !entry->conn)
>>> + continue;
>>>
>>> We should return even invalidated entry because it has still cached connection?
>>>
>>
>> I checked this point earlier, for invalidated connections, the tuple
>> returned from the cache is also invalid and the following error will
>> be thrown. So, we can not get the server name for that user mapping.
>> Cache entries too would have been invalidated after the connection is
>> marked as invalid in pgfdw_inval_callback().
>>
>> umaptup = SearchSysCache1(USERMAPPINGOID, ObjectIdGetDatum(entry->key));
>> if (!HeapTupleIsValid(umaptup))
>> elog(ERROR, "cache lookup failed for user mapping with OID %u",
>> entry->key);
>>
>
> I further checked on returning invalidated connections in the output
> of the function. Actually, the reason I'm seeing a null tuple from sys
> cache (and hence the error "cache lookup failed for user mapping with
> OID xxxx") for an invalidated connection is that the user mapping
> (with OID entry->key that exists in the cache) is getting dropped, so
> the sys cache returns null tuple. The use case is as follows:
>
> 1) Create a server, role, and user mapping of the role with the server
> 2) Run a foreign table query, so that the connection related to the
> server gets cached
> 3) Issue DROP OWNED BY for the role created, since the user mapping is
> dependent on that role, it gets dropped from the catalogue table and
> an invalidation message will be pending to clear the sys cache
> associated with that user mapping.
> 4) Now, if I do select * from postgres_fdw_get_connections() or for
> that matter any query, at the beginning the txn
> AtStart_Cache()-->AcceptInvalidationMessages()-->pgfdw_inval_callback()
> gets called and marks the cached entry as invalidated. Remember the
> reason for this invalidation message is that the user mapping with the
> OID entry->key is dropped from 3). Later in
> postgres_fdw_get_connections(), when we search the sys cache with
> entry->key for that invalidated connection, since the user mapping is
> dropped from the system, null tuple is returned.
Thanks for the analysis! This means that the cached connection invalidated by drop of server or user mapping will not be closed even by the subsequent access to the foreign server and will remain until the backend exits. Right? If so, this seems like a connection-leak bug, at least for me.... Thought?
Regards,
--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: masao.fujii@oss.nttdata.com, bharath.rupireddyforpostgres@gmail.com, a.kondratov@postgrespro.ru
Subject: Re: [PATCH] postgres_fdw connection caching - cause remote sessions linger till the local session exit
In-Reply-To: <fe4fe2b9-9de6-1aa0-c7a9-5b5eadae241f@oss.nttdata.com>
References: <CALj2ACVvrp5=AVp2PupEm+nAC8S4buqR3fJMmaCoc7ftT0aD2A@mail.gmail.com> <c22ad9fcdba6ab768ec2ea86d33d0c18@postgrespro.ru> <CALj2ACW+PzzuqE6YOueNUi5Zek9XTv9P3FXdT4XF3-1JDk4RuA@mail.gmail.com> <CALj2ACU0gf_Xf2sAtrCRhvLc-G42UqLGthDfVC9G1jzUpBcQ1w@mail.gmail.com> <1f29ad3f1d8b969dfde6d500bbd9d82d@postgrespro.ru> <CALj2ACVq99r+s04tWrD8TBG6QOfa=r1j0JXvKbO6JFmrMgdWpg@mail.gmail.com> <be224d0520df0594b0693c95bd19fe0a@postgrespro.ru> <CALj2ACXBgRBxGvyPA=kWF=96h9rdTAcUqBGbkRgwOx_-vyN3+g@mail.gmail.com> <2d5cb0b3-a6e8-9bbb-953f-879f47128faa@oss.nttdata.com> <CALj2ACX3SiYXodW1vka2RdHMqok9kLvwJ4vNUMO358yL5BeNJA@mail.gmail.com> <CALj2ACW2cgfNARmgwK-+_vMpv73F7=uq2vEoRokkEj=6+oRCJQ@mail.gmail.com> <fdc8af8f-fc3f-a072-8db6-8fc17ac87e20@oss.nttdata.com> <CALj2ACUYS7zgLZgG8qELvK8YRNQ4Fmi0bfvRisUjyj07LtBYPA@mail.gmail.com> <CALj2ACX8FgUEJBuzS2bB8+vLENQdEkjLQZ89jk1cqK0y2aDJZA@mail.gmail.com> <fe4fe2b9-9de6-1aa0-c7a9-5b5eadae241f@oss.nttdata.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox