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 1jeZNP-0005XN-SU for pgsql-hackers@arkaria.postgresql.org; Fri, 29 May 2020 07:24:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jeZNO-00082d-Qo for pgsql-hackers@arkaria.postgresql.org; Fri, 29 May 2020 07:24:22 +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 1jeZNO-00082F-JU for pgsql-hackers@lists.postgresql.org; Fri, 29 May 2020 07:24:22 +0000 Received: from oss.nttdata.com ([49.212.34.109]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jeZNL-0003NJ-Lm for pgsql-hackers@postgresql.org; Fri, 29 May 2020 07:24:22 +0000 Received: from hnk.local (p1864124-ipbf1405funabasi.chiba.ocn.ne.jp [123.216.143.124]) by oss.nttdata.com (Postfix) with ESMTPSA id 5485B602FB; Fri, 29 May 2020 16:24:13 +0900 (JST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.2 at oss.nttdata.com Subject: Re: race condition when writing pg_control To: Michael Paquier , "Bossart, Nathan" Cc: Thomas Munro , "pgsql-hackers@postgresql.org" References: <70BF24D6-DC51-443F-B55A-95735803842A@amazon.com> <637e17dd-e90b-0dab-f215-dbbe9c6c726a@oss.nttdata.com> <20200523053935.GB266978@paquier.xyz> <20200527071053.GD103662@paquier.xyz> From: Fujii Masao Message-ID: Date: Fri, 29 May 2020 16:24:12 +0900 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.8.1 MIME-Version: 1.0 In-Reply-To: <20200527071053.GD103662@paquier.xyz> Content-Type: text/plain; charset=windows-1252; 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 2020/05/27 16:10, Michael Paquier wrote: > On Tue, May 26, 2020 at 07:30:54PM +0000, Bossart, Nathan wrote: >> While an assertion in UpdateControlFile() would not have helped us >> catch the problem I initially reported, it does seem worthwhile to add >> it. I have attached a patch that adds this assertion and also >> attempts to fix XLogReportParameters(). Since there is only one place >> where we feel it is safe to call UpdateControlFile() without a lock, I >> just changed it to take the lock. I don't think this adds any sort of >> significant contention risk, and IMO it is a bit cleaner than the >> boolean flag. > > Let's see what Fujii-san and Thomas think about that. I'd rather > avoid taking a lock here because we don't need it and because it makes > things IMO confusing with the beginning of StartupXLOG() where a lot > of the fields are read, even if we go without this extra assertion. I have no strong opinion about this, but I tend to agree with Michael here. >> For the XLogReportParameters() fix, I simply added an exclusive lock >> acquisition for the portion that updates the values in shared memory >> and calls UpdateControlFile(). IIUC the first part of this function >> that accesses several ControlFile values should be safe, as none of >> them can be updated after server start. > > They can get updated when replaying a XLOG_PARAMETER_CHANGE record. > But you are right as all of this happens in the startup process, so > your patch looks right to me here. LGTM. Regards, -- Fujii Masao Advanced Computing Technology Center Research and Development Headquarters NTT DATA CORPORATION