Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aS6zK-0006mO-H4 for pgsql-hackers@arkaria.postgresql.org; Sat, 06 Feb 2016 17:49:38 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aS6zK-00064r-3o for pgsql-hackers@arkaria.postgresql.org; Sat, 06 Feb 2016 17:49:38 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aS6zJ-00064l-HS for pgsql-hackers@postgresql.org; Sat, 06 Feb 2016 17:49:37 +0000 Received: from mail.anarazel.de ([217.115.131.40]) by makus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1aS6zH-0008Ct-3Q for pgsql-hackers@postgresql.org; Sat, 06 Feb 2016 17:49:36 +0000 Received: by mail.anarazel.de (Postfix, from userid 108) id 5282D3AC731; Sat, 6 Feb 2016 18:49:34 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on mail X-Spam-Level: X-Spam-Status: No, score=-5.6 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 Received: from anarazel.de (p4FC0A3C8.dip0.t-ipconnect.de [79.192.163.200]) (Authenticated sender: andres@anarazel.de) by mail.anarazel.de (Postfix) with ESMTPSA id 09DB6860002; Sat, 6 Feb 2016 18:49:31 +0100 (CET) Received: by anarazel.de (Postfix, from userid 1000) id 8977010575A; Sat, 6 Feb 2016 18:49:30 +0100 (CET) Date: Sat, 6 Feb 2016 18:49:30 +0100 From: Andres Freund To: Michael Paquier Cc: Amit Kapila , Robert Haas , Jeff Janes , "pgsql-hackers@postgresql.org" Subject: Re: Re: BUG #13685: Archiving while idle every archive_timeout with wal_level hot_standby Message-ID: <20160206174930.GA21471@awork2.anarazel.de> References: <20160129081330.e5mj65du2cknxsja@alap3.anarazel.de> <20160203093803.ui5h2avzz534cxrw@alap3.anarazel.de> <20160204131003.h7obwkeaellkcewb@alap3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Pg-Spam-Score: -4.6 (----) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org On 2016-02-06 22:03:15 +0900, Michael Paquier wrote: > The patch attached will apply on master, on 9.5 there is one minor > conflict. For older versions we will need another reworked patch. FWIW, I don't think we should backpatch this. It'd look noticeably different in the back branches, and this isn't really a critical issue. I think it makes sense to see this as an optimization. > + /* > + * Update the progress LSN positions. At least one WAL insertion lock > + * is already taken appropriately before doing that, and it is just more > + * simple to do that here where WAL record data and type is at hand. > + * The progress is set at the start position of the record tracked that > + * is being added, making easier checkpoint progress tracking as the > + * control file already saves the start LSN position of the last > + * checkpoint run. > + */ > + if (!isStandbySnapshot) > + { I don't like isStandbySnapshot much, it seems better to do this more generally, via a flag passed down by the inserter. > + if (holdingAllLocks) > + { > + int i; > + > + for (i = 0; i < NUM_XLOGINSERT_LOCKS; i++) > + WALInsertLocks[i].l.progressAt = StartPos; Why update all? > /* > + * GetProgressRecPtr -- Returns the newest WAL activity position, aimed > + * at the last significant WAL activity, or in other words any activity > + * not referring to standby logging as of now. Finding the last activity > + * position is done by scanning each WAL insertion lock by taking directly > + * the light-weight lock associated to it. > + */ > +XLogRecPtr > +GetProgressRecPtr(void) > +{ > + XLogRecPtr res = InvalidXLogRecPtr; > + int i; > + > + /* > + * Look at the latest LSN position referring to the activity done by > + * WAL insertion. > + */ > + for (i = 0; i < NUM_XLOGINSERT_LOCKS; i++) > + { > + XLogRecPtr progress_lsn; > + > + LWLockAcquire(&WALInsertLocks[i].l.lock, LW_EXCLUSIVE); > + progress_lsn = WALInsertLocks[i].l.progressAt; > + LWLockRelease(&WALInsertLocks[i].l.lock); Add a comment explaining that we a) need a lock because of the potential for "torn reads" on some platforms. b) need an exclusive one, because the insert lock logic currently only expects exclusive locks. > /* > + * Fetch the progress position before taking any WAL insert lock. This > + * is normally an operation that does not take long, but leaving this > + * lookup out of the section taken an exclusive lock saves a couple > + * of instructions. > + */ > + progress_lsn = GetProgressRecPtr(); too long for my taste. How about: /* get progress, before acuiring insert locks to shorten locked section */ Looks much better now. Greetings, Andres Freund -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers