Received: from maia.hub.org (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id E2135633CD8 for ; Wed, 20 Jan 2010 14:07:25 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 61088-07 for ; Wed, 20 Jan 2010 18:07:13 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from exprod7og114.obsmtp.com (exprod7og114.obsmtp.com [64.18.2.215]) by mail.postgresql.org (Postfix) with SMTP id 96B046332FD for ; Wed, 20 Jan 2010 14:07:14 -0400 (AST) Received: from source ([74.125.78.147]) by exprod7ob114.postini.com ([64.18.6.12]) with SMTP ID DSNKS1dGUTXVc+U2jge79VCSCiNCNOoPVwQi@postini.com; Wed, 20 Jan 2010 10:07:14 PST Received: by ey-out-1920.google.com with SMTP id 4so1033801eyg.36 for ; Wed, 20 Jan 2010 10:07:12 -0800 (PST) Received: by 10.213.104.88 with SMTP id n24mr297067ebo.0.1264010436579; Wed, 20 Jan 2010 10:00:36 -0800 (PST) Received: from ?192.168.1.117? ([88.195.103.165]) by mx.google.com with ESMTPS id 23sm198374eya.35.2010.01.20.10.00.34 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 20 Jan 2010 10:00:35 -0800 (PST) Message-ID: <4B5744C1.40806@enterprisedb.com> Date: Wed, 20 Jan 2010 20:00:33 +0200 From: Heikki Linnakangas Organization: EnterpriseDB User-Agent: Mozilla-Thunderbird 2.0.0.22 (X11/20090706) MIME-Version: 1.0 To: Andres Freund CC: Tom Lane , Simon Riggs , pgsql-hackers@postgresql.org, Hiroyuki Yamada Subject: Synchronization primitives (Was: Re: An example of bugs for Hot Standby) References: <200912151111.AA00168@silver.kokolink.net> <201001201740.22069.andres@anarazel.de> <14578.1264006776@sss.pgh.pa.us> <201001201841.15760.andres@anarazel.de> In-Reply-To: <201001201841.15760.andres@anarazel.de> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.394 tagged_above=-10 required=5 tests=AWL=0.205, BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 201001/1997 X-Sequence-Number: 155218 Andres Freund wrote: > On Wednesday 20 January 2010 17:59:36 Tom Lane wrote: >> Andres Freund writes: >>> I realize its way too late in the cycle for that, but why dont we start >>> using some library for easy cross platform atomic ops? >> (1) there probably isn't one that does exactly what we want, works >> everywhere, and has the right license; >> (2) what actual gain would we get? We've already done the work. > That there might be some other instructions were interested in? > Like really atomic increment? This reminds me of something I've been pondering for some time: Streaming Replication introduces a few places with a polling pattern like this (in pseudocode): while() { /* Check if variable in shared has advanced beoynd X */ SpinLockAcquire() localvar = sharedvar; SpinLockRelease() if (localvar > X) break; /* Not yet. Sleep pg_usleep(100); } For example, startup process polls like that to wait for walreceiver to write & flush new WAL to be replayed. And in master, walsender polls like that for new WAL to be generated, so that it can be sent to standby. Hot standby also has a polling loop where it waits for a transaction a transaction to die, though I'm not sure if that can be fit into the same model. That's OK for asynchronous replication, but unacceptable for synchronous mode. It would be nice to have a new synchronization primitive for that. -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com