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 1ofMI3-0007rq-TV for pgsql-hackers@arkaria.postgresql.org; Mon, 03 Oct 2022 14:19:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ofMI1-000780-Nm for pgsql-hackers@arkaria.postgresql.org; Mon, 03 Oct 2022 14:19:25 +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 1ofMI1-00077h-8d for pgsql-hackers@lists.postgresql.org; Mon, 03 Oct 2022 14:19:25 +0000 Received: from mail-vk1-xa2a.google.com ([2607:f8b0:4864:20::a2a]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ofMHy-0002sZ-Oz for pgsql-hackers@lists.postgresql.org; Mon, 03 Oct 2022 14:19:24 +0000 Received: by mail-vk1-xa2a.google.com with SMTP id y129so5514261vkg.8 for ; Mon, 03 Oct 2022 07:19:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=C3521jkWi8ZqPPRbael26zn7QrcLQR/Z0i3u/wqi8bY=; b=awXSCaxXUHrt2FuTCgmul8y2w2veZYQ0O0uWbYoAFSxucosqbq58N1rDn5tYziLx8u Uwy1g4kN8LDkgqRBdfw6KSD0xyyxwYttT4cxKRqNI8E4EN+6CylPNqRxQl064hdZLvTZ vecQ154V+XAax4LvvLnBJeKVBzlIo+oazk0mUqjmaCdg6qm677nRuTv6LWNNV0hejD+W LaCEy44UA45bSESl5MKLgUhh+rM3LeObwF6WL+V+YhKrzLIqIDeQWtm4149/KaWD/CRs lDes4MAOVr+glWKgJXzwoBZtqRtzSiVD1l74jxwtAQTRRkH9FqV2q/qSYCx7D1T8tHWh uiGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=C3521jkWi8ZqPPRbael26zn7QrcLQR/Z0i3u/wqi8bY=; b=v7Tnc0n6UGLFLOC4SXHPBDqSa9O8SAKywjmCrJtIpH6Gxio0ohfPXFyntgQMLjhZY5 2Q/QVDSjC0Fh15siDK49z5ibwPRu+wmet8WX5ZxtuRSQ1FlFVtL4rEJSeHM0DQHk4jpO Myi8qpJ8gk70csxFLfeZq3+5w0OImSkP6Jqt320JsNiAnBQTpz4otf64Bt7OH3WXrTQi VFDKdScDgsptUTyAZFeU6xO8H/BgymGN6mzOKz0E+VG69e3PMnwpnB2JU5nAiQHysMBw vtZYB6YhRdYJRqS5s7Jr3BQWTxDqsvX6AgeXgGVWJiXSPQJfU2uSO4yWChFg1GWcqMaS djIA== X-Gm-Message-State: ACrzQf0qi222eAKiRLYY0SYU0XEQ0Alb/Iv+UdtmsdhWqPhEmwUJ+6yx GUxF9tuia75L9DzXLYykGStlsH7p1whp0Vxs1NM= X-Google-Smtp-Source: AMsMyM73rXZi/10yO2hTn8PbBaz9a0XHKqibSIxUHvb6HRvJC8bRmsm6gT386XlTy8bvZugAWU5z4yfctEqknAMqWKI= X-Received: by 2002:a1f:57c7:0:b0:3a9:c896:32a6 with SMTP id l190-20020a1f57c7000000b003a9c89632a6mr3534481vkb.34.1664806761736; Mon, 03 Oct 2022 07:19:21 -0700 (PDT) MIME-Version: 1.0 References: <20220217.170832.627054018291482509.horikyota.ntt@gmail.com> <379473f3-ed14-a19f-92ed-91dc73d430d3@oss.nttdata.com> <4968741d-f32c-a251-efc9-2d3db83e6891@oss.nttdata.com> <2160c6db-079a-be7c-df96-6c5cb21c03cf@oss.nttdata.com> <20221002153905.kaadndwwqemd3eu2@awork3.anarazel.de> In-Reply-To: From: =?UTF-8?B?w5ZuZGVyIEthbGFjxLE=?= Date: Mon, 3 Oct 2022 16:19:10 +0200 Message-ID: Subject: Re: [Proposal] Add foreign-server health checks infrastructure To: "kuroda.hayato@fujitsu.com" Cc: Andres Freund , Fujii Masao , "pgsql-hackers@lists.postgresql.org" , "Shinya11.Kato@oss.nttdata.com" , "zyu@yugabyte.com" , Kyotaro Horiguchi Content-Type: multipart/alternative; boundary="000000000000a72df605ea22072b" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000a72df605ea22072b Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Hayato Kuroda, > If the checking function is called not periodically but GetConnection(), > it means that the health of foreign servers will be check only when remot= e > connections are used. > So following workload described in [1] cannot handle the issue. > > BEGIN --- remote operations--- local operations --- COMMIT > > As far as I can see this patch is mostly useful for detecting the failures on the initial remote command. This is especially common when the remote server does a failover/switchover and postgres_fdw uses a cached connection to access to the remote server. The remote server failures within a transaction block sounds like a much less common problem. Still, you can give a good error message before COMMIT is sent to the remote server. I agree that this doesn't solve the issue you described, but I'm not sure if it is worthwhile to fix such a problem. > > Can we have this function/logic on Postgres core, so that other > extensions > > can also use? > > I was not sure about any use-case, but I think it can because it does > quite general things. > Is there any good motivation to do that? > I think any extension that deals with multiple Postgres nodes can benefit from such logic. In fact, the reason I realized this patch is that on the Citus extension, we are trying to solve a similar problem [1], [2]. Thinking even more, I think any extension that uses libpq and WaitEventSets can benefit from such a function. > > Do you see any performance implications of creating/freeing waitEventSe= ts > > per check? I wonder if we can somehow re-use the same waitEventSet by > > modifyWaitEvent? I guess no, but still, if this check causes a > performance > > implication, can we somehow cache 1 waitEventSet per connection? > > I have not tested yet, but I agreed this will be caused performance > decrease. > In next version first I will re-use the event set anyway, and it must be > considered later. > Actually I'm not sure your suggestion, > but you mean to say that we can add a hash table that associates PGconn > and WaitEventSet, right? > > I think it also depends on where you decide to put pgfdw_connection_check_internal(). If you prefer the postgres_fdw side, could we maybe use ConnCacheEntry in contrib/postgres_fdw/connection.c? But if you decide to put it into the Postgres side, the API for pgfdw_connection_check_internal() -- or equivalent function -- could be discussed. Do we pass a WaitEventSet and if it is NULL create a new one, else use what is passed to the function? Not sure, maybe you can come up with a better API. Thanks, Onder KALACI [1]: Check WL_SOCKET_CLOSED before using any connection by onderkalaci =C2= =B7 Pull Request #6259 =C2=B7 citusdata/citus (github.com) [2]: Add a single connection retry in MULTI_CONNECTION_LOST state by marcocitus =C2=B7 Pull Request #6283 =C2=B7 citusdata/citus (github.com) --000000000000a72df605ea22072b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi=C2=A0Hayato Kuroda,

=C2=A0
If the checking function is called not periodically but GetConnection(), it means that the health of foreign servers will be check only when remote = connections are used.
So following workload described in [1] cannot handle the issue.

BEGIN --- remote operations--- local operations --- COMMIT


As far as I can see this patch is most= ly useful for detecting the failures on the initial remote command. This is= especially common when the remote server does a failover/switchover and po= stgres_fdw uses=C2=A0a cached=C2=A0connection to access to the remote=C2=A0= server.

The remote=C2=A0server=C2=A0failures withi= n a transaction block sounds like a much less common=C2=A0problem. Still, y= ou can give a good error message before COMMIT is sent to the remote server= .
=C2=A0
I agree that this=C2=A0doesn't solve t= he issue you described, but I'm not sure if it is worthwhile=C2=A0to fi= x such a problem.


> Can we have this function/logic on Postgres core, so that other extens= ions
> can also use?

I was not sure about any use-case, but I think it can because it does quite= general things.
Is there any good motivation to do that?

I think any extension that deals with multiple Postgres nodes can benefit= from such logic. In fact, the reason I realized this patch is that on the = Citus extension, we are trying to solve a similar problem [1], [2].

Thinking even more, I think any extension that uses libpq= and WaitEventSets can benefit from such a function.=C2=A0


> Do you see any performance implications of creating/freeing waitEventS= ets
> per check? I wonder if we can somehow re-use the same waitEventSet by<= br> > modifyWaitEvent? I guess no, but still, if this check causes a perform= ance
> implication, can we somehow cache 1 waitEventSet per connection?

I have not tested yet, but I agreed this will be caused performance decreas= e.
In next version first I will re-use the event set anyway, and it must be co= nsidered later.
Actually I'm not sure your suggestion,
but you mean to say that we can add a hash table that associates=C2=A0 PGco= nn and WaitEventSet,=C2=A0 right?


I= think it also depends on where you decide to put pgfdw_connection_check_in= ternal(). If you prefer the postgres_fdw side, could we maybe use ConnCache= Entry in=C2=A0contrib/postgres_fdw/connection.c?=C2=A0

=
But if you decide to put it into the Postgres side, the API for=C2=A0p= gfdw_connection_check_internal() -- or equivalent function -- could be disc= ussed. Do we pass a WaitEventSet and if it is NULL create=C2=A0a new one, e= lse use what is passed to the function? Not sure, maybe you can come up wit= h a better API.
=C2=A0
Thanks,