Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s4YrV-005Dzf-BR for pgsql-hackers@arkaria.postgresql.org; Wed, 08 May 2024 04:25:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1s4YrS-006sdD-N0 for pgsql-hackers@arkaria.postgresql.org; Wed, 08 May 2024 04:24:59 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s4YrR-006sd5-2R for pgsql-hackers@lists.postgresql.org; Wed, 08 May 2024 04:24:59 +0000 Received: from fhigh8-smtp.messagingengine.com ([103.168.172.159]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s4YrN-0026aH-Lp for pgsql-hackers@lists.postgresql.org; Wed, 08 May 2024 04:24:57 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 461A51140161; Wed, 8 May 2024 00:24:51 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 08 May 2024 00:24:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715142291; x=1715228691; bh=2P8TFQMVSK 2PGeE4C4DjCKe7aQSNuv2TYLMUBMqjPfc=; b=LlopXvPEmmPKyqYRSybELSe6if 8MLIGh1QE3lXezJtQiIa4y3O3eLw3uSn1XGRsOl3yzQLOe71K16dcJOtiHPCxLV6 JzUn1WTTPpgBmSxI+g317ym0uWvVu8s4fqH1Huvng1+7tu/PZH/Mw+a12q4j0Uqq KTxGpkkcfBPz2aqwm7IRLIBktrjm/FEbvxl/+HxzdVGsZbCtc1iuGS3vRnlp3gOh yMHbYSJvgIgKW7qBNksNC1q/vF8SdFFuc+MWK2+ZpmMYwTcOozgFrjnTjeZNnehb KpWKkOyUUqTUq37kmM7TvCPI2KCSUAvycm/yiT3aKJ2mWUMQYsePOIPkX+sQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715142291; x=1715228691; bh=2P8TFQMVSK2PGeE4C4DjCKe7aQSN uv2TYLMUBMqjPfc=; b=H7bdLaf/dXOf5ATvshcLwbhC1mzb1bvoiyj4UsUKrgpE StH6hzfIT5ml+X2mUdOHEVqZ5DGS4344/oKLalFJT+T0MPk1OuoV+cUURRht0asO 9k7tdWsgYn1imHltI8X7SHv5khZJ5KBHAYt3yq+yDM7fCtNytodafrNSOvhkDrG3 bOV9egG4zFkExQI4qHkb+uLTOslt+7he1sLr7vjlg70Tpa9Yf+9yRKuZ+qKimqhM 0vbnYFVZZkhQ92W7WQ1/z1ZHE8n0mD2f7GrgkkzuWT3l6cGjoPzwz+x8xpmvu3zq WKMt/PaBkX4IsNokZ/vnkbXbj0mAWoAvNZpk1+0Y/Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddvledgjeelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne gfrhhlucfvnfffucdlfeehmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredt tddvnecuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruceomhhitghhrggvlhesph grqhhuihgvrhdrgiihiieqnecuggftrfgrthhtvghrnhepteelieefudffhffhtdetleeg geegfffhkeeuveetiefgudduvedutefggeeivdejnecuvehluhhsthgvrhfuihiivgeptd enucfrrghrrghmpehmrghilhhfrhhomhepmhhitghhrggvlhesphgrqhhuihgvrhdrgiih ii X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 8 May 2024 00:24:49 -0400 (EDT) Date: Wed, 8 May 2024 13:24:23 +0900 From: Michael Paquier To: m.litsarev@postgrespro.ru Cc: Tristan Partin , pgsql-hackers@lists.postgresql.org Subject: Re: SQL function which allows to distinguish a server being in point in time recovery mode and an ordinary replica Message-ID: References: <06c02ef916d85e77778e5cdfdf67a3df@postgrespro.ru> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="h+LEj+iq9ZRvyG3c" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --h+LEj+iq9ZRvyG3c Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, May 06, 2024 at 06:55:46PM +0300, m.litsarev@postgrespro.ru wrote: > as a first step I have introduced the `SharedRecoveryDataFlags` bitmask > instead of three boolean SharedHotStandbyActive, SharedPromoteIsTriggered > and SharedStandbyModeRequested flags (the last one from my previous patch) > and made minimal updates in corresponding code based on that change. Thanks for the patch. /* - * Local copy of SharedHotStandbyActive variable. False actually means "not + * Local copy of XLR_HOT_STANDBY_ACTIVE flag. False actually means "not * known, need to check the shared state". */ static bool LocalHotStandbyActive =3D false; =20 /* - * Local copy of SharedPromoteIsTriggered variable. False actually means "= not + * Local copy of XLR_PROMOTE_IS_TRIGGERED flag. False actually means "not * known, need to check the shared state". */ static bool LocalPromoteIsTriggered =3D false; It's a bit strange to have a bitwise set of flags in shmem while we keep these local copies as booleans. Perhaps it would be cleaner to merge both local variables into a single bits32 store? + uint32 SharedRecoveryDataFlags; I'd switch to bits32 for flags here. +bool +StandbyModeIsRequested(void) +{ + /* + * Spinlock is not needed here because XLR_STANDBY_MODE_REQUESTED flag + * can only be read after startup process is done. + */ + return (XLogRecoveryCtl->SharedRecoveryDataFlags & XLR_STANDBY_MODE_REQUE= STED) !=3D 0; +} How about introducing a single wrapper function that returns the whole value SharedRecoveryDataFlags, with the flags published in a header? Sure, XLR_HOT_STANDBY_ACTIVE is not really exciting because being able to query a standby implies it, but XLR_PROMOTE_IS_TRIGGERED could be interesting? Then this could be used with a function that returns a text[] array with all the states retrieved? The refactoring pieces and the function pieces should be split, for clarity. -- Michael --h+LEj+iq9ZRvyG3c Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmY6/ncACgkQnvQgOdby QH0Q9g//Sm66iYPHbsLEqGNa/0dfu7All9nt2VOwJjkfk3bDSrItMR30mMFcjWhO 5tpvFQu0FKSB7EnMR/2Di8ESlmPcqz+De2A7RpcZmTJL+Kiv5400Ws4+1hn/QJfe PEUwVHrJ/4Eu1zWKZV3hDJr+bprq2dMoAoZLyeGTIZ+W1ipqVEIh7UTyuau7/rrl 42DoNENWpjgnxL4Na6sWHlJ9Vmt7Vc3XX++oj1Ua5vLIYcnGK4WXY6HCm9Z4kKwF ghVWLj7yqsORJn0Fih0CC8uV7osDwYunND6CokkxJ+OL7nL2ewoZHKqZdXW59hmV GtKmR+d36dZrnsuYNZ20FALH67GHO56AZY9MlqkDZ/7O2If3kBpa0+gZ8qTj5UPK NXNrjgUHbgHHl0NHx001VWo0NGWM5GABflzbm0F4fzFuaOyATSQp6Cm2OfsXKlOj 87+zVghYrqlcZQZb2G+O1fhyOvdc5ile/VmmSnFbluNNFuQl8xWUcvobhjvw2Gr3 Eky1yykETASFyCEuBeKOIpUMuoEFxHZSf0xxBznCiT7ODq62BYD43a9PKGdft+Lw G4D757M0jvMS58lQvj1EFy83TUbMgKYkwW/oC84mnGusBFqdQ/K0P7g0Bc+M3Gmw 4H6NpGt52rgo4cbU139eK8kpaU6lIudbQnnfTGATf36oMf5V508= =j+WC -----END PGP SIGNATURE----- --h+LEj+iq9ZRvyG3c--