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 1qW9rA-002IqS-0M for pgsql-bugs@arkaria.postgresql.org; Wed, 16 Aug 2023 06:18:12 +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 1qW9r8-003c6c-MO for pgsql-bugs@arkaria.postgresql.org; Wed, 16 Aug 2023 06:18:10 +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 1qW9r7-003c5w-Qx for pgsql-bugs@lists.postgresql.org; Wed, 16 Aug 2023 06:18:10 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qW9r4-000OPP-JB for pgsql-bugs@lists.postgresql.org; Wed, 16 Aug 2023 06:18:08 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 02C3C5C0518; Wed, 16 Aug 2023 02:18:06 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 16 Aug 2023 02:18:06 -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:sender :subject:subject:to:to; s=fm1; t=1692166685; x=1692253085; bh=0Y 7bHfRI7GqLxJoyzlxGmOyuOHdPv1aEQUamLSamPKg=; b=N3k6MwJxIp45Jpuo5T 3tCbWY9E3gDqSEjhcR34dtOuW5DXVlbbWCNiwGRRsPBlv8AMqqJkZOb/u8IVhe2l XEYNicF+SV02oZKsKQ4H8VzjW5a/CnRDFK34dEBkUuEbOAaL6VIrrE4SI1kxTuHb R0xkomhjWlGkY0XlrvCxNP+OTs2GzyCo8MRUBiauCfOqYtZMss7riyguBbe42xI+ JsSXo/UTQp+90pfQCivWQstKNEbr3z41R1pI5BOw4PHDFKF8s2RXZ2Ya3WlTAb/h 3NyTyiaB+itD3drjIIk2ZpXPu42xB/jYdrQm5kj6lO/4p4CSaaCPDVpHmKjRH9TT 0ztA== 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:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1692166685; x=1692253085; bh=0Y7bHfRI7GqLx JoyzlxGmOyuOHdPv1aEQUamLSamPKg=; b=DK8kxuimOaupC3AqKHro018oJEJdL PPnxyuuCYSQG7J+R1aIzlfSlmsqz4a4hWa526UUnOkE5Fkd10FAef0meB2f57Sww 6byn0n7IJy4wiOyFhUW889fzLJH0iNU3LGVQGkaEVZ76UhVKSTyyOTaom4i1QvHN m8Sp62BifYYPZT/3sCpEYZOGj2u77bAPY6WsWPPxCrQW/uZLl0u6G8D7OEk5HiBz L9Oa4NEaGC1HCmQmem+2rB4Hi/WXceqnewRixBGic0hvO+u1JACjqyLUx8YXn9N4 DJSduYxFH+iN6BP/VGLoTjohDHhNYkKBBuGbCTig6GympgnbUaS1B/R0g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedruddtkedguddtiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enfghrlhcuvffnffculdejtddmnecujfgurhepfffhvfevuffkfhggtggujgesghdtreer tddtjeenucfhrhhomhepofhitghhrggvlhcurfgrqhhuihgvrhcuoehmihgthhgrvghlse hprghquhhivghrrdighiiiqeenucggtffrrghtthgvrhhnpeevteejgfejveegudekheei ueeiueeiveeuiedugeehveeugffgudeuleegleeiteenucevlhhushhtvghrufhiiigvpe dtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehmihgthhgrvghlsehprghquhhivghrrdig hiii X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 16 Aug 2023 02:18:03 -0400 (EDT) Date: Wed, 16 Aug 2023 15:17:58 +0900 From: Michael Paquier To: Thomas Munro Cc: Noah Misch , Tom Lane , Kyotaro Horiguchi , exclusion@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17928: Standby fails to decode WAL on termination of primary Message-ID: References: <20230813033034.GD2326466@rfd.leadboat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="XyoPStSaLO2sygBR" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --XyoPStSaLO2sygBR Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Aug 16, 2023 at 03:29:49PM +1200, Thomas Munro wrote: > I hacked on this idea for quite a long time yesterday and today and > came up with a set of tests for the main end-of-WAL conditions: >=20 > =E2=96=B6 1/1 - xl_tot_len zero OK > =E2=96=B6 1/1 - xl_tot_len short OK > =E2=96=B6 1/1 - xl_prev bad OK > =E2=96=B6 1/1 - xl_crc bad OK > =E2=96=B6 1/1 - xlp_magic zero OK > =E2=96=B6 1/1 - xlp_magic bad OK > =E2=96=B6 1/1 - xlp_pageaddr bad OK > =E2=96=B6 1/1 - xlp_info bad OK > =E2=96=B6 1/1 - xlp_info lacks XLP_FIRST_IS_CONTRECORD OK > =E2=96=B6 1/1 - xlp_rem_len bad OK > =E2=96=B6 1/1 - xlp_magic zero (split record header) OK > =E2=96=B6 1/1 - xlp_pageaddr bad (split record header) OK > =E2=96=B6 1/1 - xlp_rem_len bad (split record header) OK > 1/1 postgresql:recovery / recovery/038_end_of_wal OK > 5.79s 13 subtests passed Nice. > It took me a while to come up with a workable way to get into the > record-header-splitting zone. Based on some of your clues about > flushing, I eventually realised I needed transactional messages, and I > built a kind of self-calibrating Rube Goldberg function around that. > It's terrible, and I'm sure we can do better. So that's advance_to_record_splitting_zone(), with the idea to loop across multiple records. The use of transactional messages ensures the flush and the stability of the test when the server is stopped, but it makes the records a bit longer than the non-transactional messages. > I wonder what people think about putting internal details of the WAL > format into a Perl test like this. Obviously it requires maintenance, > since it knows the size and layout of a few things. I guess it'd be > allowed to fish a couple of those numbers out of the source. The format of the WAL header does not change a lot across the years, so I'd be OK with that. If that's an issue, the scope of the test could always be restricted a bit. > Work in progress... I'm sure more useful checks could be added. One > thing that occurred to me while thinking about all this it that the > 'treat malloc failure as end of WAL' thing you highlighted in another > thread is indeed completely bananas -- I didn't go digging, but > perhaps it was an earlier solution to the very same garbage xl_tot_len > problem, before 70b4f82a4b5 and now this xl_rem_len-based solution? It is bananas. Still, the problem of the other thread is similar to what's here, and different at the same time because it can happen with a valid record if the host is under memory pressure, and we should still allow a standby to loop and continue in this case. Perhaps also a startup process doing only crash recovery. This thread's problem is=20 dependent on this one, which is why this one needs to happen first: we need to clarify the boundary between a real OOM and garbage indicating the end of WAL. +my $RECORD_HEADER_SIZE =3D 24; +my $XLP_PAGE_MAGIC =3D 0xd113; +my $XLP_FIRST_IS_CONTRECORD =3D 0x1; This could use something like check_pg_config() to find the header contents for the last two ones, but there's no easy way to extract the size of the header struct, is there? Or perhaps perl has a tool for that.. Anything I can read on the matter tells to use pack() to make the size estimations predictible. + my $page_offset =3D $end_lsn % $WAL_BLOCK_SIZE; + while ($page_offset >=3D $WAL_BLOCK_SIZE - 2000) + { + $end_lsn =3D emit_message($node, 2000) The hardcoded 2000 feels magic here, but I get that you just want to get away from the page border, as well. I'd be OK with more comments. +sub lsn_to_segment_and_offset +{ + my $lsn =3D shift; + return ($lsn / $WAL_SEGMENT_SIZE, $lsn % $WAL_SEGMENT_SIZE); +} Now the backend also has pg_walfile_name_offset(). I tend to rely on the backend logic as much as I can for tests. +sub start_of_page Not sure this one is needed, only being called in start_of_next_page(). +sub get_insert_lsn Name is confusing with Cluster::lsn('insert') available, perhaps this should be named get_insert_lsn_in_bytes. As a whole, I find that pretty cool. Not sure if I would backpatch the test, so my opinion would be to use that on HEAD and let it stabilize there. -- Michael --XyoPStSaLO2sygBR Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmTcahYACgkQnvQgOdby QH1lyxAAipRM0l2u9HO+HCKPw1rtSf5ygHh668e9qqw6CGxw0TD+5c/oJcGG/ijy 0lplxst5AG3WJHpBB97Cet1Rw4fEfSCcbFKbHZSB30nzHlcl0b/wszzifjxyvflz SK3tVVJdP+RookWIJCjuWhTxBkfLkNjxUNcIxxGjrmfFnY0N2vyxulzTwQILRhK5 NDMtTxrskYVHBWIkpj/v6Kc9n/3fjM6oGnP7CD0gijMnjIlKt5iGLRqYAUqBfRSF Gul6DX/V1CBFeYYMLHVivoauK4l0DC8hA9jdQfBj5rXIm1DSxu5bQOuQQjAuFTMj +ZUoRYnqUTmUYbf/8fMEquWE4wWk31A42mnK6G33PqadgTlDuABqs8OTjyuZ/rvJ sNaJ8csfJzUvKNu33v8tu+8b0AldJRM4eBHE7+bz/y2Yq7a5HWXqrueTsg3m85uC t0eB7hEZCyxb3RjEjWCOXTvDh4Sr1kAgWCfzZ9uNqlfo/HHZlLx+EhS/ZFrYu6WS yPy570WNfcoOkPlCTb6SYiljSBTiyfcuMSFQJK/evNgOTE2lpozaREpqiHuc37Vr noklV9zN+jV+ivRvIJFoFR7qfW2bXWkGEg+NB21EZU4BqsvnAoRBxHI8bqS8JDKm senVB45iOs7Od0L1YzARP+BTcba3PHDUsWagvLcCrhyUPrEbsFA= =wtxA -----END PGP SIGNATURE----- --XyoPStSaLO2sygBR--