Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l2ABu-0005DT-Bk for pgsql-hackers@arkaria.postgresql.org; Wed, 20 Jan 2021 09:54:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l2ABt-0001kM-7m for pgsql-hackers@arkaria.postgresql.org; Wed, 20 Jan 2021 09:54:17 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l2ABt-0001kF-0j for pgsql-hackers@lists.postgresql.org; Wed, 20 Jan 2021 09:54:17 +0000 Received: from oss.nttdata.com ([49.212.34.109]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l2ABq-0003bN-FP for pgsql-hackers@lists.postgresql.org; Wed, 20 Jan 2021 09:54:16 +0000 Received: from hnk.local (p2388216-ipbf1027funabasi.chiba.ocn.ne.jp [118.6.6.216]) by oss.nttdata.com (Postfix) with ESMTPSA id 49D0B627F4; Wed, 20 Jan 2021 18:54:10 +0900 (JST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.3 at oss.nttdata.com Subject: Re: [PATCH] postgres_fdw connection caching - cause remote sessions linger till the local session exit To: Bharath Rupireddy Cc: Zhihong Yu , Alexey Kondratov , "Hou, Zhijie" , PostgreSQL Hackers References: <55bd82c5-d133-6fbb-f1f4-e25c1509c96e@oss.nttdata.com> <422884a8-c863-a4d4-cebd-562855c29977@oss.nttdata.com> <0bc2b366-76d4-9480-5812-6f0de2b3f526@oss.nttdata.com> From: Fujii Masao Message-ID: <0c53c3da-9bfe-82f0-1190-5f029e92a816@oss.nttdata.com> Date: Wed, 20 Jan 2021 18:54:09 +0900 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2021/01/20 17:41, Bharath Rupireddy wrote: > On Wed, Jan 20, 2021 at 11:53 AM Fujii Masao > wrote: >> So, furthermore, we can use hash_search() to find the target cached >> connection, instead of using hash_seq_search(), when the server name >> is given. This would simplify the code a bit more? Of course, >> hash_seq_search() is necessary when closing all the connections, though. > > Note that the cache entry key is user mapping oid and to use > hash_search() we need the user mapping oid. But in > postgres_fdw_disconnect we can get server oid and we can also get user > mapping id using GetUserMapping, but it requires > GetUserId()/CurrentUserId as an input, I doubt we will have problems > if CurrentUserId is changed somehow with the change of current user in > the session. And user mapping may be dropped but still the connection > can exist if it's in use, in that case GetUserMapping fails in cache > lookup. > > And yes, disconnecting all connections requires hash_seq_search(). > > Keeping above in mind, I feel we can do hash_seq_search(), as we do > currently, even when the server name is given as input. This way, we > don't need to bother much on the above points. > > Thoughts? Thanks for explaining this! You're right. I'd withdraw my suggestion. Regards, -- Fujii Masao Advanced Computing Technology Center Research and Development Headquarters NTT DATA CORPORATION