pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Fujii Masao <masao.fujii@oss.nttdata.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
To: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
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 13:58:11 +0900
Message-ID: <fbfdf4e2-37fb-a3f1-f6a0-3f9bf089e356@oss.nttdata.com> (raw)
In-Reply-To: <2724627.1611886184@sss.pgh.pa.us>
References: <CALj2ACVvrp5=AVp2PupEm+nAC8S4buqR3fJMmaCoc7ftT0aD2A@mail.gmail.com>
	<64ee084b-1368-e044-debd-69cc156276c6@oss.nttdata.com>
	<CALj2ACXGwV=qTzZ+ELo+tKR9pUb52r+CFVah4hpBwGViGPMOig@mail.gmail.com>
	<CALj2ACVr+vo+D46uLEATX5fVFPCQRiuKRydxnSy7E6ZwUzBT=w@mail.gmail.com>
	<39259f30-897c-ceaf-8a1e-78fe2db398cb@oss.nttdata.com>
	<CALj2ACUwqO74-amff63Lr1VU1F7WrWEK_28+iT_Ubf8htjZzLg@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>
	<CALj! 2ACU6CdAB+GnsoJjfWndUGyDMMV-9hg9qHYXYBTPuWYV3pQ@mail.gmail.com>
	<2688508.1611865371@sss.pgh.pa.us>
	<CALj2ACWhoQtyZdsCZNLDLOnRjCBcoscrc3H0qU4=7f23UZcF9g@mail.gmail.com>
	<2724627.1611886184@sss.pgh.pa.us>



On 2021/01/29 11:09, Tom Lane wrote:
> Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com> writes:
>> On Fri, Jan 29, 2021 at 1:52 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>>> https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=trilobite&dt=2021-01-26%2019%3A59%3A40
>>> This is a CLOBBER_CACHE_ALWAYS build, so I suspect what it's
>>> telling us is that the patch's behavior is unstable in the face
>>> of unexpected cache flushes.
> 
>> Thanks a lot! It looks like the syscache invalidation messages are
>> generated too frequently with -DCLOBBER_CACHE_ALWAYS build due to
>> which pgfdw_inval_callback gets called many times in which the cached
>> entries are marked as invalid and closed if they are not used in the
>> txn. The new function postgres_fdw_get_connections outputs the
>> information of the cached connections such as name if the connection
>> is still open and their validity. Hence the output of the
>> postgres_fdw_get_connections became unstable in the buildfarm member.
>> I will further analyze making tests stable, meanwhile any suggestions
>> are welcome.
> 
> I do not think you should regard this as "we need to hack the test
> to make it stable".  I think you should regard this as "this is a
> bug".  A cache flush should not cause user-visible state changes.
> In particular, the above analysis implies that you think a cache
> flush is equivalent to end-of-transaction, which it absolutely
> is not.
> 
> Also, now that I've looked at pgfdw_inval_callback, it scares
> the heck out of me.  Actually disconnecting a connection during
> a cache inval callback seems quite unsafe --- what if that happens
> while we're using the connection?

If the connection is still used in the transaction, pgfdw_inval_callback()
marks it as invalidated and doesn't close it. So I was not thinking that
this is so unsafe.

The disconnection code in pgfdw_inval_callback() was added in commit
e3ebcca843 to fix connection leak issue, and it's back-patched. If this
change is really unsafe, we need to revert it immediately at least from back
branches because the next minor release is scheduled soon.

BTW, even if we change pgfdw_inval_callback() so that it doesn't close
the connection at all, ISTM that the results of postgres_fdw_get_connections()
would not be stable because entry->invalidated would vary based on
whether CLOBBER_CACHE_ALWAYS is used or not.

Regards,

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





view thread (175+ messages)  latest in thread

Message-ID: <fbfdf4e2-37fb-a3f1-f6a0-3f9bf089e356@oss.nttdata.com>
Permalink:  ../fbfdf4e2-37fb-a3f1-f6a0-3f9bf089e356@oss.nttdata.com/
Also on:    postgresql.org/message-id/fbfdf4e2-37fb-a3f1-f6a0-3f9bf089e356@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, tgl@sss.pgh.pa.us, bharath.rupireddyforpostgres@gmail.com
  Subject: Re: [PATCH] postgres_fdw connection caching - cause remote sessions linger till the local session exit
  In-Reply-To: <fbfdf4e2-37fb-a3f1-f6a0-3f9bf089e356@oss.nttdata.com>
  References: <CALj2ACVvrp5=AVp2PupEm+nAC8S4buqR3fJMmaCoc7ftT0aD2A@mail.gmail.com> <64ee084b-1368-e044-debd-69cc156276c6@oss.nttdata.com> <CALj2ACXGwV=qTzZ+ELo+tKR9pUb52r+CFVah4hpBwGViGPMOig@mail.gmail.com> <CALj2ACVr+vo+D46uLEATX5fVFPCQRiuKRydxnSy7E6ZwUzBT=w@mail.gmail.com> <39259f30-897c-ceaf-8a1e-78fe2db398cb@oss.nttdata.com> <CALj2ACUwqO74-amff63Lr1VU1F7WrWEK_28+iT_Ubf8htjZzLg@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>

* 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