pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Fujii Masao <masao.fujii@oss.nttdata.com>
To: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
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: Fri, 29 Jan 2021 16:06:34 +0900
Message-ID: <c0d078a7-1cfb-3621-6a44-d73ba1382bb2@oss.nttdata.com> (raw)
In-Reply-To: <CALj2ACXQ9ke6deP1-f34vv7TOrLuXr6=nmbi5fgxA3N_Zs=pnQ@mail.gmail.com>
References: <CALj2ACVvrp5=AVp2PupEm+nAC8S4buqR3fJMmaCoc7ftT0aD2A@mail.gmail.com>
	<2147113.1611644754@sss.pgh.pa.us>
	<1b4d7c4f-a9f9-08f0-295d-de6ec0d5def5@oss.nttdata.com>
	<CALj2ACWq4+T-M1cTDDdHm2wBcYCD1fUhpONg11UAH1L-+MoEBw@mail.gmail.com>
	<3c20e3e6-1127-17f4-7725-a860b394076c@oss.nttdata.com>
	<73fc5ae4-3c54-1262-4533-f8c547de2e60@oss.nttdata.com>
	<CALj2ACWFX8wjEKmK8LQ-ZNVJqGt_Zy=1-cBhKE3XTJ+At_VN-w@mail.gmail.com>
	<2688508.1611865371@sss.pgh.pa.us>
	<CALj2ACWhoQtyZdsCZNLDLOnRjCBcoscrc3H0qU4=7f23UZcF9g@mail.gmail.com>
	<2724627.1611886184@sss.pgh.pa.us>
	<fbfdf4e2-37fb-a3f1-f6a0-3f9bf089e356@oss.nttdata.com>
	<CALj2ACVL7PZO+gOj7Jrhshm79TjTpj_6CJDqtf34VgjQasX1DA@mail.gmail.com>
	<6e9c9d45-c612-639a-f741-7798013c0ae4@oss.nttdata.com>
	<CALj2ACW1jAJTi-SmBCStZ6+a1C3DeAc8-_Zuw1LYFzo8D33k2w@mail.gmail.com>
	<CALj2ACXhM_yTBXXTCA-whZ_oA1x3DuGxyKnsROjMh8YZLG9bJw@mail.gmail.com>
	<7fa16ff3-5b37-0617-7a27-22e839695ef5@oss.nttdata.com>
	<CALj2ACXQ9ke6deP1-f34vv7TOrLuXr6=nmbi5fgxA3N_Zs=pnQ@mail.gmail.com>



On 2021/01/29 15:44, Bharath Rupireddy wrote:
> On Fri, Jan 29, 2021 at 11:54 AM Fujii Masao
> <masao.fujii@oss.nttdata.com> wrote:
>>>> IIRC, when we were finding a way to close the invalidated connections
>>>> so that they don't leaked, we had two options:
>>>>
>>>> 1) let those connections (whether currently being used in the xact or
>>>> not) get marked invalidated in pgfdw_inval_callback and closed in
>>>> pgfdw_xact_callback at the main txn end as shown below
>>>>
>>>>           if (PQstatus(entry->conn) != CONNECTION_OK ||
>>>>               PQtransactionStatus(entry->conn) != PQTRANS_IDLE ||
>>>>               entry->changing_xact_state ||
>>>>               entry->invalidated).   ----> by adding this
>>>>           {
>>>>               elog(DEBUG3, "discarding connection %p", entry->conn);
>>>>               disconnect_pg_server(entry);
>>>>           }
>>>>
>>>> 2) close the unused connections right away in pgfdw_inval_callback
>>>> instead of marking them invalidated. Mark used connections as
>>>> invalidated in pgfdw_inval_callback and close them in
>>>> pgfdw_xact_callback at the main txn end.
>>>>
>>>> We went with option (2) because we thought this would ease some burden
>>>> on pgfdw_xact_callback closing a lot of invalid connections at once.
>>>
>>> Also, see the original patch for the connection leak issue just does
>>> option (1), see [1]. But in [2] and [3], we chose option (2).
>>>
>>> I feel, we can go for option (1), with the patch attached in [1] i.e.
>>> having have_invalid_connections whenever any connection gets invalided
>>> so that we don't quickly exit in pgfdw_xact_callback and the
>>> invalidated connections get closed properly. Thoughts?
>>
>> Before going for (1) or something, I'd like to understand what the actual
>> issue of (2), i.e., the current code is. Otherwise other approaches might
>> have the same issue.
> 
> The problem with option (2) is that because of CLOBBER_CACHE_ALWAYS,
> pgfdw_inval_callback is getting called many times and the connections
> that are not used i..e xact_depth == 0, are getting disconnected
> there, so we are not seeing the consistent results for
> postgres_fdw_get_connectionstest cases. If the connections are being
> used within the xact, then the valid option for those connections are
> being shown as false again making postgres_fdw_get_connections output
> inconsistent. This is what happened on the build farm member with
> CLOBBER_CACHE_ALWAYS build.

