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 1rm6AY-00602N-0Z for pgsql-hackers@arkaria.postgresql.org; Mon, 18 Mar 2024 06:08:22 +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 1rm6AW-00FukS-AT for pgsql-hackers@arkaria.postgresql.org; Mon, 18 Mar 2024 06:08:20 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rm6AV-00FukK-Qg for pgsql-hackers@lists.postgresql.org; Mon, 18 Mar 2024 06:08:20 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rm6AS-0055vf-F2 for pgsql-hackers@lists.postgresql.org; Mon, 18 Mar 2024 06:08:19 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 56C4B5C006A; Mon, 18 Mar 2024 02:08:16 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Mon, 18 Mar 2024 02:08:16 -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=fm2; t=1710742096; x=1710828496; bh=25RnoovdR8 relat4qhfuu7zIzv29Qtp4t4il+ikgc88=; b=gBTtj0dnFGDGQeJs5XUz89WxuR HtzH0P0Ogn4uxKPCzaz6Qohcxa2oehI4IY4dt5I7g/7Dpbp6G6dfItagXlA6w0D+ o9CFlr0mZ584cWqnIrzW1CWtiL0Ryb45R58Mjz4vxBsvc0ltVSSCJ3ntSrG4QzTS GFD/vj3QLBHnqHDPx53gPK7uOASVe6U+L/ZyXHKGTnH3QJgNEY8CAUGHRYJGD9Cc N/GaMU2onRV1kTUBPbxsHMOgwhEPl3wjLJw3bbAdD6bJ8KPdW8VS/cQFz8dOFxKo wxsE4vkcf3Irfn5DUPf9YXU4/jLyUPFi9A3oqcmQzF982HpVwARYCJ4gizeg== 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= fm2; t=1710742096; x=1710828496; bh=25RnoovdR8relat4qhfuu7zIzv29 Qtp4t4il+ikgc88=; b=lQ3+DJZN2oZPrl0yuCTlLlXss4k4MMoIHFM2Q1YbhMHG g78p+YFxICXq4WGO17xPRQxyUCYHr9G8d26FQYVJN16Da9GnAvPP3eCz7Kgq6aR0 kPqVuEF8jd/nkyKom2PBLgA/v+16IUyJCSVDgl5Ve3tPTa9i7HjfFFq8Hkxy4gFN WlbGN5KliWi/RRz0IuxxXMmIIn7/LAWyoRFmURuraTfan/9fa+AC89ylMd2iIj1y 7gVo5y5cla5TR8dar3FT1n0hIO0cCqDgNUTG35Kuh9hgOm3EQaXRWg8eHUZVQt/l 5sG5VXME5XWsAGTeQZUlR223lLeE3hfl7EYAA9fDrw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrkeeigdelvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenfg hrlhcuvffnffculdejtddmnecujfgurhepfffhvfevuffkfhggtggujgesghdtreertddt vdenucfhrhhomhepofhitghhrggvlhcurfgrqhhuihgvrhcuoehmihgthhgrvghlsehprg hquhhivghrrdighiiiqeenucggtffrrghtthgvrhhnpeetleeifedufffhhfdtteelgeeg geffhfekueevteeigfduudevudetgfegiedvjeenucevlhhushhtvghrufhiiigvpedtne curfgrrhgrmhepmhgrihhlfhhrohhmpehmihgthhgrvghlsehprghquhhivghrrdighiii X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 18 Mar 2024 02:08:12 -0400 (EDT) Date: Mon, 18 Mar 2024 15:08:02 +0900 From: Michael Paquier To: Bharath Rupireddy Cc: Nathan Bossart , Japin Li , Ian Lawrence Barwick , Kyotaro Horiguchi , Cary Huang , SATYANARAYANA NARLAPURAM , pgsql-hackers@lists.postgresql.org Subject: Re: Switching XLog source from archive to streaming when primary available Message-ID: References: <20240305020452.GA3373526@nathanxps13> <20240305195212.GB3481820@nathanxps13> <20240306161926.GB3542434@nathanxps13> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="eq3/hf7y7cv/yunH" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --eq3/hf7y7cv/yunH Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Mar 17, 2024 at 11:37:58AM +0530, Bharath Rupireddy wrote: > Rebase needed after 071e3ad59d6fd2d6d1277b2bd9579397d10ded28 due to a > conflict in meson.build. Please see the attached v23 patch. I've been reading this patch, and this is a very tricky one. Please be *very* cautious. +#streaming_replication_retry_interval =3D 0 # time after which standby + # attempts to switch WAL source from archive to + # streaming replication in seconds; 0 disables This stuff allows a minimal retry interval of 1s. Could it be useful to have more responsiveness here and allow lower values than that? Why not switching the units to be milliseconds? + if (streaming_replication_retry_interval <=3D 0 || + !StandbyMode || + currentSource !=3D XLOG_FROM_ARCHIVE) + return SWITCH_TO_STREAMING_NONE; Hmm. Perhaps this should mention why we don't care about the consistent point. + /* See if we can switch WAL source to streaming */ + if (wal_source_switch_state =3D=3D SWITCH_TO_STREAMING_NON= E) + wal_source_switch_state =3D SwitchWALSourceToPrimary(); Rather than a routine that returns as result the value to use for the GUC, I'd suggest to let this routine set the GUC as there is only one caller of SwitchWALSourceToPrimary(). This can also include a check on SWITCH_TO_STREAMING_NONE, based on what I'm reading that. - if (lastSourceFailed) + if (lastSourceFailed || + wal_source_switch_state =3D=3D SWITCH_TO_STREAMING)=20 Hmm. This one may be tricky. I'd recommend a separation between the failure in reading from a source and the switch to a new "forced" source. + if (wal_source_switch_state =3D=3D SWITCH_TO_STREAMING_PEN= DING) + readFrom =3D XLOG_FROM_PG_WAL; + else + readFrom =3D currentSource =3D=3D XLOG_FROM_ARCHIVE ? + XLOG_FROM_ANY : currentSource; WALSourceSwitchState looks confusing here, and are you sure that this is actualy correct? Shouldn't we still try a READ_FROM_ANY or a read =66rom the archives even with a streaming pending. By the way, I am not convinced that what you have is the best interface ever. This assumes that we'd always want to switch to streaming more aggressively. Could there be a point in also controlling if we should switch to pg_wal/ or just to archiving more aggressively as well, aka be able to do the opposite switch of WAL source? This design looks somewhat limited to me. The origin of the issue is that we don't have a way to control the order of the sources consumed by WAL replay. Perhaps something like a replay_source_order that uses a list would be better, with elements settable to archive, pg_wal and streaming? -- Michael --eq3/hf7y7cv/yunH Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmX32kIACgkQnvQgOdby QH1H1g/9HaNriy8iR/MA9sB6CFF38wI+NBZFeju0lzFI+OdiL3C2yd1+qn9WYNPq YGbsxTZw6km6FE8qEN3+Cdtq1n9z7yKQBuoZ8MTwgl1qxyNr3Zi/OeSQGzssCP0C xemSy8eRh0hGnfi1lpmj9c32i3a5hhYCvS6MXGEP3kEuwQULhl2Xh/wvrO0kl1ew ePR9mfC6zjFmHFStXTedZR6jEZKZu4gJa7bCQdwbKNqQJ0BAqbpztDH3aM+5RjyV GPr+8KL9N/Z8mKIZzqg8Jm+Nxv52P9OcBEhuzcJkOMFT3hW41v/ZPXaj9oh/8r9R 4G79IjRIwAPhJ0mAJ7GgvJZbbD5jqRuOeLOd/V3rdeI5mSlnS1vUIRw2PoFWLJcH MfD7B2Mtn7TK7lpqwAkT86Lqwe4FF6+ludr+2q7L5NKpUKtzxkAA+PzRv7PY+eHc 36YERbMMV60UB0XLTD/xxLYWwY0OWk+6ytiCr2ac9/BLSxYSEGIUusvm+Hm8Ki+U ED9AiNRcQtFVw/sqVjfIspGcpupJ8er1k9lkIyfrUuz5Tn1YLlXl6HONzBBXGL7X 5vUUYMBfF4tlNMmuXxXAu3hJwe7o5VCQJIOx8pj/+p2yYOLdLHzvj0GVh34O9aTX nx7GsnYiaxoP1HmgN+Z74pD7OEN6RHp3qD4TzMokhR4IfUQ2tMA= =t2D7 -----END PGP SIGNATURE----- --eq3/hf7y7cv/yunH--