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 1ldx7r-00020i-5Y for pgsql-hackers@arkaria.postgresql.org; Tue, 04 May 2021 15:38:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ldx7o-0003xz-AB for pgsql-hackers@arkaria.postgresql.org; Tue, 04 May 2021 15:38:16 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ldx7o-0003xs-1w for pgsql-hackers@lists.postgresql.org; Tue, 04 May 2021 15:38:16 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ldx7k-0003yS-Qr for pgsql-hackers@lists.postgresql.org; Tue, 04 May 2021 15:38:15 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 144Fc9n93908057; Tue, 4 May 2021 11:38:09 -0400 From: Tom Lane To: Bharath Rupireddy cc: Michael Paquier , PostgreSQL Hackers , Fujii Masao Subject: Re: Simplify backend terminate and wait logic in postgres_fdw test In-reply-to: References: <3854538.1620081771@sss.pgh.pa.us> Comments: In-reply-to Bharath Rupireddy message dated "Tue, 04 May 2021 12:43:53 +0530" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <3908035.1620142664.0@sss.pgh.pa.us> Date: Tue, 04 May 2021 11:38:09 -0400 Message-ID: <3908056.1620142689@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3908035.1620142664.1@sss.pgh.pa.us> Bharath Rupireddy writes: > On Tue, May 4, 2021 at 4:12 AM Tom Lane wrote: >> The buildfarm is showing that one of these test queries is not stable >> under CLOBBER_CACHE_ALWAYS: > I can reproduce the issue with the failing case. Issue is that the > backend pid will be null in the pg_stat_activity because of the cache > invalidation that happens at the beginning of the query and hence > pg_terminate_backend returns null on null input. No, that's nonsense: if it were happening that way, the query would return one row with a NULL result, but actually it's returning no rows. What's actually happening, it seems, is that because pgfdw_inval_callback is constantly getting called due to cache flushes, we invariably drop remote connections immediately during transaction termination (cf pgfdw_xact_callback). Thus, by the time we inspect pg_stat_activity, there is no remote session to terminate. I don't like your patch because what it effectively does is mask whether termination happened or not; if there were a bug there causing that not to happen, the test would still appear to pass. I think the most expedient fix, if we want to keep this test, is just to transiently disable debug_invalidate_system_caches_always. (That option wasn't available before v14, but fortunately we don't need a fix for the back branches.) I believe the attached will do the trick, but I'm running the test with debug_invalidate_system_caches_always turned on to verify that. Should be done in an hour or so... regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="disable-cache-clobber-for-termination-test.patch"; charset="us-ascii" Content-ID: <3908035.1620142664.2@sss.pgh.pa.us> Content-Description: disable-cache-clobber-for-termination-test.patch Content-Transfer-Encoding: quoted-printable diff --git a/contrib/postgres_fdw/expected/postgres_fdw.out b/contrib/post= gres_fdw/expected/postgres_fdw.out index 8e1cc69508..6f533c745d 100644 --- a/contrib/postgres_fdw/expected/postgres_fdw.out +++ b/contrib/postgres_fdw/expected/postgres_fdw.out @@ -9204,6 +9204,12 @@ WARNING: there is no transaction in progress -- Change application_name of remote connection to special one -- so that we can easily terminate the connection later. ALTER SERVER loopback OPTIONS (application_name 'fdw_retry_check'); +-- If debug_invalidate_system_caches_always is active, it results in +-- dropping remote connections after every transaction, making it +-- impossible to test termination meaningfully. So turn that off +-- for this test. +SET debug_invalidate_system_caches_always =3D 0; +-- Make sure we have a remote connection. SELECT 1 FROM ft1 LIMIT 1; ?column? = ---------- @@ -9227,9 +9233,8 @@ SELECT 1 FROM ft1 LIMIT 1; 1 (1 row) = --- If the query detects the broken connection when starting new remote --- subtransaction, it doesn't reestablish new connection and should fail. --- The text of the error might vary across platforms, so don't show it. +-- If we detect the broken connection when starting a new remote +-- subtransaction, we should fail instead of establishing a new connectio= n. -- Terminate the remote connection and wait for the termination to comple= te. SELECT pg_terminate_backend(pid, 180000) FROM pg_stat_activity WHERE application_name =3D 'fdw_retry_check'; @@ -9239,11 +9244,13 @@ SELECT pg_terminate_backend(pid, 180000) FROM pg_s= tat_activity (1 row) = SAVEPOINT s; +-- The text of the error might vary across platforms, so only show SQLSTA= TE. \set VERBOSITY sqlstate SELECT 1 FROM ft1 LIMIT 1; -- should fail ERROR: 08006 \set VERBOSITY default COMMIT; +RESET debug_invalidate_system_caches_always; -- =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D -- test connection invalidation cases and postgres_fdw_get_connections fu= nction -- =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D diff --git a/contrib/postgres_fdw/sql/postgres_fdw.sql b/contrib/postgres_= fdw/sql/postgres_fdw.sql index dcd36a9753..000e2534fc 100644 --- a/contrib/postgres_fdw/sql/postgres_fdw.sql +++ b/contrib/postgres_fdw/sql/postgres_fdw.sql @@ -2795,6 +2795,14 @@ ROLLBACK; -- Change application_name of remote connection to special one -- so that we can easily terminate the connection later. ALTER SERVER loopback OPTIONS (application_name 'fdw_retry_check'); + +-- If debug_invalidate_system_caches_always is active, it results in +-- dropping remote connections after every transaction, making it +-- impossible to test termination meaningfully. So turn that off +-- for this test. +SET debug_invalidate_system_caches_always =3D 0; + +-- Make sure we have a remote connection. SELECT 1 FROM ft1 LIMIT 1; = -- Terminate the remote connection and wait for the termination to comple= te. @@ -2806,18 +2814,20 @@ SELECT pg_terminate_backend(pid, 180000) FROM pg_s= tat_activity BEGIN; SELECT 1 FROM ft1 LIMIT 1; = --- If the query detects the broken connection when starting new remote --- subtransaction, it doesn't reestablish new connection and should fail. --- The text of the error might vary across platforms, so don't show it. +-- If we detect the broken connection when starting a new remote +-- subtransaction, we should fail instead of establishing a new connectio= n. -- Terminate the remote connection and wait for the termination to comple= te. SELECT pg_terminate_backend(pid, 180000) FROM pg_stat_activity WHERE application_name =3D 'fdw_retry_check'; SAVEPOINT s; +-- The text of the error might vary across platforms, so only show SQLSTA= TE. \set VERBOSITY sqlstate SELECT 1 FROM ft1 LIMIT 1; -- should fail \set VERBOSITY default COMMIT; = +RESET debug_invalidate_system_caches_always; + -- =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D -- test connection invalidation cases and postgres_fdw_get_connections fu= nction -- =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D ------- =_aaaaaaaaaa0--