But if the issue is only the inconsistency of test results,
we can go with the option (2)? Even with (2), we can make the test
stable by removing "valid" column and executing
postgres_fdw_get_connections() within the transaction?

> 
> So if we go with option (1), get rid of valid state from
> postgres_fdw_get_connectionstest and having the test cases inside an
> explicit xact block at the beginning of the postgres_fdw.sql test
> file, we don't see CLOBBER_CACHE_ALWAYS inconsistencies. I'm not sure
> if this is the correct way.
> 
>> Regarding (1), as far as I understand correctly, even when the transaction
>> doesn't use foreign tables at all, it needs to scan the connection cache
>> entries if necessary. I was thinking to avoid this. I guess that this doesn't
>> work with at least the postgres_fdw 2PC patch that Sawada-san is proposing
>> because with the patch the commit/rollback callback is performed only
>> for the connections used in the transaction.
> 
> You mean to say, pgfdw_xact_callback will not get called when the xact
> uses no foreign server connection or is it that pgfdw_xact_callback
> gets called but exits quickly from it? I'm not sure what the 2PC patch
> does.

Maybe it's chance to review the patch! ;P

BTW his patch tries to add new callback interfaces for commit/rollback of
foreign transactions, and make postgres_fdw use them instead of
XactCallback. And those new interfaces are executed only when
the transaction has started the foreign transactions.

Regards,

-- 
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION





view thread (175+ messages)  latest in thread

Message-ID: <c0d078a7-1cfb-3621-6a44-d73ba1382bb2@oss.nttdata.com>
Permalink:  ../c0d078a7-1cfb-3621-6a44-d73ba1382bb2@oss.nttdata.com/
Also on:    postgresql.org/message-id/c0d078a7-1cfb-3621-6a44-d73ba1382bb2@oss.nttdata.com

 · 

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: masao.fujii@oss.nttdata.com, bharath.rupireddyforpostgres@gmail.com, tgl@sss.pgh.pa.us
  Subject: Re: [PATCH] postgres_fdw connection caching - cause remote sessions linger till the local session exit
  In-Reply-To: <c0d078a7-1cfb-3621-6a44-d73ba1382bb2@oss.nttdata.com>
  References: <CALj2ACVvrp5=AVp2PupEm+nAC8S4buqR3fJMmaCoc7ftT0aD2A@mail.gmail.com> <CALj2ACWq4+T-M1cTDDdHm2wBcYCD1fUhpONg11UAH1L-+MoEBw@mail.gmail.com> <3c20e3e6-1127-17f4-7725-a860b394076c@oss.nttdata.com> <73fc5ae4-3c54-1262-4533-f8c547de2e60@oss.nttdata.com> <CALj2ACWFX8wjEKmK8LQ-ZNVJqGt_Zy=1-cBhKE3XTJ+At_VN-w@mail.gmail.com> <2688508.1611865371@sss.pgh.pa.us> <CALj2ACWhoQtyZdsCZNLDLOnRjCBcoscrc3H0qU4=7f23UZcF9g@mail.gmail.com> <2724627.1611886184@sss.pgh.pa.us> <fbfdf4e2-37fb-a3f1-f6a0-3f9bf089e356@oss.nttdata.com> <CALj2ACVL7PZO+gOj7Jrhshm79TjTpj_6CJDqtf34VgjQasX1DA@mail.gmail.com> <6e9c9d45-c612-639a-f741-7798013c0ae4@oss.nttdata.com> <CALj2ACW1jAJTi-SmBCStZ6+a1C3DeAc8-_Zuw1LYFzo8D33k2w@mail.gmail.com> <CALj2ACXhM_yTBXXTCA-whZ_oA1x3DuGxyKnsROjMh8YZLG9bJw@mail.gmail.com> <7fa16ff3-5b37-0617-7a27-22e839695ef5@oss.nttdata.com> <CALj2ACXQ9ke6deP1-f34vv7TOrLuXr6=nmbi5fgxA3N_Zs=pnQ@mail.gmail.com> <c0d078a7-1cfb-3621-6a44-d73ba1382bb2@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