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: Tue, 15 Dec 2020 02:30:47 +0900
Message-ID: <0b13f28d-de46-fb06-e946-4c0c00cea591@oss.nttdata.com> (raw)
In-Reply-To: <CALj2ACX7Yr_X25Lc5DAAw5tdAjz7qMTBXqLjWkN67NeCHL+-jA@mail.gmail.com>
References: <CALj2ACVvrp5=AVp2PupEm+nAC8S4buqR3fJMmaCoc7ftT0aD2A@mail.gmail.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>
<CALj2ACVFfsmAMyYVidXWfu4URST2xwO20NSYrHUQwxG070poxA@mail.gmail.com>
<3595a221-d845-c97c-96fe-5d4f739edaad@oss.nttdata.com>
<CALj2ACUOQYs+ssxkxRvZ6Ja5+sfc6a-s_0e-Nv2A591hEyOgiw@mail.gmail.com>
<2a0d7305-1cf6-db59-7fc6-241c55c8fc8b@oss.nttdata.com>
<CALj2ACXrf3VcCVXoKqkyZ4N+B2=ndiJzvcOtA-_uYGM_8ux5yg@mail.gmail.com>
<6da38393-6ae5-4d87-2690-11c932123403@oss.nttdata.com>
<CALj2ACV7egGf+LmuUrjirtn4DeOfWCEP9mrOzgKroJ_6Htekyg@mail.gmail.com>
<CALj2ACX7Yr_X25Lc5DAAw5tdAjz7qMTBXqLjWkN67NeCHL+-jA@mail.gmail.com>
On 2020/12/15 1:40, Bharath Rupireddy wrote:
> On Mon, Dec 14, 2020, 9:47 PM Bharath Rupireddy
> <bharath.rupireddyforpostgres@gmail.com> wrote:
>>
>> On Mon, Dec 14, 2020 at 8:03 PM Fujii Masao <masao.fujii@oss.nttdata.com> wrote:
>>>> We will not output if the invalidated entry has no active connection[2], so if we fix the connection leak issue with the above discussed fix i.e closing all the invalidated connections at the end of next xact, there are less chances that we will output invalidated entries in the postgres_fdw_get_connections() output. Only case we may show up invalidated connections(which have active connections entry->conn) in the postgres_fdw_get_connections() output is as follows:
>>>>
>>>> 1) say we have few cached active connections exists in session 1
>>>> 2) drop the user mapping (in another session) associated with any of the cached connections to make that entry invalid
>>>> 3) run select * from postgres_fdw_get_connections(); in session 1. At the start of the xact, the invalidation message gets processed and the corresponding entry gets marked as invalid. If we allow invalid connections (that have entry->conn) to show up in the output, then we show them in the result of the query. At the end of xact, we close these invalid connections, in this case, user might think that he still have invalid connections active.
>>>
>>> What about the case where the transaction started at the above 1) at session 1, and postgres_fdw_get_connections() in the above 3) is called within that transaction at session 1? In this case, postgres_fdw_get_connections() can return even invalidated connections?
>>
>> In that case, since the user mapping would have been dropped in
>> another session and we are in the middle of a txn in session 1, the
>> entries would not get marked as invalid until the invalidation message
>> gets processed by the session 1 which may happen if the session 1
Yes, and this can happen by other commands, for example, CREATE TABLE.
>> opens a sub txn, if not then for postgres_fdw_get_connections() the
>> entries will still be active as they would not have been marked as
>> invalid yet and postgres_fdw_get_connections() would return them in
>> the output.
>
> One more point for the above scenario: if the user mapping is dropped
> in another session, then cache lookup for that entry in the
> postgres_fdw_get_connections() returns a null tuple which I plan to
> not throw an error, but just to skip in that case and continue. But if
> the user mapping is not dropped in another session but altered, then
> postgres_fdw_get_connections() still can show that in the output.
Yes, so *if* we really want to return even connection invalidated by drop of
user mapping, the cached connection entry may need to store not only
user mapping id but also server id so that we can get the server name without
user mapping entry.
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: <0b13f28d-de46-fb06-e946-4c0c00cea591@oss.nttdata.com>
References: <CALj2ACVvrp5=AVp2PupEm+nAC8S4buqR3fJMmaCoc7ftT0aD2A@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> <CALj2ACVFfsmAMyYVidXWfu4URST2xwO20NSYrHUQwxG070poxA@mail.gmail.com> <3595a221-d845-c97c-96fe-5d4f739edaad@oss.nttdata.com> <CALj2ACUOQYs+ssxkxRvZ6Ja5+sfc6a-s_0e-Nv2A591hEyOgiw@mail.gmail.com> <2a0d7305-1cf6-db59-7fc6-241c55c8fc8b@oss.nttdata.com> <CALj2ACXrf3VcCVXoKqkyZ4N+B2=ndiJzvcOtA-_uYGM_8ux5yg@mail.gmail.com> <6da38393-6ae5-4d87-2690-11c932123403@oss.nttdata.com> <CALj2ACV7egGf+LmuUrjirtn4DeOfWCEP9mrOzgKroJ_6Htekyg@mail.gmail.com> <CALj2ACX7Yr_X25Lc5DAAw5tdAjz7qMTBXqLjWkN67NeCHL+-jA@mail.gmail.com> <0b13f28d-de46-fb06-e946-4c0c00cea591@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