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 1jOk15-0004MZ-Jx for pgsql-hackers@arkaria.postgresql.org; Wed, 15 Apr 2020 15:31:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jOk14-0005mC-5y for pgsql-hackers@arkaria.postgresql.org; Wed, 15 Apr 2020 15:31:54 +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 1jOk13-0005lv-VK for pgsql-hackers@lists.postgresql.org; Wed, 15 Apr 2020 15:31:53 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jOk11-0004Kq-R7 for pgsql-hackers@lists.postgresql.org; Wed, 15 Apr 2020 15:31:52 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id 03FFVnG8022259; Wed, 15 Apr 2020 11:31:49 -0400 From: Tom Lane To: Kyotaro Horiguchi cc: masahiko.sawada@2ndquadrant.com, masao.fujii@oss.nttdata.com, pgsql-hackers@lists.postgresql.org Subject: Re: Race condition in SyncRepGetSyncStandbysPriority In-reply-to: <20200415.113558.363461930251464527.horikyota.ntt@gmail.com> References: <20200414.183538.344904915964423903.horikyota.ntt@gmail.com> <15616.1586872362@sss.pgh.pa.us> <13059.1586896360@sss.pgh.pa.us> <20200415.113558.363461930251464527.horikyota.ntt@gmail.com> Comments: In-reply-to Kyotaro Horiguchi message dated "Wed, 15 Apr 2020 11:35:58 +0900" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <22257.1586964709.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 15 Apr 2020 11:31:49 -0400 Message-ID: <22258.1586964709@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Kyotaro Horiguchi writes: > At Tue, 14 Apr 2020 16:32:40 -0400, Tom Lane wrote i= n = > + stby->is_sync_standby =3D true; /* might change below */ > I'm uneasy with that. In quorum mode all running standbys are marked > as "sync" and that's bogus. I don't follow that? The existing coding of SyncRepGetSyncStandbysQuorum returns all the candidates in its list, so this is isomorphic to that. Possibly a different name for the flag would be more suited? > On the other hand sync_standbys is already sorted in priority order so I= think we can get rid of the member by setting *am_sync as the follows. > SyncRepGetSyncRecPtr: > if (sync_standbys[i].is_me) > { > *am_sync =3D (i < SyncRepConfig->num_sync); > break; > } I disagree with this, it will change the behavior in the quorum case. In any case, a change like this will cause callers to know way more than they ought to about the ordering of the array. In my mind, the fact that SyncRepGetSyncStandbysPriority is sorting the array is an internal implementation detail; I do not want it to be part of the API. (Apropos to that, I realized from working on this patch that there's another, completely undocumented assumption in the existing code, that the integer list will be sorted by walsender index for equal priorities. I don't like that either, and not just because it's undocumented.) regards, tom lane