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 1pNOzl-000363-4z for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Feb 2023 02:06:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pNOzk-00048N-2D for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Feb 2023 02:06:36 +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 1pNOzi-00046U-Di for pgsql-hackers@lists.postgresql.org; Thu, 02 Feb 2023 02:06:35 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pNOzc-0006zk-T3 for pgsql-hackers@lists.postgresql.org; Thu, 02 Feb 2023 02:06:34 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id F40705C007E; Wed, 1 Feb 2023 21:06:25 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 01 Feb 2023 21:06:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm3; t=1675303585; x=1675389985; bh=mUQ7EF9Osb IkyD1rkes6mG7+3mjYRmH4cizk0iFeKvM=; b=iEi5n0/of24ps2qIPFByNJmydh 3lOHc3JLTtzXz/i1HPMbPeSsl1Tglg1435WGBulZiN3IF0QFB3OijG7ZLSz0gO53 DTR0UELlSZAB+wODTiNO1mb7LoDcDrF8zgE0SIAle2dtkUq1y1Uj9eGN3TQt5EN5 tTTl72aEbbe4JWlaU/tiQzakPXHjjooVFW7M4h/uqwtgr4NLNch+FRL1l5Bsrz+h IVrpBStrzf1H4ghDQcoyYo2z9GVKIwmY73wDjrE9+nF48kP2n/+L2tT0W/HLYqDh fzpVaZBuuoLcvqX6rqstXZEAk0g2yUJ49V1FWTIQJkvl0nysfxIz9l3ASK2g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1675303585; x=1675389985; bh=mUQ7EF9OsbIkyD1rkes6mG7+3mjY RmH4cizk0iFeKvM=; b=RoJUpK5jNH4A+XQMUfVSRwkUe+t3yixn1nZqylPvvKK8 L3tyZ6oJCGDhoCk7q4tfx6VXfJdWZw/QsdfE1bTYzwg1gS+tVcn63z8LrQGhRyMn Y9r5PBS76l9NxARAvHOZzgOZFtbdKcbrlyUMzxrze90gWm7phZ6IBGNDsN4mD/cH rGwTGK42ybM01V3NyfcImy2uLUoDQZdcPQwY+4xJqfF3GhvVlrNgb1No1i0VkM0l q7/9XOQkiWCaNenqg4lB8iXe75bGQnOEWNNiL/lEeE58aA7EZuqfR1iZAbhrnK4K ykxL5TqJjeYUNnG1Pcl0T047kPtQPDceNZahUnY6XQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrudefjedggeeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne gfrhhlucfvnfffucdljedtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredt tddvnecuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruceomhhitghhrggvlhesph grqhhuihgvrhdrgiihiieqnecuggftrfgrthhtvghrnhepteelieefudffhffhtdetleeg geegfffhkeeuveetiefgudduvedutefggeeivdejnecuvehluhhsthgvrhfuihiivgeptd enucfrrghrrghmpehmrghilhhfrhhomhepmhhitghhrggvlhesphgrqhhuihgvrhdrgiih ii X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 1 Feb 2023 21:06:23 -0500 (EST) Date: Thu, 2 Feb 2023 11:06:19 +0900 From: Michael Paquier To: Nathan Bossart Cc: Andres Freund , Tom Lane , Thomas Munro , Fujii Masao , Postgres hackers Subject: Re: Weird failure with latches in curculio on v15 Message-ID: References: <20230201021206.wobi3dsnnuany3yq@alap3.anarazel.de> <20230201105514.rsjl4bnhb65giyvo@alap3.anarazel.de> <1369666.1675264346@sss.pgh.pa.us> <20230201165801.33ydbxvjdbomjqa7@alap3.anarazel.de> <20230201175806.GA3199959@nathanxps13> <20230201223555.GA3721373@nathanxps13> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="6vxOU9gA2GalusCZ" Content-Disposition: inline In-Reply-To: <20230201223555.GA3721373@nathanxps13> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --6vxOU9gA2GalusCZ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Feb 01, 2023 at 02:35:55PM -0800, Nathan Bossart wrote: > Here is a first draft for the proposed stopgap fix. If we want to proceed > with this, I can provide patches for the back branches. > + /* > + * PreRestoreCommand() is used to tell the SIGTERM handler for the startup > + * process that it is okay to proc_exit() right away on SIGTERM. This is > + * done for the duration of the system() call because there isn't a good > + * way to break out while it is executing. Since we might call proc_exit() > + * in a signal handler here, it is extremely important that nothing but the > + * system() call happens between the calls to PreRestoreCommand() and > + * PostRestoreCommand(). Any additional code must go before or after this > + * section. > + */ > + if (exitOnSigterm) > + PreRestoreCommand(); > + > rc = system(command); > + > + if (exitOnSigterm) > + PostRestoreCommand(); > + > pgstat_report_wait_end(); Hmm. Isn't that something that we should also document in startup.c where both routines are defined? If we begin to use PreRestoreCommand() and PostRestoreCommand() in more code paths in the future, that could be again an issue. That looks enough to me to reduce the window back to what it was before 9a740f8, as exitOnSigterm is only used for restore_command. There is a different approach possible here: rely more on wait_event_info rather than failOnSignal and exitOnSigterm to decide which code path should do what. Andres Freund wrote: > - the error message for a failed restore command seems to have gotten > worse: > could not restore file \"%s\" from archive: %s" > -> > "%s \"%s\": %s", commandName, command IMO, we don't lose any context with this method: the command type and the command string itself are the bits actually relevant. Perhaps something like that would be more intuitive? One idea: "could not execute command for %s: %s", commandName, command > - shell_* imo is not a good namespace for something called from xlog.c, > xlogarchive.c. I realize the intention is that shell_archive.c is > going to be its own "restore module", but for now it imo looks odd shell_restore.c does not sound that bad to me, FWIW. The parallel with the archive counterparts is here. My recent history is not that good when it comes to naming, based on the feedback I received, though. > And there's just plenty other stuff in the 14bdb3f13de 9a740f81eb0 that > doesn't look right: > - We now have two places open-coding what BuildRestoreCommand did Yeah, BuildRestoreCommand() was just a small wrapper on top of the new percentrepl.c, making it rather irrelevant at this stage, IMO. For the two code paths where it was called. > - The comment moved out of RestoreArchivedFile() doesn't seems less > useful at its new location We are talking about that: - /* - * Remember, we rollforward UNTIL the restore fails so failure here is - * just part of the process... that makes it difficult to determine - * whether the restore failed because there isn't an archive to restore, - * or because the administrator has specified the restore program - * incorrectly. We have to assume the former. - * - * However, if the failure was due to any sort of signal, it's best to - * punt and abort recovery. (If we "return false" here, upper levels will - * assume that recovery is complete and start up the database!) It's - * essential to abort on child SIGINT and SIGQUIT, because per spec - * system() ignores SIGINT and SIGQUIT while waiting; if we see one of - * those it's a good bet we should have gotten it too. - * - * On SIGTERM, assume we have received a fast shutdown request, and exit - * cleanly. It's pure chance whether we receive the SIGTERM first, or the - * child process. If we receive it first, the signal handler will call - * proc_exit, otherwise we do it here. If we or the child process received - * SIGTERM for any other reason than a fast shutdown request, postmaster - * will perform an immediate shutdown when it sees us exiting - * unexpectedly. - * - * We treat hard shell errors such as "command not found" as fatal, too. - */ The failure processing is stuck within the way we build and handle the command given down to system(), so keeping this in shell_restore.c (or whatever name you think would be a better fit) makes sense to me. Now, thinking a bit more of this, we could just push the description down to ExecuteRecoveryCommand(), that actually does the work, adaptinh the comment based on the refactored internals of the routine. -- Michael --6vxOU9gA2GalusCZ Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmPbGpsACgkQnvQgOdby QH25Rw/8Ci+D3aIMplTGubfsoE9/JJ4wrBzJ5LQqbee7d51QwZ4V4I6J6n8c7fXx y6vmubjqoCQN7zadIMvdjAL3LJHHgWnDJ3i2e9GVpaGsBKym/Ta4odpfqg+ErQfF AXqFaeKf2gSqvqjRHE37QAF+gMuYLwHHTriK6EL3d06RZLWgSx/G9UbCdfv2fBeK sF/2bbh0kRQLwLVFPYX3Fd3kdpI7fkhk2jLUWXLUrhDbGWhAiJSYNBeXHvVgoxCQ SMrHwqQ3Ew4HeVJ9nFZi3Ymk/IK4MLYJuoNCzTUmwhEmDhVK/GSFTWwv2M5yA5Kg u0+bMxRPx6zGl2uoD/omiDG3YdpVgks2UGTv21KlVMkTh2T/9+0dJP8SzUZ2Dov+ 3eJgCSBW1mn489LXlL7jbKKm4so+Fv92+uQ5O5Vxmj2QlFLLc0Jhq9JHXZnTt7bL pyAfv3PJIoSmQ8d8vZ+FybSeHhjqgpZ6g/ZSSc6I61fVcWz9q9QWx8p3ZWaTFa7q u/W9JkAJgHgTRvQ+B8amBolfGTs7nf+YjkfFc5wtNDXyeiiP6iabcCk1v/okpRBs FX2wlv5hIPFN0KhFlx+nB6/VxtreodY6vF1r6P25shbJu5mx7UW9KjtM9NJIoVEj 6qUiumOZXf8BeyU0S4DzqkqrcoODMoMEvOqBlhkFE7SJPdeFOrg= =Sl7y -----END PGP SIGNATURE----- --6vxOU9gA2GalusCZ--