pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alexey Kondratov <a.kondratov@postgrespro.ru>
To: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Cc: Hou, Zhijie <houzj.fnst@cn.fujitsu.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Cc: Fujii Masao <masao.fujii@oss.nttdata.com>
Subject: Re: [PATCH] postgres_fdw connection caching - cause remote sessions linger till the local session exit
Date: Thu, 17 Dec 2020 20:02:19 +0300
Message-ID: <919942767cf9a3d4e413c63887aec679@postgrespro.ru> (raw)
In-Reply-To: <CALj2ACWReYX_OmqYfS-O5Dw-nTsL95VihTAJW8WdWEDFsnPUtQ@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>
	<0b13f28d-de46-fb06-e946-4c0c00cea591@oss.nttdata.com>
	<CALj2ACVypPe+4L2uAVMNfXCH3B00fqX5Nx01pVFJCU009BTJdg@mail.gmail.com>
	<CALj2ACXghAf_GPOVBVuvuPy=9b5ccB7mtf1Jeeoa0QMav-cxOQ@mail.gmail.com>
	<617e9887b74c4332a5d1e5fb2c56ddfd@G08CNEXMBPEKD05.g08.fujitsu.local>
	<CALj2ACWReYX_OmqYfS-O5Dw-nTsL95VihTAJW8WdWEDFsnPUtQ@mail.gmail.com>

On 2020-12-17 18:02, Bharath Rupireddy wrote:
> On Thu, Dec 17, 2020 at 5:38 PM Hou, Zhijie <houzj.fnst@cn.fujitsu.com> 
> wrote:
>> I took a look into the patch, and have a little issue:
>> 
>> +bool disconnect_cached_connections(uint32 hashvalue, bool all)
>> +       if (all)
>> +       {
>> +               hash_destroy(ConnectionHash);
>> +               ConnectionHash = NULL;
>> +               result = true;
>> +       }
>> 
>> If disconnect_cached_connections is called to disconnect all the 
>> connections,
>> should we reset the 'xact_got_connection' flag ?
> 
> I think we must allow postgres_fdw_disconnect() to disconnect the
> particular/all connections only when the corresponding entries have no
> open txns or connections are not being used in that txn, otherwise
> not. We may end up closing/disconnecting the connection that's still
> being in use because entry->xact_dept can even go more than 1 for sub
> txns. See use case [1].
> 
> +        if ((all || entry->server_hashvalue == hashvalue) &&
> entry->xact_depth == 0 &&
> +            entry->conn)
> +        {
> +            disconnect_pg_server(entry);
> +            result = true;
> +        }
> 
> Thoughts?
> 

I think that you are right. Actually, I was thinking about much more 
simple solution to this problem --- just restrict 
postgres_fdw_disconnect() to run only *outside* of explicit transaction 
block. This should protect everyone from closing its underlying 
connections, but seems to be a bit more restrictive than you propose.

Just thought, that if we start closing fdw connections in the open xact 
block:

1) Close a couple of them.
2) Found one with xact_depth > 0 and error out.
3) End up in the mixed state: some of connections were closed, but some 
them not, and it cannot be rolled back with the xact.

In other words, I have some doubts about allowing to call a 
non-transactional by its nature function in the transaction block.


Regards
-- 
Alexey Kondratov

Postgres Professional https://www.postgrespro.com
Russian Postgres Company





view thread (175+ messages)  latest in thread

Message-ID: <919942767cf9a3d4e413c63887aec679@postgrespro.ru>
Permalink:  ../919942767cf9a3d4e413c63887aec679@postgrespro.ru/
Also on:    postgresql.org/message-id/919942767cf9a3d4e413c63887aec679@postgrespro.ru

 · 

reply

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: a.kondratov@postgrespro.ru, bharath.rupireddyforpostgres@gmail.com, houzj.fnst@cn.fujitsu.com, masao.fujii@oss.nttdata.com
  Subject: Re: [PATCH] postgres_fdw connection caching - cause remote sessions linger till the local session exit
  In-Reply-To: <919942767cf9a3d4e413c63887aec679@postgrespro.ru>
  References: <CALj2ACVvrp5=AVp2PupEm+nAC8S4buqR3fJMmaCoc7ftT0aD2A@mail.gmail.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> <CALj2ACVypPe+4L2uAVMNfXCH3B00fqX5Nx01pVFJCU009BTJdg@mail.gmail.com> <CALj2ACXghAf_GPOVBVuvuPy=9b5ccB7mtf1Jeeoa0QMav-cxOQ@mail.gmail.com> <617e9887b74c4332a5d1e5fb2c56ddfd@G08CNEXMBPEKD05.g08.fujitsu.local> <CALj2ACWReYX_OmqYfS-O5Dw-nTsL95VihTAJW8WdWEDFsnPUtQ@mail.gmail.com> <919942767cf9a3d4e413c63887aec679@postgrespro.ru>

* 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