Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id AE90A64FE47 for ; Mon, 17 Nov 2008 11:39:24 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 84797-07 for ; Mon, 17 Nov 2008 11:39:19 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from outmail129159.authsmtp.net (outmail129159.authsmtp.net [62.13.129.159]) by mail.postgresql.org (Postfix) with ESMTP id CDE4364FD92 for ; Mon, 17 Nov 2008 11:39:18 -0400 (AST) Received: from mail-c193.authsmtp.com (mail-c193.authsmtp.com [62.13.128.118]) by punt3.authsmtp.com (8.14.2/8.14.2/Kp) with ESMTP id mAHFci11054683; Mon, 17 Nov 2008 15:38:44 GMT Received: from [192.168.0.3] (85-211-229-157.dyn.gotadsl.co.uk [85.211.229.157]) (authenticated bits=0) by mail.authsmtp.com (8.14.2/8.14.2/Kp) with ESMTP id mAHFchj3025862; Mon, 17 Nov 2008 15:38:43 GMT Subject: Re: [PATCHES] Infrastructure changes for recovery (v8) From: Simon Riggs To: Heikki Linnakangas Cc: pgsql-hackers In-Reply-To: <49217D3F.9050603@enterprisedb.com> References: <1222815151.4445.1397.camel@ebony.2ndQuadrant> <48EC9CC5.6060803@enterprisedb.com> <1223468660.4747.294.camel@ebony.2ndQuadrant> <1223472898.4747.310.camel@ebony.2ndQuadrant> <49217D3F.9050603@enterprisedb.com> Content-Type: text/plain Date: Mon, 17 Nov 2008 15:39:42 +0000 Message-Id: <1226936382.3790.19.camel@ebony.2ndQuadrant> Mime-Version: 1.0 X-Mailer: Evolution 2.12.0 Content-Transfer-Encoding: 7bit X-Server-Quench: d0fbbee0-b4bd-11dd-8a51-002264978518 X-AuthRoute: OCdxZQATClZOTQEd DAteCiNZVAwpPBRK HVkIKg5MJUcNSQVJ NksadBtFaQJbY1ZH HGQLW1xEUVh7Wmt/ bwkfZQBDYEtPQQdo WVZIR1VNFgBqBAMB SENvKm8hL19FeHx1 bUBgEHJdWkY0IUYr EBwBQG0bN2MyPH0e URQMagsFdQJXfh9H aFZ7XXQFZGQPKBg1 TUcABxkNFhVyExEd YwcDN1sJXVwWFSIh XR1KFjUmG0IIXG09 KAZuMFMXG1gcKFR6 cUVxGDpf X-Authentic-SMTP: 61633235383639.pelican.dmpriest.net.uk:1378/Kp X-Report-SPAM: If SPAM / abuse - report it at: http://www.authsmtp.com/abuse X-Virus-Status: No virus detected - but ensure you scan with your own anti-virus system! X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200811/1152 X-Sequence-Number: 127864 On Mon, 2008-11-17 at 16:18 +0200, Heikki Linnakangas wrote: > Simon Riggs wrote: > > @@ -3845,6 +3850,52 @@ sigusr1_handler(SIGNAL_ARGS) > > > > PG_SETMASK(&BlockSig); > > > > + if (CheckPostmasterSignal(PMSIGNAL_RECOVERY_START)) > > + { > > + Assert(pmState == PM_STARTUP); > > + > > + /* > > + * Go to shutdown mode if a shutdown request was pending. > > + */ > > + if (Shutdown > NoShutdown) > > + { > > + pmState = PM_WAIT_BACKENDS; > > + /* PostmasterStateMachine logic does the rest */ > > + } > > + else > > + { > > + /* > > + * Startup process has entered recovery > > + */ > > + pmState = PM_RECOVERY; > > > Hmm, I smell a race condition here: > > 1. Startup process goes into consistent state, and signals postmaster > 2. Startup process finishes WAL replay and dies > 3. Postmaster wakes up in reaper(), noting that the startup process > dies, and goes into PM_RUN mode. > 4. The above signal handler for postmaster is run, causing an assertion > failure, or putting postmaster back into PM_RECOVERY mode if assertions > are disabled. > > Highly unlikely in practice, given how much code needs to run in the > startup process between signaling the postmaster and exiting, but it > seems theoretically possible. Do we care, and if we do, how can we fix it? Might be possible - it does depend on the sequence of actions its true. Agree not likely to happen, except as the result of another bug. I'll change it to a test for if (pmState == PM_STARTUP) pmState = PM_RECOVERY; The assertion was mainly for documentation, its not protecting anything critical (IIRC). -- Simon Riggs www.2ndQuadrant.com PostgreSQL Training, Services and Support